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