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