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