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