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.MuleManager; 20 import org.mule.impl.model.AbstractComponent; 21 import org.mule.impl.model.seda.SedaComponent; 22 import org.mule.management.stats.ComponentStatistics; 23 import org.mule.umo.UMOComponent; 24 import org.mule.umo.UMOException; 25 import org.mule.umo.UMOSession; 26 27 34 public class ComponentService implements ComponentServiceMBean, MBeanRegistration , ComponentStatsMBean 35 { 36 37 40 private static Log LOGGER = LogFactory.getLog(ComponentService.class); 41 42 private MBeanServer server; 43 44 private String name; 45 46 private ObjectName statsName; 47 48 private ObjectName objectName; 49 50 private ComponentStatistics statistics; 51 52 public ComponentService(String name) 53 { 54 this.name = name; 55 this.statistics = getComponent().getStatistics(); 56 57 } 58 59 public int getQueueSize() 60 { 61 UMOComponent c = getComponent(); 62 if (c instanceof SedaComponent) 63 { 64 return ((SedaComponent)c).getQueueSize(); 65 } 66 else 67 { 68 return -1; 69 } 70 } 71 72 83 public void pause() throws UMOException 84 { 85 getComponent().pause(); 86 } 87 88 94 public void resume() throws UMOException 95 { 96 getComponent().resume(); 97 } 98 99 public boolean isPaused() 100 { 101 return getComponent().isPaused(); 102 } 103 104 public boolean isStopped() 105 { 106 return getComponent().isStopped(); 107 } 108 109 public void stop() throws UMOException 110 { 111 getComponent().stop(); 112 } 113 114 public void forceStop() throws UMOException 115 { 116 getComponent().forceStop(); 117 } 118 119 public boolean isStopping() 120 { 121 return getComponent().isStopping(); 122 } 123 124 public void dispose() throws UMOException 125 { 126 getComponent().dispose(); 127 } 128 129 public void start() throws UMOException 130 { 131 getComponent().start(); 132 } 133 134 139 public ObjectName getStatistics() 140 { 141 return statsName; 142 } 143 144 150 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception 151 { 152 this.server = server; 153 this.objectName = name; 154 return name; 155 } 156 157 162 public void postRegister(Boolean registrationDone) 163 { 164 try 165 { 166 if (getComponent().getStatistics() != null) 167 { 168 statsName = new ObjectName (objectName.getDomain() + ":type=org.mule.Statistics,component=" 169 + getName()); 170 if (this.server.isRegistered(statsName)) 172 { 173 this.server.unregisterMBean(statsName); 174 } 175 176 this.server.registerMBean(new ComponentStats(getComponent().getStatistics()), this.statsName); 177 } 178 } 179 catch (Exception e) 180 { 181 LOGGER.error("Error post-registering the MBean", e); 182 } 183 } 184 185 190 public void preDeregister() throws Exception 191 { 192 try 193 { 194 if (this.server.isRegistered(statsName)) 195 { 196 this.server.unregisterMBean(statsName); 197 } 198 } 199 catch (Exception ex) 200 { 201 LOGGER.error("Error unregistering ComponentService child " + statsName.getCanonicalName(), ex); 202 } 203 } 204 205 210 public void postDeregister() 211 { 212 } 214 215 private AbstractComponent getComponent() 216 { 217 UMOSession session = MuleManager.getInstance().getModel().getComponentSession(getName()); 218 if (session == null) 219 { 220 return null; 221 } 222 else 223 { 224 return (AbstractComponent)session.getComponent(); 225 } 226 } 227 228 230 233 public void clearStatistics() 234 { 235 statistics.clear(); 236 } 237 238 241 public long getAsyncEventsReceived() 242 { 243 return statistics.getAsyncEventsReceived(); 244 } 245 246 249 public long getAsyncEventsSent() 250 { 251 return statistics.getAsyncEventsSent(); 252 } 253 254 257 public long getAverageExecutionTime() 258 { 259 return statistics.getAverageExecutionTime(); 260 } 261 262 265 public long getAverageQueueSize() 266 { 267 return statistics.getAverageQueueSize(); 268 } 269 270 273 public long getExecutedEvents() 274 { 275 return statistics.getExecutedEvents(); 276 } 277 278 281 public long getExecutionErrors() 282 { 283 return statistics.getExecutionErrors(); 284 } 285 286 289 public long getFatalErrors() 290 { 291 return statistics.getFatalErrors(); 292 } 293 294 297 public long getMaxExecutionTime() 298 { 299 return statistics.getMaxExecutionTime(); 300 } 301 302 305 public long getMaxQueueSize() 306 { 307 return statistics.getMaxQueueSize(); 308 } 309 310 313 public long getMinExecutionTime() 314 { 315 return statistics.getMinExecutionTime(); 316 } 317 318 321 public String getName() 322 { 323 return name; 324 } 325 326 329 public long getQueuedEvents() 330 { 331 return statistics.getQueuedEvents(); 332 } 333 334 337 public long getReplyToEventsSent() 338 { 339 return statistics.getReplyToEventsSent(); 340 } 341 342 345 public long getSyncEventsReceived() 346 { 347 return statistics.getSyncEventsReceived(); 348 } 349 350 353 public long getSyncEventsSent() 354 { 355 return statistics.getSyncEventsSent(); 356 } 357 358 361 public long getTotalEventsReceived() 362 { 363 return statistics.getTotalEventsReceived(); 364 } 365 366 369 public long getTotalEventsSent() 370 { 371 return statistics.getTotalEventsSent(); 372 } 373 374 377 public long getTotalExecutionTime() 378 { 379 return statistics.getTotalExecutionTime(); 380 } 381 } 382 | Popular Tags |