KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > internal > admin > AbstractNotificationLoggerAgent


1 /*
2  * $Id: AbstractNotificationLoggerAgent.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.impl.internal.admin;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.MuleManager;
16 import org.mule.impl.internal.notifications.AdminNotificationListener;
17 import org.mule.impl.internal.notifications.ComponentNotificationListener;
18 import org.mule.impl.internal.notifications.ConnectionNotificationListener;
19 import org.mule.impl.internal.notifications.CustomNotificationListener;
20 import org.mule.impl.internal.notifications.ManagementNotificationListener;
21 import org.mule.impl.internal.notifications.ManagerNotificationListener;
22 import org.mule.impl.internal.notifications.MessageNotificationListener;
23 import org.mule.impl.internal.notifications.ModelNotificationListener;
24 import org.mule.impl.internal.notifications.NotificationException;
25 import org.mule.impl.internal.notifications.SecurityNotificationListener;
26 import org.mule.umo.UMOException;
27 import org.mule.umo.lifecycle.InitialisationException;
28 import org.mule.umo.manager.UMOAgent;
29 import org.mule.umo.manager.UMOManager;
30 import org.mule.umo.manager.UMOServerNotification;
31 import org.mule.umo.manager.UMOServerNotificationListener;
32
33 import java.util.HashSet JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.Set JavaDoc;
36
37 /**
38  * <code>AbstractNotificationLoggerAgent</code> Receives Mule server notifications
39  * and logs them and can optionally route them to an endpoint
40  *
41  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
42  * @version $Revision: 3798 $
43  */

44 public abstract class AbstractNotificationLoggerAgent implements UMOAgent
45 {
46     /**
47      * The logger used for this class
48      */

49     protected transient Log logger = LogFactory.getLog(getClass());
50
51     private String JavaDoc name;
52
53     private boolean ignoreManagerNotifications = false;
54     private boolean ignoreModelNotifications = false;
55     private boolean ignoreComponentNotifications = false;
56     private boolean ignoreConnectionNotifications = false;
57     private boolean ignoreSecurityNotifications = false;
58     private boolean ignoreManagementNotifications = false;
59     private boolean ignoreCustomNotifications = false;
60     private boolean ignoreAdminNotifications = false;
61     private boolean ignoreMessageNotifications = false;
62
63     private Set JavaDoc listeners = new HashSet JavaDoc();
64
65     /**
66      * Gets the name of this agent
67      *
68      * @return the agent name
69      */

70     public String JavaDoc getName()
71     {
72         return name;
73     }
74
75     /**
76      * Sets the name of this agent
77      *
78      * @param name the name of the agent
79      */

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