001: /*
002: * $Id: ServiceStats.java 11234 2008-03-06 23:44:34Z tcarlson $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.module.management.mbean;
012:
013: import org.mule.management.stats.ServiceStatistics;
014: import org.mule.management.stats.RouterStatistics;
015:
016: import javax.management.MBeanRegistration;
017: import javax.management.MBeanServer;
018: import javax.management.ObjectName;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022:
023: /**
024: * <code>ServiceStats</code> TODO
025: */
026: public class ServiceStats implements ServiceStatsMBean,
027: MBeanRegistration {
028:
029: /**
030: * logger used by this class
031: */
032: private static Log LOGGER = LogFactory.getLog(ServiceStats.class);
033:
034: private MBeanServer server;
035:
036: private ObjectName name;
037: private ObjectName inboundName;
038: private ObjectName outboundName;
039:
040: private ServiceStatistics statistics;
041:
042: public ServiceStats(ServiceStatistics statistics) {
043: this .statistics = statistics;
044: }
045:
046: /**
047: *
048: */
049: public void clearStatistics() {
050: statistics.clear();
051: }
052:
053: /**
054: * @return
055: */
056: public long getAsyncEventsReceived() {
057: return statistics.getAsyncEventsReceived();
058: }
059:
060: /**
061: * @return
062: */
063: public long getAsyncEventsSent() {
064: return statistics.getAsyncEventsSent();
065: }
066:
067: /**
068: * @return
069: */
070: public long getAverageExecutionTime() {
071: return statistics.getAverageExecutionTime();
072: }
073:
074: /**
075: * @return
076: */
077: public long getAverageQueueSize() {
078: return statistics.getAverageQueueSize();
079: }
080:
081: /**
082: * @return
083: */
084: public long getExecutedEvents() {
085: return statistics.getExecutedEvents();
086: }
087:
088: /**
089: * @return
090: */
091: public long getExecutionErrors() {
092: return statistics.getExecutionErrors();
093: }
094:
095: /**
096: * @return
097: */
098: public long getFatalErrors() {
099: return statistics.getFatalErrors();
100: }
101:
102: /**
103: * @return
104: */
105: public long getMaxExecutionTime() {
106: return statistics.getMaxExecutionTime();
107: }
108:
109: /**
110: * @return
111: */
112: public long getMaxQueueSize() {
113: return statistics.getMaxQueueSize();
114: }
115:
116: /**
117: * @return
118: */
119: public long getMinExecutionTime() {
120: return statistics.getMinExecutionTime();
121: }
122:
123: /**
124: * @return
125: */
126: public String getName() {
127: return statistics.getName();
128: }
129:
130: /**
131: * @return
132: */
133: public long getQueuedEvents() {
134: return statistics.getQueuedEvents();
135: }
136:
137: /**
138: * @return
139: */
140: public long getReplyToEventsSent() {
141: return statistics.getReplyToEventsSent();
142: }
143:
144: /**
145: * @return
146: */
147: public long getSyncEventsReceived() {
148: return statistics.getSyncEventsReceived();
149: }
150:
151: /**
152: * @return
153: */
154: public long getSyncEventsSent() {
155: return statistics.getSyncEventsSent();
156: }
157:
158: /**
159: * @return
160: */
161: public long getTotalEventsReceived() {
162: return statistics.getTotalEventsReceived();
163: }
164:
165: /**
166: * @return
167: */
168: public long getTotalEventsSent() {
169: return statistics.getTotalEventsSent();
170: }
171:
172: /**
173: * @return
174: */
175: public long getTotalExecutionTime() {
176: return statistics.getTotalExecutionTime();
177: }
178:
179: /*
180: * (non-Javadoc)
181: *
182: * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
183: * javax.management.ObjectName)
184: */
185: public ObjectName preRegister(MBeanServer server, ObjectName name)
186: throws Exception {
187: this .server = server;
188: this .name = name;
189: return name;
190: }
191:
192: /*
193: * (non-Javadoc)
194: *
195: * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
196: */
197: public void postRegister(Boolean registrationDone) {
198:
199: try {
200: RouterStatistics is = this .statistics
201: .getInboundRouterStat();
202: if (is != null) {
203: inboundName = new ObjectName(name.getDomain()
204: + ":type=org.mule.Statistics,service="
205: + statistics.getName() + ",router=inbound");
206: // unregister old version if exists
207: if (this .server.isRegistered(inboundName)) {
208: this .server.unregisterMBean(inboundName);
209: }
210: this .server.registerMBean(new RouterStats(is),
211: this .inboundName);
212: }
213: RouterStatistics os = this .statistics
214: .getOutboundRouterStat();
215: if (os != null) {
216: outboundName = new ObjectName(name.getDomain()
217: + ":type=org.mule.Statistics,service="
218: + statistics.getName() + ",router=outbound");
219: // unregister old version if exists
220: if (this .server.isRegistered(outboundName)) {
221: this .server.unregisterMBean(outboundName);
222: }
223: this .server.registerMBean(new RouterStats(os),
224: this .outboundName);
225: }
226: } catch (Exception e) {
227: LOGGER.error("Error post-registering MBean", e);
228: }
229:
230: }
231:
232: /*
233: * (non-Javadoc)
234: *
235: * @see javax.management.MBeanRegistration#preDeregister()
236: */
237: public void preDeregister() throws Exception {
238: // nothing to do
239: }
240:
241: /*
242: * (non-Javadoc)
243: *
244: * @see javax.management.MBeanRegistration#postDeregister()
245: */
246: public void postDeregister() {
247: try {
248: if (this .server.isRegistered(inboundName)) {
249: this .server.unregisterMBean(inboundName);
250: }
251: } catch (Exception ex) {
252: LOGGER.error("Error unregistering ServiceStats child "
253: + inboundName.getCanonicalName(), ex);
254: }
255: try {
256: if (this .server.isRegistered(outboundName)) {
257: this .server.unregisterMBean(outboundName);
258: }
259: } catch (Exception ex) {
260: LOGGER.error("Error unregistering ServiceStats child "
261: + inboundName.getCanonicalName(), ex);
262: }
263: }
264:
265: /*
266: * (non-Javadoc)
267: *
268: * @see org.mule.management.mbeans.ServiceStatsMBean#getInboundRouter()
269: */
270: public ObjectName getRouterInbound() {
271: return this .inboundName;
272: }
273:
274: /*
275: * (non-Javadoc)
276: *
277: * @see org.mule.management.mbeans.ServiceStatsMBean#getOutboundRouter()
278: */
279: public ObjectName getRouterOutbound() {
280: return this.outboundName;
281: }
282: }
|