1 23 24 package com.sun.ejb.base.stats; 25 26 import javax.management.j2ee.statistics.CountStatistic ; 27 import javax.management.j2ee.statistics.RangeStatistic ; 28 import javax.management.j2ee.statistics.TimeStatistic ; 29 30 import com.sun.ejb.spi.stats.MonitorableSFSBStoreManager; 31 32 import com.sun.enterprise.admin.monitor.stats.AverageRangeStatistic; 33 import com.sun.enterprise.admin.monitor.stats.BoundedRangeStatisticImpl; 34 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 35 import com.sun.enterprise.admin.monitor.stats.MutableAverageRangeStatisticImpl; 36 import com.sun.enterprise.admin.monitor.stats.MutableBoundedRangeStatisticImpl; 37 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 38 import com.sun.enterprise.admin.monitor.stats.MutableTimeStatisticImpl; 39 import com.sun.enterprise.admin.monitor.stats.TimeStatisticImpl; 40 41 47 48 public class HAStatefulSessionStoreStatsImpl 49 extends StatefulSessionStoreStatsImpl 50 implements com.sun.enterprise.admin.monitor.stats.HAStatefulSessionStoreStats 51 { 52 53 private MutableCountStatisticImpl checkpointCount; 54 private MutableCountStatisticImpl checkpointSuccessCount; 55 private MutableCountStatisticImpl checkpointErrorCount; 56 private MutableAverageRangeStatisticImpl checkpointSize; 57 private MutableAverageRangeStatisticImpl checkpointTime; 58 59 private Object checkpointCountLock = new Object (); 60 private Object checkpointSizeLock = new Object (); 61 private Object checkpointTimeLock = new Object (); 62 63 private long checkpointCountVal; 64 private long checkpointSuccessCountVal; 65 private long checkpointErrorCountVal; 66 67 public HAStatefulSessionStoreStatsImpl( 68 MonitorableSFSBStoreManager provider) 69 { 70 super(provider, "com.sun.enterprise.admin.monitor.stats.HAStatefulSessionStoreStats"); 71 initialize(); 72 } 73 74 protected void initialize() { 75 super.initialize(); 76 77 synchronized (checkpointCountLock) { 78 checkpointCount = new MutableCountStatisticImpl( 79 new CountStatisticImpl("CheckpointCount")); 80 checkpointSuccessCount = new MutableCountStatisticImpl( 81 new CountStatisticImpl("CheckpointSuccessCount")); 82 checkpointErrorCount = new MutableCountStatisticImpl( 83 new CountStatisticImpl("CheckpointErrorCount")); 84 } 85 86 long now = System.currentTimeMillis(); 87 synchronized (checkpointTimeLock) { 88 checkpointTime = new MutableAverageRangeStatisticImpl( 89 new BoundedRangeStatisticImpl(0, 0, 0, 90 0, 0, "CheckpointTime", 91 "millis", "Time spent on checkpointing", 0, 0) 92 ); 93 } 94 95 synchronized (checkpointSizeLock) { 96 checkpointSize = new MutableAverageRangeStatisticImpl( 97 new BoundedRangeStatisticImpl(0, 0, 0, 98 0, 0, "CheckpointSize", 99 "millis", "Number of bytes checkpointed", 0, 0) 100 ); 101 } 102 } 103 104 107 public CountStatistic getCheckpointCount() { 108 synchronized (checkpointCountLock) { 109 checkpointCount.setCount(checkpointCountVal); 110 return (CountStatistic ) checkpointCount.unmodifiableView(); 111 } 112 } 113 114 117 public CountStatistic getCheckpointSuccessCount() { 118 synchronized (checkpointCountLock) { 119 checkpointSuccessCount.setCount(checkpointSuccessCountVal); 120 return (CountStatistic ) checkpointSuccessCount.unmodifiableView(); 121 } 122 } 123 124 127 public CountStatistic getCheckpointErrorCount() { 128 synchronized (checkpointCountLock) { 129 checkpointErrorCount.setCount(checkpointErrorCountVal); 130 return (CountStatistic ) checkpointErrorCount.unmodifiableView(); 131 } 132 } 133 134 137 public AverageRangeStatistic getCheckpointedBeanSize() { 138 synchronized (checkpointTimeLock) { 139 return (AverageRangeStatistic) checkpointSize.unmodifiableView(); 140 } 141 } 142 143 146 public AverageRangeStatistic getCheckpointTime() { 147 synchronized (checkpointTimeLock) { 148 return (AverageRangeStatistic) checkpointTime.unmodifiableView(); 149 } 150 } 151 152 public void incrementCheckpointCount(boolean success) { 153 synchronized (checkpointCountLock) { 154 checkpointCountVal++; 155 if (success) { 156 checkpointSuccessCountVal++; 157 } else { 158 checkpointErrorCountVal++; 159 } 160 } 161 } 162 163 public void setCheckpointSize(long val) { 164 synchronized (checkpointSizeLock) { 165 checkpointSize.setCount(val); 166 } 167 } 168 169 public void setCheckpointTime(long val) { 170 synchronized (checkpointTimeLock) { 171 checkpointTime.setCount(val); 172 } 173 } 174 175 protected void appendStats(StringBuffer sbuf) { 176 super.appendStats(sbuf); 177 sbuf.append("CheckpointCount: ").append(checkpointCountVal) 178 .append("; ") 179 .append("CheckpointSuccessCount: ").append(checkpointSuccessCountVal) 180 .append("; ") 181 .append("CheckpointErrorCount: ").append(checkpointErrorCountVal) 182 .append("; "); 183 184 appendTimeStatistic(sbuf, "CheckpointTime", checkpointTime); 185 } 186 187 } 188 | Popular Tags |