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