1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.management.mbean; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.construct.AbstractFlowConstruct; |
11 | |
import org.mule.management.stats.FlowConstructStatistics; |
12 | |
import org.mule.module.management.support.AutoDiscoveryJmxSupportFactory; |
13 | |
import org.mule.module.management.support.JmxSupport; |
14 | |
import org.mule.module.management.support.JmxSupportFactory; |
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 | |
|
27 | |
public class FlowConstructService implements FlowConstructServiceMBean, MBeanRegistration, FlowConstructStatsMBean |
28 | |
{ |
29 | 0 | private static Log LOGGER = LogFactory.getLog(FlowConstructService.class); |
30 | |
|
31 | |
protected FlowConstructStatistics statistics; |
32 | |
|
33 | |
protected MBeanServer server; |
34 | |
|
35 | |
protected String name; |
36 | |
|
37 | |
protected String type; |
38 | |
|
39 | |
protected ObjectName statsName; |
40 | |
|
41 | |
protected ObjectName objectName; |
42 | |
|
43 | |
protected MuleContext muleContext; |
44 | |
|
45 | |
|
46 | 0 | protected JmxSupportFactory jmxSupportFactory = AutoDiscoveryJmxSupportFactory.getInstance(); |
47 | 0 | protected JmxSupport jmxSupport = jmxSupportFactory.getJmxSupport(); |
48 | |
|
49 | |
public FlowConstructService(String type, String name, MuleContext muleContext, FlowConstructStatistics statistics) |
50 | 0 | { |
51 | 0 | this.muleContext = muleContext; |
52 | 0 | this.type = type; |
53 | 0 | this.name = name; |
54 | 0 | this.statistics = statistics; |
55 | 0 | } |
56 | |
|
57 | |
protected FlowConstructService(String type, String name, MuleContext muleContext) |
58 | 0 | { |
59 | 0 | this.muleContext = muleContext; |
60 | 0 | this.type = type; |
61 | 0 | this.name = name; |
62 | 0 | } |
63 | |
|
64 | |
public String getName() |
65 | |
{ |
66 | 0 | return name; |
67 | |
} |
68 | |
|
69 | |
public String getType() |
70 | |
{ |
71 | 0 | return type; |
72 | |
} |
73 | |
|
74 | |
public ObjectName getStatistics() |
75 | |
{ |
76 | 0 | return statsName; |
77 | |
} |
78 | |
|
79 | |
public void clearStatistics() |
80 | |
{ |
81 | 0 | statistics.clear(); |
82 | 0 | } |
83 | |
|
84 | |
public long getAsyncEventsReceived() |
85 | |
{ |
86 | 0 | return statistics.getAsyncEventsReceived(); |
87 | |
} |
88 | |
|
89 | |
public long getSyncEventsReceived() |
90 | |
{ |
91 | 0 | return statistics.getSyncEventsReceived(); |
92 | |
} |
93 | |
|
94 | |
public long getTotalEventsReceived() |
95 | |
{ |
96 | 0 | return statistics.getTotalEventsReceived(); |
97 | |
} |
98 | |
|
99 | |
public long getAverageProcessingTime() |
100 | |
{ |
101 | 0 | return statistics.getAverageProcessingTime(); |
102 | |
} |
103 | |
|
104 | |
public long getProcessedEvents() |
105 | |
{ |
106 | 0 | return statistics.getProcessedEvents(); |
107 | |
} |
108 | |
|
109 | |
public long getMaxProcessingTime() |
110 | |
{ |
111 | 0 | return statistics.getMaxProcessingTime(); |
112 | |
} |
113 | |
|
114 | |
public long getMinProcessingTime() |
115 | |
{ |
116 | 0 | return statistics.getMinProcessingTime(); |
117 | |
} |
118 | |
|
119 | |
public long getTotalProcessingTime() |
120 | |
{ |
121 | 0 | return statistics.getTotalProcessingTime(); |
122 | |
} |
123 | |
|
124 | |
public long getExecutionErrors() |
125 | |
{ |
126 | 0 | return statistics.getExecutionErrors(); |
127 | |
} |
128 | |
|
129 | |
public long getFatalErrors() |
130 | |
{ |
131 | 0 | return statistics.getFatalErrors(); |
132 | |
} |
133 | |
|
134 | |
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception |
135 | |
{ |
136 | 0 | this.server = server; |
137 | 0 | this.objectName = name; |
138 | 0 | return name; |
139 | |
} |
140 | |
|
141 | |
public void postRegister(Boolean registrationDone) |
142 | |
{ |
143 | 0 | AbstractFlowConstruct flow = muleContext.getRegistry().lookupObject(getName()); |
144 | |
try |
145 | |
{ |
146 | 0 | if (flow.getStatistics() != null) |
147 | |
{ |
148 | 0 | statsName = jmxSupport.getObjectName(String.format("%s:type=org.mule.Statistics,%s=%s", objectName.getDomain(), |
149 | |
flow.getConstructType(), jmxSupport.escape(getName()))); |
150 | |
|
151 | |
|
152 | 0 | if (this.server.isRegistered(statsName)) |
153 | |
{ |
154 | 0 | this.server.unregisterMBean(statsName); |
155 | |
} |
156 | |
|
157 | 0 | this.server.registerMBean(new FlowConstructStats(flow.getStatistics()), this.statsName); |
158 | |
} |
159 | |
} |
160 | 0 | catch (Exception e) |
161 | |
{ |
162 | 0 | LOGGER.error("Error post-registering the MBean", e); |
163 | 0 | } |
164 | 0 | } |
165 | |
|
166 | |
public void preDeregister() throws Exception |
167 | |
{ |
168 | |
try |
169 | |
{ |
170 | 0 | if (this.server.isRegistered(statsName)) |
171 | |
{ |
172 | 0 | this.server.unregisterMBean(statsName); |
173 | |
} |
174 | |
} |
175 | 0 | catch (Exception ex) |
176 | |
{ |
177 | 0 | LOGGER.error("Error unregistering ServiceService child " + statsName.getCanonicalName(), ex); |
178 | 0 | } |
179 | 0 | } |
180 | |
|
181 | |
public void postDeregister() |
182 | |
{ |
183 | |
|
184 | 0 | } |
185 | |
} |