1 10 11 package org.mule.management.mbeans; 12 13 import javax.management.MBeanRegistration ; 14 import javax.management.MBeanServer ; 15 import javax.management.ObjectName ; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.mule.management.stats.ComponentStatistics; 20 import org.mule.management.stats.RouterStatistics; 21 22 29 public class ComponentStats implements ComponentStatsMBean, MBeanRegistration 30 { 31 32 35 private static Log LOGGER = LogFactory.getLog(ComponentStats.class); 36 37 private MBeanServer server; 38 39 private ObjectName name; 40 private ObjectName inboundName; 41 private ObjectName outboundName; 42 43 private ComponentStatistics statistics; 44 45 public ComponentStats(ComponentStatistics statistics) 46 { 47 this.statistics = statistics; 48 } 49 50 53 public void clearStatistics() 54 { 55 statistics.clear(); 56 } 57 58 61 public long getAsyncEventsReceived() 62 { 63 return statistics.getAsyncEventsReceived(); 64 } 65 66 69 public long getAsyncEventsSent() 70 { 71 return statistics.getAsyncEventsSent(); 72 } 73 74 77 public long getAverageExecutionTime() 78 { 79 return statistics.getAverageExecutionTime(); 80 } 81 82 85 public long getAverageQueueSize() 86 { 87 return statistics.getAverageQueueSize(); 88 } 89 90 93 public long getExecutedEvents() 94 { 95 return statistics.getExecutedEvents(); 96 } 97 98 101 public long getExecutionErrors() 102 { 103 return statistics.getExecutionErrors(); 104 } 105 106 109 public long getFatalErrors() 110 { 111 return statistics.getFatalErrors(); 112 } 113 114 117 public long getMaxExecutionTime() 118 { 119 return statistics.getMaxExecutionTime(); 120 } 121 122 125 public long getMaxQueueSize() 126 { 127 return statistics.getMaxQueueSize(); 128 } 129 130 133 public long getMinExecutionTime() 134 { 135 return statistics.getMinExecutionTime(); 136 } 137 138 141 public String getName() 142 { 143 return statistics.getName(); 144 } 145 146 149 public long getQueuedEvents() 150 { 151 return statistics.getQueuedEvents(); 152 } 153 154 157 public long getReplyToEventsSent() 158 { 159 return statistics.getReplyToEventsSent(); 160 } 161 162 165 public long getSyncEventsReceived() 166 { 167 return statistics.getSyncEventsReceived(); 168 } 169 170 173 public long getSyncEventsSent() 174 { 175 return statistics.getSyncEventsSent(); 176 } 177 178 181 public long getTotalEventsReceived() 182 { 183 return statistics.getTotalEventsReceived(); 184 } 185 186 189 public long getTotalEventsSent() 190 { 191 return statistics.getTotalEventsSent(); 192 } 193 194 197 public long getTotalExecutionTime() 198 { 199 return statistics.getTotalExecutionTime(); 200 } 201 202 208 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception 209 { 210 this.server = server; 211 this.name = name; 212 return name; 213 } 214 215 220 public void postRegister(Boolean registrationDone) 221 { 222 223 try 224 { 225 RouterStatistics is = this.statistics.getInboundRouterStat(); 226 if (is != null) 227 { 228 inboundName = new ObjectName (name.getDomain() + ":type=org.mule.Statistics,component=" 229 + statistics.getName() + ",router=inbound"); 230 if (this.server.isRegistered(inboundName)) 232 { 233 this.server.unregisterMBean(inboundName); 234 } 235 this.server.registerMBean(new RouterStats(is), this.inboundName); 236 } 237 RouterStatistics os = this.statistics.getOutboundRouterStat(); 238 if (os != null) 239 { 240 outboundName = new ObjectName (name.getDomain() + ":type=org.mule.Statistics,component=" 241 + statistics.getName() + ",router=outbound"); 242 if (this.server.isRegistered(outboundName)) 244 { 245 this.server.unregisterMBean(outboundName); 246 } 247 this.server.registerMBean(new RouterStats(os), this.outboundName); 248 } 249 } 250 catch (Exception e) 251 { 252 LOGGER.error("Error post-registering MBean", e); 253 } 254 255 } 256 257 262 public void preDeregister() throws Exception 263 { 264 } 266 267 272 public void postDeregister() 273 { 274 try 275 { 276 if (this.server.isRegistered(inboundName)) 277 { 278 this.server.unregisterMBean(inboundName); 279 } 280 } 281 catch (Exception ex) 282 { 283 LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex); 284 } 285 try 286 { 287 if (this.server.isRegistered(outboundName)) 288 { 289 this.server.unregisterMBean(outboundName); 290 } 291 } 292 catch (Exception ex) 293 { 294 LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex); 295 } 296 } 297 298 303 public ObjectName getRouterInbound() 304 { 305 return this.inboundName; 306 } 307 308 313 public ObjectName getRouterOutbound() 314 { 315 return this.outboundName; 316 } 317 } 318 | Popular Tags |