1 23 package com.sun.enterprise.web.stats; 24 25 import java.util.ArrayList ; 26 import java.util.logging.Logger ; 27 import java.util.logging.Level ; 28 import java.text.MessageFormat ; 29 import javax.management.ObjectName ; 30 import javax.management.MBeanServerFactory ; 31 import javax.management.MBeanServer ; 32 import javax.management.j2ee.statistics.CountStatistic ; 33 import javax.management.j2ee.statistics.Statistic ; 34 import com.sun.logging.LogDomains; 35 import com.sun.enterprise.admin.monitor.stats.PWCKeepAliveStats; 36 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 37 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 38 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 39 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 40 41 44 public class PWCKeepAliveStatsImpl implements PWCKeepAliveStats { 45 46 private static Logger _logger 47 = LogDomains.getLogger(LogDomains.WEB_LOGGER); 48 49 private GenericStatsImpl baseStatsImpl; 50 51 private MBeanServer server; 52 private ObjectName keepAliveName; 53 54 private MutableCountStatistic countConnections; 55 private MutableCountStatistic maxConnections; 56 private MutableCountStatistic countHits; 57 private MutableCountStatistic countFlushes; 58 private MutableCountStatistic countRefusals; 59 private MutableCountStatistic countTimeouts; 60 private MutableCountStatistic secondsTimeouts; 61 62 63 public PWCKeepAliveStatsImpl(String domain) { 64 65 baseStatsImpl = new GenericStatsImpl( 66 com.sun.enterprise.admin.monitor.stats.PWCKeepAliveStats.class, 67 this); 68 69 ArrayList servers = MBeanServerFactory.findMBeanServer(null); 71 if(!servers.isEmpty()) 72 server = (MBeanServer )servers.get(0); 73 else 74 server = MBeanServerFactory.createMBeanServer(); 75 76 String objNameStr = domain + ":type=PWCKeepAlive,*"; 77 try { 78 keepAliveName = new ObjectName (objNameStr); 79 } catch (Throwable t) { 80 String msg = _logger.getResourceBundle().getString( 81 "webcontainer.objectNameCreationError"); 82 msg = MessageFormat.format(msg, new Object [] { objNameStr }); 83 _logger.log(Level.SEVERE, msg, t); 84 } 85 86 initializeStatistics(); 88 } 89 90 91 96 public CountStatistic getCountConnections() { 97 countConnections.setCount( 98 StatsUtil.getAggregateStatistic(server, keepAliveName, 99 "countConnections")); 100 return (CountStatistic )countConnections.unmodifiableView(); 101 } 102 103 104 109 public CountStatistic getMaxConnections() { 110 maxConnections.setCount( 111 StatsUtil.getConstant(server, keepAliveName, "maxConnections")); 112 return (CountStatistic )maxConnections.unmodifiableView(); 113 } 114 115 116 121 public CountStatistic getCountHits() { 122 countHits.setCount( 123 StatsUtil.getAggregateStatistic(server, keepAliveName, 124 "countHits")); 125 return (CountStatistic )countHits.unmodifiableView(); 126 } 127 128 129 134 public CountStatistic getCountFlushes() { 135 countFlushes.setCount( 136 StatsUtil.getAggregateStatistic(server, keepAliveName, 137 "countFlushes")); 138 return (CountStatistic )countFlushes.unmodifiableView(); 139 } 140 141 142 147 public CountStatistic getCountRefusals() { 148 countRefusals.setCount( 149 StatsUtil.getAggregateStatistic(server, keepAliveName, 150 "countRefusals")); 151 return (CountStatistic )countRefusals.unmodifiableView(); 152 } 153 154 155 160 public CountStatistic getCountTimeouts() { 161 countTimeouts.setCount( 162 StatsUtil.getAggregateStatistic(server, keepAliveName, 163 "countTimeouts")); 164 return (CountStatistic )countTimeouts.unmodifiableView(); 165 } 166 167 168 174 public CountStatistic getSecondsTimeouts() { 175 secondsTimeouts.setCount( 176 StatsUtil.getConstant(server, keepAliveName, "secondsTimeouts")); 177 return (CountStatistic )secondsTimeouts.unmodifiableView(); 178 } 179 180 181 186 public Statistic [] getStatistics() { 187 return baseStatsImpl.getStatistics(); 188 } 189 190 191 198 public Statistic getStatistic(String name) { 199 return baseStatsImpl.getStatistic(name); 200 } 201 202 203 209 public String [] getStatisticNames() { 210 return baseStatsImpl.getStatisticNames(); 211 } 212 213 214 private void initializeStatistics() { 215 216 CountStatistic c = null; 217 218 c = new CountStatisticImpl("CountConnections"); 219 countConnections = new MutableCountStatisticImpl(c); 220 221 c = new CountStatisticImpl("MaxConnections"); 222 maxConnections = new MutableCountStatisticImpl(c); 223 224 c = new CountStatisticImpl("CountHits"); 225 countHits = new MutableCountStatisticImpl(c); 226 227 c = new CountStatisticImpl("CountFlushes"); 228 countFlushes = new MutableCountStatisticImpl(c); 229 230 c = new CountStatisticImpl("CountRefusals"); 231 countRefusals = new MutableCountStatisticImpl(c); 232 233 c = new CountStatisticImpl("CountTimeouts"); 234 countTimeouts = new MutableCountStatisticImpl(c); 235 236 c = new CountStatisticImpl("SecondsTimeouts"); 237 secondsTimeouts = new MutableCountStatisticImpl(c); 238 } 239 240 } 241 | Popular Tags |