1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.agent; |
8 | |
|
9 | |
import org.mule.AbstractAgent; |
10 | |
import org.mule.api.MuleException; |
11 | |
import org.mule.api.context.MuleContextBuilder; |
12 | |
import org.mule.api.context.notification.ComponentMessageNotificationListener; |
13 | |
import org.mule.api.context.notification.ConnectionNotificationListener; |
14 | |
import org.mule.api.context.notification.CustomNotificationListener; |
15 | |
import org.mule.api.context.notification.EndpointMessageNotificationListener; |
16 | |
import org.mule.api.context.notification.ManagementNotificationListener; |
17 | |
import org.mule.api.context.notification.ModelNotificationListener; |
18 | |
import org.mule.api.context.notification.MuleContextNotificationListener; |
19 | |
import org.mule.api.context.notification.SecurityNotificationListener; |
20 | |
import org.mule.api.context.notification.ServerNotification; |
21 | |
import org.mule.api.context.notification.ServerNotificationListener; |
22 | |
import org.mule.api.context.notification.ServiceNotificationListener; |
23 | |
import org.mule.api.lifecycle.InitialisationException; |
24 | |
import org.mule.context.notification.ComponentMessageNotification; |
25 | |
import org.mule.context.notification.ConnectionNotification; |
26 | |
import org.mule.context.notification.EndpointMessageNotification; |
27 | |
import org.mule.context.notification.ManagementNotification; |
28 | |
import org.mule.context.notification.ModelNotification; |
29 | |
import org.mule.context.notification.MuleContextNotification; |
30 | |
import org.mule.context.notification.NotificationException; |
31 | |
import org.mule.context.notification.SecurityNotification; |
32 | |
import org.mule.context.notification.ServiceNotification; |
33 | |
|
34 | |
import java.util.HashSet; |
35 | |
import java.util.Set; |
36 | |
|
37 | |
import org.apache.commons.logging.Log; |
38 | |
import org.apache.commons.logging.LogFactory; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public abstract class AbstractNotificationLoggerAgent extends AbstractAgent |
48 | |
{ |
49 | |
|
50 | |
|
51 | |
|
52 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
53 | |
|
54 | 0 | private boolean ignoreManagerNotifications = false; |
55 | 0 | private boolean ignoreModelNotifications = false; |
56 | 0 | private boolean ignoreComponentNotifications = false; |
57 | 0 | private boolean ignoreConnectionNotifications = false; |
58 | 0 | private boolean ignoreSecurityNotifications = false; |
59 | 0 | private boolean ignoreManagementNotifications = false; |
60 | 0 | private boolean ignoreCustomNotifications = false; |
61 | 0 | private boolean ignoreAdminNotifications = false; |
62 | 0 | private boolean ignoreMessageNotifications = false; |
63 | 0 | private boolean ignoreEndpointMessageNotifications = false; |
64 | 0 | private boolean ignoreComponentMessageNotifications = false; |
65 | |
|
66 | 0 | private Set<ServerNotificationListener> listeners = new HashSet<ServerNotificationListener>(); |
67 | |
|
68 | |
protected AbstractNotificationLoggerAgent(String name) |
69 | |
{ |
70 | 0 | super(name); |
71 | 0 | } |
72 | |
|
73 | |
public void start() throws MuleException |
74 | |
{ |
75 | |
|
76 | 0 | } |
77 | |
|
78 | |
public void stop() throws MuleException |
79 | |
{ |
80 | |
|
81 | 0 | } |
82 | |
|
83 | |
public void dispose() |
84 | |
{ |
85 | 0 | for (ServerNotificationListener listener : listeners) |
86 | |
{ |
87 | 0 | muleContext.unregisterListener(listener); |
88 | |
} |
89 | 0 | } |
90 | |
|
91 | |
public boolean isIgnoreManagerNotifications() |
92 | |
{ |
93 | 0 | return ignoreManagerNotifications; |
94 | |
} |
95 | |
|
96 | |
public void setIgnoreManagerNotifications(boolean ignoreManagerNotifications) |
97 | |
{ |
98 | 0 | this.ignoreManagerNotifications = ignoreManagerNotifications; |
99 | 0 | } |
100 | |
|
101 | |
public boolean isIgnoreMessageNotifications() |
102 | |
{ |
103 | 0 | return ignoreMessageNotifications; |
104 | |
} |
105 | |
|
106 | |
public void setIgnoreMessageNotifications(boolean ignoreMessageNotifications) |
107 | |
{ |
108 | 0 | this.ignoreMessageNotifications = ignoreMessageNotifications; |
109 | 0 | } |
110 | |
|
111 | |
public boolean isIgnoreModelNotifications() |
112 | |
{ |
113 | 0 | return ignoreModelNotifications; |
114 | |
} |
115 | |
|
116 | |
public void setIgnoreModelNotifications(boolean ignoreModelNotifications) |
117 | |
{ |
118 | 0 | this.ignoreModelNotifications = ignoreModelNotifications; |
119 | 0 | } |
120 | |
|
121 | |
public boolean isIgnoreComponentNotifications() |
122 | |
{ |
123 | 0 | return ignoreComponentNotifications; |
124 | |
} |
125 | |
|
126 | |
public void setIgnoreComponentNotifications(boolean ignoreComponentNotifications) |
127 | |
{ |
128 | 0 | this.ignoreComponentNotifications = ignoreComponentNotifications; |
129 | 0 | } |
130 | |
|
131 | |
public boolean isIgnoreSecurityNotifications() |
132 | |
{ |
133 | 0 | return ignoreSecurityNotifications; |
134 | |
} |
135 | |
|
136 | |
public void setIgnoreSecurityNotifications(boolean ignoreSecurityNotifications) |
137 | |
{ |
138 | 0 | this.ignoreSecurityNotifications = ignoreSecurityNotifications; |
139 | 0 | } |
140 | |
|
141 | |
public boolean isIgnoreManagementNotifications() |
142 | |
{ |
143 | 0 | return ignoreManagementNotifications; |
144 | |
} |
145 | |
|
146 | |
public void setIgnoreManagementNotifications(boolean ignoreManagementNotifications) |
147 | |
{ |
148 | 0 | this.ignoreManagementNotifications = ignoreManagementNotifications; |
149 | 0 | } |
150 | |
|
151 | |
public boolean isIgnoreCustomNotifications() |
152 | |
{ |
153 | 0 | return ignoreCustomNotifications; |
154 | |
} |
155 | |
|
156 | |
public void setIgnoreCustomNotifications(boolean ignoreCustomNotifications) |
157 | |
{ |
158 | 0 | this.ignoreCustomNotifications = ignoreCustomNotifications; |
159 | 0 | } |
160 | |
|
161 | |
public boolean isIgnoreAdminNotifications() |
162 | |
{ |
163 | 0 | return ignoreAdminNotifications; |
164 | |
} |
165 | |
|
166 | |
public void setIgnoreAdminNotifications(boolean ignoreAdminNotifications) |
167 | |
{ |
168 | 0 | this.ignoreAdminNotifications = ignoreAdminNotifications; |
169 | 0 | } |
170 | |
|
171 | |
public boolean isIgnoreConnectionNotifications() |
172 | |
{ |
173 | 0 | return ignoreConnectionNotifications; |
174 | |
} |
175 | |
|
176 | |
public void setIgnoreConnectionNotifications(boolean ignoreConnectionNotifications) |
177 | |
{ |
178 | 0 | this.ignoreConnectionNotifications = ignoreConnectionNotifications; |
179 | 0 | } |
180 | |
|
181 | |
public boolean isIgnoreComponentMessageNotifications() |
182 | |
{ |
183 | 0 | return ignoreComponentMessageNotifications; |
184 | |
} |
185 | |
|
186 | |
public void setIgnoreComponentMessageNotifications(boolean ignoreComponentMessageNotifications) |
187 | |
{ |
188 | 0 | this.ignoreComponentMessageNotifications = ignoreComponentMessageNotifications; |
189 | 0 | } |
190 | |
|
191 | |
public boolean isIgnoreEndpointMessageNotifications() |
192 | |
{ |
193 | 0 | return ignoreEndpointMessageNotifications; |
194 | |
} |
195 | |
|
196 | |
public void setIgnoreEndpointMessageNotifications(boolean ignoreEndpointMessageNotifications) |
197 | |
{ |
198 | 0 | this.ignoreEndpointMessageNotifications = ignoreEndpointMessageNotifications; |
199 | 0 | } |
200 | |
|
201 | |
public final void initialise() throws InitialisationException |
202 | |
{ |
203 | 0 | doInitialise(); |
204 | 0 | if (!ignoreManagerNotifications) |
205 | |
{ |
206 | 0 | ServerNotificationListener<MuleContextNotification> l |
207 | |
= new MuleContextNotificationListener<MuleContextNotification>() |
208 | 0 | { |
209 | |
public void onNotification(MuleContextNotification notification) |
210 | |
{ |
211 | 0 | logEvent(notification); |
212 | 0 | } |
213 | |
}; |
214 | |
try |
215 | |
{ |
216 | 0 | muleContext.registerListener(l); |
217 | |
} |
218 | 0 | catch (NotificationException e) |
219 | |
{ |
220 | 0 | throw new InitialisationException(e, this); |
221 | 0 | } |
222 | 0 | listeners.add(l); |
223 | |
} |
224 | 0 | if (!ignoreModelNotifications) |
225 | |
{ |
226 | 0 | ServerNotificationListener<ModelNotification> l |
227 | |
= new ModelNotificationListener<ModelNotification>() |
228 | 0 | { |
229 | |
public void onNotification(ModelNotification notification) |
230 | |
{ |
231 | 0 | logEvent(notification); |
232 | 0 | } |
233 | |
}; |
234 | |
try |
235 | |
{ |
236 | 0 | muleContext.registerListener(l); |
237 | |
} |
238 | 0 | catch (NotificationException e) |
239 | |
{ |
240 | 0 | throw new InitialisationException(e, this); |
241 | 0 | } |
242 | 0 | listeners.add(l); |
243 | |
} |
244 | 0 | if (!ignoreComponentNotifications) |
245 | |
{ |
246 | 0 | ServerNotificationListener<ServiceNotification> l |
247 | |
= new ServiceNotificationListener<ServiceNotification>() |
248 | 0 | { |
249 | |
public void onNotification(ServiceNotification notification) |
250 | |
{ |
251 | 0 | logEvent(notification); |
252 | 0 | } |
253 | |
}; |
254 | |
try |
255 | |
{ |
256 | 0 | muleContext.registerListener(l); |
257 | |
} |
258 | 0 | catch (NotificationException e) |
259 | |
{ |
260 | 0 | throw new InitialisationException(e, this); |
261 | 0 | } |
262 | 0 | listeners.add(l); |
263 | |
} |
264 | 0 | if (!ignoreSecurityNotifications) |
265 | |
{ |
266 | 0 | ServerNotificationListener<SecurityNotification> l |
267 | |
= new SecurityNotificationListener<SecurityNotification>() |
268 | 0 | { |
269 | |
public void onNotification(SecurityNotification notification) |
270 | |
{ |
271 | 0 | logEvent(notification); |
272 | 0 | } |
273 | |
}; |
274 | |
try |
275 | |
{ |
276 | 0 | muleContext.registerListener(l); |
277 | |
} |
278 | 0 | catch (NotificationException e) |
279 | |
{ |
280 | 0 | throw new InitialisationException(e, this); |
281 | 0 | } |
282 | 0 | listeners.add(l); |
283 | |
} |
284 | |
|
285 | 0 | if (!ignoreManagementNotifications) |
286 | |
{ |
287 | 0 | ServerNotificationListener<ManagementNotification> l |
288 | |
= new ManagementNotificationListener<ManagementNotification>() |
289 | 0 | { |
290 | |
public void onNotification(ManagementNotification notification) |
291 | |
{ |
292 | 0 | logEvent(notification); |
293 | 0 | } |
294 | |
}; |
295 | |
try |
296 | |
{ |
297 | 0 | muleContext.registerListener(l); |
298 | |
} |
299 | 0 | catch (NotificationException e) |
300 | |
{ |
301 | 0 | throw new InitialisationException(e, this); |
302 | 0 | } |
303 | 0 | listeners.add(l); |
304 | |
} |
305 | |
|
306 | 0 | if (!ignoreCustomNotifications) |
307 | |
{ |
308 | 0 | ServerNotificationListener l = new CustomNotificationListener() |
309 | 0 | { |
310 | |
public void onNotification(ServerNotification notification) |
311 | |
{ |
312 | 0 | logEvent(notification); |
313 | 0 | } |
314 | |
}; |
315 | |
try |
316 | |
{ |
317 | 0 | muleContext.registerListener(l); |
318 | |
} |
319 | 0 | catch (NotificationException e) |
320 | |
{ |
321 | 0 | throw new InitialisationException(e, this); |
322 | 0 | } |
323 | 0 | listeners.add(l); |
324 | |
} |
325 | |
|
326 | 0 | if (!ignoreConnectionNotifications) |
327 | |
{ |
328 | 0 | ServerNotificationListener<ConnectionNotification> l |
329 | |
= new ConnectionNotificationListener<ConnectionNotification>() |
330 | 0 | { |
331 | |
public void onNotification(ConnectionNotification notification) |
332 | |
{ |
333 | 0 | logEvent(notification); |
334 | 0 | } |
335 | |
}; |
336 | |
try |
337 | |
{ |
338 | 0 | muleContext.registerListener(l); |
339 | |
} |
340 | 0 | catch (NotificationException e) |
341 | |
{ |
342 | 0 | throw new InitialisationException(e, this); |
343 | 0 | } |
344 | 0 | listeners.add(l); |
345 | |
} |
346 | |
|
347 | 0 | if (!ignoreMessageNotifications && !ignoreEndpointMessageNotifications) |
348 | |
{ |
349 | 0 | ServerNotificationListener<EndpointMessageNotification> l = |
350 | |
new EndpointMessageNotificationListener<EndpointMessageNotification>() |
351 | 0 | { |
352 | |
public void onNotification(EndpointMessageNotification notification) |
353 | |
{ |
354 | 0 | logEvent(notification); |
355 | 0 | } |
356 | |
}; |
357 | |
try |
358 | |
{ |
359 | 0 | muleContext.registerListener(l); |
360 | |
} |
361 | 0 | catch (NotificationException e) |
362 | |
{ |
363 | 0 | throw new InitialisationException(e, this); |
364 | 0 | } |
365 | 0 | listeners.add(l); |
366 | |
} |
367 | |
|
368 | 0 | if (!ignoreMessageNotifications && !ignoreComponentMessageNotifications) |
369 | |
{ |
370 | 0 | ServerNotificationListener<ComponentMessageNotification> l = |
371 | |
new ComponentMessageNotificationListener<ComponentMessageNotification>() |
372 | 0 | { |
373 | |
public void onNotification(ComponentMessageNotification notification) |
374 | |
{ |
375 | 0 | logEvent(notification); |
376 | 0 | } |
377 | |
}; |
378 | |
try |
379 | |
{ |
380 | 0 | muleContext.registerListener(l); |
381 | |
} |
382 | 0 | catch (NotificationException e) |
383 | |
{ |
384 | 0 | throw new InitialisationException(e, this); |
385 | 0 | } |
386 | 0 | listeners.add(l); |
387 | |
} |
388 | |
|
389 | 0 | } |
390 | |
|
391 | |
protected abstract void doInitialise() throws InitialisationException; |
392 | |
|
393 | |
protected abstract void logEvent(ServerNotification e); |
394 | |
} |