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