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