1 22 package org.jboss.web.tomcat.statistics; 23 24 import java.io.Serializable ; 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 29 30 35 public class ReplicationStatistics implements Serializable 36 { 37 38 private static final long serialVersionUID = 9153807780893455734L; 39 40 41 private ConcurrentReaderHashMap ctxStats; 42 43 public long lastResetTime = System.currentTimeMillis(); 44 45 public static class TimeStatistic 46 { 47 public long replicationCount; 48 public long minPassivationTime = Long.MAX_VALUE; 49 public long maxPassivationTime; 50 public long totalPassivationTime; 51 public long minReplicationTime = Long.MAX_VALUE; 52 public long maxReplicationTime; 53 public long totalReplicationlTime; 54 55 public long loadCount; 56 public long minLoadTime = Long.MAX_VALUE; 57 public long maxLoadTime; 58 public long totalLoadlTime; 59 60 public void reset() 61 { 62 replicationCount = 0; 63 minPassivationTime = Long.MAX_VALUE; 64 maxPassivationTime = 0; 65 totalPassivationTime = 0; 66 minReplicationTime = Long.MAX_VALUE; 67 maxReplicationTime = 0; 68 totalReplicationlTime = 0; 69 loadCount = 0; 70 minLoadTime = Long.MAX_VALUE; 71 maxLoadTime = 0; 72 totalLoadlTime = 0; 73 } 74 } 75 76 public ReplicationStatistics() 77 { 78 ctxStats = new ConcurrentReaderHashMap(); 79 } 80 81 public void updatePassivationStats(String ctx, long elapsed) 82 { 83 TimeStatistic stat = (TimeStatistic) ctxStats.get(ctx); 84 if( stat == null ) 85 { 86 stat = new TimeStatistic(); 87 ctxStats.put(ctx, stat); 88 } 89 stat.totalPassivationTime += elapsed; 90 if( stat.minPassivationTime > elapsed ) 91 stat.minPassivationTime = elapsed; 92 if( stat.maxPassivationTime < elapsed ) 93 stat.maxPassivationTime = elapsed; 94 } 95 101 public void updateReplicationStats(String ctx, long elapsed) 102 { 103 TimeStatistic stat = (TimeStatistic) ctxStats.get(ctx); 104 if( stat == null ) 105 { 106 stat = new TimeStatistic(); 107 ctxStats.put(ctx, stat); 108 } 109 stat.replicationCount ++; 110 stat.totalReplicationlTime += elapsed; 111 if( stat.minReplicationTime > elapsed ) 112 stat.minReplicationTime = elapsed; 113 if( stat.maxReplicationTime < elapsed ) 114 stat.maxReplicationTime = elapsed; 115 } 116 public void updateLoadStats(String ctx, long elapsed) 117 { 118 TimeStatistic stat = (TimeStatistic) ctxStats.get(ctx); 119 if( stat == null ) 120 { 121 stat = new TimeStatistic(); 122 ctxStats.put(ctx, stat); 123 } 124 stat.loadCount ++; 125 stat.totalLoadlTime += elapsed; 126 if( stat.minLoadTime > elapsed ) 127 stat.minLoadTime = elapsed; 128 if( stat.maxLoadTime < elapsed ) 129 stat.maxLoadTime = elapsed; 130 } 131 132 135 public void resetStats() 136 { 137 synchronized( ctxStats ) 138 { 139 Iterator iter = ctxStats.values().iterator(); 140 while( iter.hasNext() ) 141 { 142 TimeStatistic stat = (TimeStatistic) iter.next(); 143 stat.reset(); 144 } 145 } 146 lastResetTime = System.currentTimeMillis(); 147 } 148 149 public void removeStats(String id) 150 { 151 ctxStats.remove(id); 152 } 153 154 158 public Map getStats() 159 { 160 return ctxStats; 161 } 162 163 public String toString() 164 { 165 StringBuffer tmp = new StringBuffer (); 166 HashMap copy = new HashMap (ctxStats); 167 Iterator iter = copy.entrySet().iterator(); 168 while( iter.hasNext() ) 169 { 170 Map.Entry entry = (Map.Entry ) iter.next(); 171 TimeStatistic stat = (TimeStatistic) entry.getValue(); 172 if (stat != null) 173 { 174 tmp.append("[sessionID: "); 175 tmp.append(entry.getKey()); 176 tmp.append(", replicationCount="); 177 tmp.append(stat.replicationCount); 178 tmp.append(", minPassivationTime="); 179 tmp.append(stat.minPassivationTime); 180 tmp.append(", maxPassivationTime="); 181 tmp.append(stat.maxPassivationTime); 182 tmp.append(", totalPassivationTime="); 183 tmp.append(stat.totalPassivationTime); 184 tmp.append(", minReplicationTime="); 185 tmp.append(stat.minReplicationTime); 186 tmp.append(", maxReplicationTime="); 187 tmp.append(stat.maxReplicationTime); 188 tmp.append(", totalReplicationlTime="); 189 tmp.append(stat.totalReplicationlTime); 190 tmp.append(", loadCount="); 191 tmp.append(stat.loadCount); 192 tmp.append(", minLoadTime="); 193 tmp.append(stat.minLoadTime); 194 tmp.append(", maxLoadTime="); 195 tmp.append(stat.maxLoadTime); 196 tmp.append(", totaLoadlTime="); 197 tmp.append(stat.totalLoadlTime); 198 tmp.append("];"); 199 } 200 } 201 tmp.append(")"); 202 return tmp.toString(); 203 } 204 205 } 206 | Popular Tags |