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