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