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 | 0 | 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 | 0 | { |
44 | 0 | this.statistics = statistics; |
45 | 0 | } |
46 | |
|
47 | |
public void clearStatistics() |
48 | |
{ |
49 | 0 | statistics.clear(); |
50 | 0 | } |
51 | |
|
52 | |
public long getAsyncEventsReceived() |
53 | |
{ |
54 | 0 | return statistics.getAsyncEventsReceived(); |
55 | |
} |
56 | |
|
57 | |
public long getAsyncEventsSent() |
58 | |
{ |
59 | 0 | return statistics.getAsyncEventsSent(); |
60 | |
} |
61 | |
|
62 | |
public long getAverageExecutionTime() |
63 | |
{ |
64 | 0 | return statistics.getAverageExecutionTime(); |
65 | |
} |
66 | |
|
67 | |
public long getAverageQueueSize() |
68 | |
{ |
69 | 0 | return statistics.getAverageQueueSize(); |
70 | |
} |
71 | |
|
72 | |
public long getExecutedEvents() |
73 | |
{ |
74 | 0 | return statistics.getExecutedEvents(); |
75 | |
} |
76 | |
|
77 | |
public long getExecutionErrors() |
78 | |
{ |
79 | 0 | return statistics.getExecutionErrors(); |
80 | |
} |
81 | |
|
82 | |
public long getFatalErrors() |
83 | |
{ |
84 | 0 | return statistics.getFatalErrors(); |
85 | |
} |
86 | |
|
87 | |
public long getMaxExecutionTime() |
88 | |
{ |
89 | 0 | return statistics.getMaxExecutionTime(); |
90 | |
} |
91 | |
|
92 | |
public long getMaxQueueSize() |
93 | |
{ |
94 | 0 | return statistics.getMaxQueueSize(); |
95 | |
} |
96 | |
|
97 | |
public long getMinExecutionTime() |
98 | |
{ |
99 | 0 | return statistics.getMinExecutionTime(); |
100 | |
} |
101 | |
|
102 | |
public String getName() |
103 | |
{ |
104 | 0 | return statistics.getName(); |
105 | |
} |
106 | |
|
107 | |
public long getQueuedEvents() |
108 | |
{ |
109 | 0 | return statistics.getQueuedEvents(); |
110 | |
} |
111 | |
|
112 | |
public long getReplyToEventsSent() |
113 | |
{ |
114 | 0 | return statistics.getReplyToEventsSent(); |
115 | |
} |
116 | |
|
117 | |
public long getSyncEventsReceived() |
118 | |
{ |
119 | 0 | return statistics.getSyncEventsReceived(); |
120 | |
} |
121 | |
|
122 | |
public long getSyncEventsSent() |
123 | |
{ |
124 | 0 | return statistics.getSyncEventsSent(); |
125 | |
} |
126 | |
|
127 | |
public long getTotalEventsReceived() |
128 | |
{ |
129 | 0 | return statistics.getTotalEventsReceived(); |
130 | |
} |
131 | |
|
132 | |
public long getTotalEventsSent() |
133 | |
{ |
134 | 0 | return statistics.getTotalEventsSent(); |
135 | |
} |
136 | |
|
137 | |
public long getTotalExecutionTime() |
138 | |
{ |
139 | 0 | return statistics.getTotalExecutionTime(); |
140 | |
} |
141 | |
|
142 | |
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception |
143 | |
{ |
144 | 0 | this.server = server; |
145 | 0 | this.name = name; |
146 | 0 | return name; |
147 | |
} |
148 | |
|
149 | |
public void postRegister(Boolean registrationDone) |
150 | |
{ |
151 | |
|
152 | |
try |
153 | |
{ |
154 | 0 | RouterStatistics is = this.statistics.getInboundRouterStat(); |
155 | 0 | if (is != null) |
156 | |
{ |
157 | 0 | inboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,service=" |
158 | |
+ statistics.getName() + ",router=inbound"); |
159 | |
|
160 | 0 | if (this.server.isRegistered(inboundName)) |
161 | |
{ |
162 | 0 | this.server.unregisterMBean(inboundName); |
163 | |
} |
164 | 0 | this.server.registerMBean(new RouterStats(is), this.inboundName); |
165 | |
} |
166 | 0 | RouterStatistics os = this.statistics.getOutboundRouterStat(); |
167 | 0 | if (os != null) |
168 | |
{ |
169 | 0 | outboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,service=" |
170 | |
+ statistics.getName() + ",router=outbound"); |
171 | |
|
172 | 0 | if (this.server.isRegistered(outboundName)) |
173 | |
{ |
174 | 0 | this.server.unregisterMBean(outboundName); |
175 | |
} |
176 | 0 | this.server.registerMBean(new RouterStats(os), this.outboundName); |
177 | |
} |
178 | |
} |
179 | 0 | catch (Exception e) |
180 | |
{ |
181 | 0 | LOGGER.error("Error post-registering MBean", e); |
182 | 0 | } |
183 | 0 | } |
184 | |
|
185 | |
public void preDeregister() throws Exception |
186 | |
{ |
187 | |
|
188 | 0 | } |
189 | |
|
190 | |
public void postDeregister() |
191 | |
{ |
192 | |
try |
193 | |
{ |
194 | 0 | if (this.server.isRegistered(inboundName)) |
195 | |
{ |
196 | 0 | this.server.unregisterMBean(inboundName); |
197 | |
} |
198 | |
} |
199 | 0 | catch (Exception ex) |
200 | |
{ |
201 | 0 | LOGGER.error("Error unregistering ServiceStats child " + inboundName.getCanonicalName(), ex); |
202 | 0 | } |
203 | |
try |
204 | |
{ |
205 | 0 | if (this.server.isRegistered(outboundName)) |
206 | |
{ |
207 | 0 | this.server.unregisterMBean(outboundName); |
208 | |
} |
209 | |
} |
210 | 0 | catch (Exception ex) |
211 | |
{ |
212 | 0 | LOGGER.error("Error unregistering ServiceStats child " + inboundName.getCanonicalName(), ex); |
213 | 0 | } |
214 | 0 | } |
215 | |
|
216 | |
public ObjectName getRouterInbound() |
217 | |
{ |
218 | 0 | return this.inboundName; |
219 | |
} |
220 | |
|
221 | |
public ObjectName getRouterOutbound() |
222 | |
{ |
223 | 0 | return this.outboundName; |
224 | |
} |
225 | |
} |