1717 * @author Alex Snaps
1818 */
1919public class CacheRegionStatisticsImpl implements CacheRegionStatistics , Serializable {
20- private final transient Region region ;
20+ private final String regionName ;
21+ private final transient ExtendedStatisticsSupport extendedStatisticsSupport ;
2122
2223 private final LongAdder hitCount = new LongAdder ();
2324 private final LongAdder missCount = new LongAdder ();
2425 private final LongAdder putCount = new LongAdder ();
2526 private final LongAdder removeCount = new LongAdder ();
2627
2728 CacheRegionStatisticsImpl (Region region ) {
28- this .region = region ;
29+ regionName = region .getName ();
30+ extendedStatisticsSupport =
31+ region instanceof ExtendedStatisticsSupport extended
32+ ? extended
33+ : null ;
2934 }
3035
3136 @ Override
3237 public String getRegionName () {
33- return region . getName () ;
38+ return regionName ;
3439 }
3540
3641 @ Override
@@ -55,23 +60,23 @@ public long getRemoveCount() {
5560
5661 @ Override
5762 public long getElementCountInMemory () {
58- return region instanceof ExtendedStatisticsSupport extended
59- ? extended . getElementCountInMemory ()
60- : NO_EXTENDED_STAT_SUPPORT_RETURN ;
63+ return extendedStatisticsSupport == null
64+ ? NO_EXTENDED_STAT_SUPPORT_RETURN
65+ : extendedStatisticsSupport . getElementCountInMemory () ;
6166 }
6267
6368 @ Override
6469 public long getElementCountOnDisk () {
65- return region instanceof ExtendedStatisticsSupport extended
66- ? extended . getElementCountOnDisk ()
67- : NO_EXTENDED_STAT_SUPPORT_RETURN ;
70+ return extendedStatisticsSupport == null
71+ ? NO_EXTENDED_STAT_SUPPORT_RETURN
72+ : extendedStatisticsSupport . getElementCountOnDisk () ;
6873 }
6974
7075 @ Override
7176 public long getSizeInMemory () {
72- return region instanceof ExtendedStatisticsSupport extended
73- ? extended . getSizeInMemory ()
74- : NO_EXTENDED_STAT_SUPPORT_RETURN ;
77+ return extendedStatisticsSupport == null
78+ ? NO_EXTENDED_STAT_SUPPORT_RETURN
79+ : extendedStatisticsSupport . getSizeInMemory () ;
7580 }
7681
7782 void incrementHitCount () {
@@ -93,15 +98,18 @@ public void incrementRemoveCount() {
9398
9499 @ Override
95100 public String toString () {
96- return "CacheRegionStatistics"
97- + "[region=" + region .getName ()
98- + ",hitCount=" + hitCount
99- + ",missCount=" + missCount
100- + ",putCount=" + putCount
101- + ",removeCount=" + removeCount
102- + ",elementCountInMemory=" + getElementCountInMemory ()
103- + ",elementCountOnDisk=" + getElementCountOnDisk ()
104- + ",sizeInMemory=" + getSizeInMemory ()
105- + ']' ;
101+ final var string =
102+ new StringBuilder ("CacheRegionStatistics" )
103+ .append ( "[region=" ).append ( regionName )
104+ .append ( ",hitCount=" ).append ( hitCount )
105+ .append ( ",missCount=" ).append ( missCount )
106+ .append ( ",putCount=" ).append ( putCount )
107+ .append ( ",removeCount=" ).append ( removeCount );
108+ if ( extendedStatisticsSupport != null ) {
109+ string .append ( ",elementCountInMemory=" ).append ( getElementCountInMemory () )
110+ .append ( ",elementCountOnDisk=" ).append ( getElementCountOnDisk () )
111+ .append ( ",sizeInMemory=" ).append ( getSizeInMemory () );
112+ }
113+ return string .append ( ']' ).toString ();
106114 }
107115}
0 commit comments