1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.management.mbean;
12
13 import org.mule.management.stats.RouterStatistics;
14 import org.mule.management.stats.ServiceStatistics;
15
16 import javax.management.MBeanRegistration;
17 import javax.management.MBeanServer;
18 import javax.management.ObjectName;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23
24
25
26 public class ServiceStats implements ServiceStatsMBean, MBeanRegistration
27 {
28
29
30
31
32 private static Log LOGGER = LogFactory.getLog(ServiceStats.class);
33
34 private MBeanServer server;
35
36 private ObjectName name;
37 private ObjectName inboundName;
38 private ObjectName outboundName;
39
40 private ServiceStatistics statistics;
41
42 public ServiceStats(ServiceStatistics statistics)
43 {
44 this.statistics = statistics;
45 }
46
47 public void clearStatistics()
48 {
49 statistics.clear();
50 }
51
52 public long getAsyncEventsReceived()
53 {
54 return statistics.getAsyncEventsReceived();
55 }
56
57 public long getAsyncEventsSent()
58 {
59 return statistics.getAsyncEventsSent();
60 }
61
62 public long getAverageExecutionTime()
63 {
64 return statistics.getAverageExecutionTime();
65 }
66
67 public long getAverageQueueSize()
68 {
69 return statistics.getAverageQueueSize();
70 }
71
72 public long getExecutedEvents()
73 {
74 return statistics.getExecutedEvents();
75 }
76
77 public long getExecutionErrors()
78 {
79 return statistics.getExecutionErrors();
80 }
81
82 public long getFatalErrors()
83 {
84 return statistics.getFatalErrors();
85 }
86
87 public long getMaxExecutionTime()
88 {
89 return statistics.getMaxExecutionTime();
90 }
91
92 public long getMaxQueueSize()
93 {
94 return statistics.getMaxQueueSize();
95 }
96
97 public long getMinExecutionTime()
98 {
99 return statistics.getMinExecutionTime();
100 }
101
102 public String getName()
103 {
104 return statistics.getName();
105 }
106
107 public long getQueuedEvents()
108 {
109 return statistics.getQueuedEvents();
110 }
111
112 public long getReplyToEventsSent()
113 {
114 return statistics.getReplyToEventsSent();
115 }
116
117 public long getSyncEventsReceived()
118 {
119 return statistics.getSyncEventsReceived();
120 }
121
122 public long getSyncEventsSent()
123 {
124 return statistics.getSyncEventsSent();
125 }
126
127 public long getTotalEventsReceived()
128 {
129 return statistics.getTotalEventsReceived();
130 }
131
132 public long getTotalEventsSent()
133 {
134 return statistics.getTotalEventsSent();
135 }
136
137 public long getTotalExecutionTime()
138 {
139 return statistics.getTotalExecutionTime();
140 }
141
142 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
143 {
144 this.server = server;
145 this.name = name;
146 return name;
147 }
148
149 public void postRegister(Boolean registrationDone)
150 {
151
152 try
153 {
154 RouterStatistics is = this.statistics.getInboundRouterStat();
155 if (is != null)
156 {
157 inboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,service="
158 + statistics.getName() + ",router=inbound");
159
160 if (this.server.isRegistered(inboundName))
161 {
162 this.server.unregisterMBean(inboundName);
163 }
164 this.server.registerMBean(new RouterStats(is), this.inboundName);
165 }
166 RouterStatistics os = this.statistics.getOutboundRouterStat();
167 if (os != null)
168 {
169 outboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,service="
170 + statistics.getName() + ",router=outbound");
171
172 if (this.server.isRegistered(outboundName))
173 {
174 this.server.unregisterMBean(outboundName);
175 }
176 this.server.registerMBean(new RouterStats(os), this.outboundName);
177 }
178 }
179 catch (Exception e)
180 {
181 LOGGER.error("Error post-registering MBean", e);
182 }
183 }
184
185 public void preDeregister() throws Exception
186 {
187
188 }
189
190 public void postDeregister()
191 {
192 try
193 {
194 if (this.server.isRegistered(inboundName))
195 {
196 this.server.unregisterMBean(inboundName);
197 }
198 }
199 catch (Exception ex)
200 {
201 LOGGER.error("Error unregistering ServiceStats child " + inboundName.getCanonicalName(), ex);
202 }
203 try
204 {
205 if (this.server.isRegistered(outboundName))
206 {
207 this.server.unregisterMBean(outboundName);
208 }
209 }
210 catch (Exception ex)
211 {
212 LOGGER.error("Error unregistering ServiceStats child " + inboundName.getCanonicalName(), ex);
213 }
214 }
215
216 public ObjectName getRouterInbound()
217 {
218 return this.inboundName;
219 }
220
221 public ObjectName getRouterOutbound()
222 {
223 return this.outboundName;
224 }
225 }