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