1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.3 |
package uk.org.iscream.client; |
3 |
ajm |
1.1 |
|
4 |
|
|
//---IMPORTS--- |
5 |
tdb |
1.3 |
import uk.org.iscream.componentmanager.*; |
6 |
|
|
import uk.org.iscream.core.*; |
7 |
|
|
import uk.org.iscream.util.*; |
8 |
ajm |
1.1 |
import java.util.*; |
9 |
|
|
|
10 |
|
|
/** |
11 |
ajm |
1.5 |
* A manager for the Alerters. |
12 |
ajm |
1.1 |
* |
13 |
ajm |
1.7 |
* This class starts by loading all the alerters as specificed in the configuration. |
14 |
|
|
* These alerters should implement the PluginAlerter interface. |
15 |
|
|
* |
16 |
|
|
* This class is then simply a reference point for the Alerters to get hooks on |
17 |
|
|
* the various parts of the system that they require. |
18 |
|
|
* |
19 |
tdb |
1.8 |
* @author $Author: ajm4 $ |
20 |
|
|
* @version $Id: AlerterManager.java,v 1.7 2001/03/23 02:30:44 ajm4 Exp $ |
21 |
ajm |
1.1 |
*/ |
22 |
ajm |
1.5 |
public class AlerterManager extends Thread { |
23 |
ajm |
1.1 |
|
24 |
|
|
//---FINAL ATTRIBUTES--- |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* The current CVS revision of this class |
28 |
|
|
*/ |
29 |
tdb |
1.8 |
public static final String REVISION = "$Revision: 1.7 $"; |
30 |
ajm |
1.1 |
|
31 |
|
|
//---STATIC METHODS--- |
32 |
|
|
|
33 |
|
|
/** |
34 |
|
|
* Return a reference to the single class. |
35 |
|
|
* Construct it if it does not already exist, otherwise just return the reference. |
36 |
|
|
*/ |
37 |
tdb |
1.6 |
public synchronized static AlerterManager getInstance() { |
38 |
ajm |
1.1 |
if (_instance == null){ |
39 |
|
|
_instance = new AlerterManager(); |
40 |
|
|
} |
41 |
|
|
return _instance; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
//---CONSTRUCTORS--- |
45 |
ajm |
1.7 |
|
46 |
|
|
/** |
47 |
|
|
* Constructs a new AlerterManager. |
48 |
|
|
* This initialises all the queues and loads |
49 |
|
|
* all the Alerters that have been specified in the configuration |
50 |
|
|
*/ |
51 |
tdb |
1.2 |
private AlerterManager() { |
52 |
|
|
// set our name |
53 |
|
|
setName("client.AlerterManager"); |
54 |
|
|
|
55 |
ajm |
1.1 |
_logger.write(toString(), Logger.SYSINIT, "Initialising"); |
56 |
|
|
_logger.write(toString(), Logger.SYSMSG, "Creating alerter pipeline for plugin alerters ..."); |
57 |
|
|
|
58 |
tdb |
1.4 |
// get the config proxy |
59 |
|
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
60 |
|
|
|
61 |
ajm |
1.1 |
// get the configuration for this plug-in setup |
62 |
tdb |
1.4 |
String pluginsPackage, pluginsList; |
63 |
|
|
try { |
64 |
|
|
pluginsPackage = cp.getProperty(_name, "Alerter.PluginsPackage"); |
65 |
|
|
pluginsList = cp.getProperty(_name, "Alerter.Plugins"); |
66 |
|
|
} catch(PropertyNotFoundException e) { |
67 |
|
|
_logger.write(toString(), Logger.WARNING, "Unable to get required configuration, Alerter's will not be activated: "+e); |
68 |
|
|
// setting these will ensure we don't build a pipeline |
69 |
|
|
pluginsPackage = ""; |
70 |
|
|
pluginsList = ""; |
71 |
|
|
} |
72 |
ajm |
1.1 |
|
73 |
|
|
StringTokenizer st = new StringTokenizer(pluginsList, ";"); |
74 |
|
|
|
75 |
|
|
while(st.hasMoreTokens()) { |
76 |
|
|
String className = pluginsPackage + "." + st.nextToken() + _suffix; |
77 |
|
|
_logger.write(toString(), Logger.DEBUG, "Attempting to create plugin: "+className); |
78 |
|
|
|
79 |
|
|
// Create an instance of the specified PluginAlerter to include |
80 |
|
|
// within the alerterPipe. Add it to the alerterPipeline |
81 |
|
|
try { |
82 |
|
|
PluginAlerter pa = (PluginAlerter)ClassLoader.getSystemClassLoader().loadClass(className).newInstance(); |
83 |
|
|
_alerterPipeline.add(pa); |
84 |
|
|
_logger.write(toString(), Logger.DEBUG, "Added alerter: "+className+" ("+pa.getDescription()+")"); |
85 |
|
|
} |
86 |
|
|
catch (InstantiationException e){ |
87 |
|
|
_logger.write(toString(), Logger.ERROR, "Failed to instantiate "+className+" to the plugin alerter pipeline."); |
88 |
|
|
_logger.write(toString(), Logger.ERROR, e.getMessage()); |
89 |
|
|
} |
90 |
|
|
catch (Exception e){ |
91 |
|
|
_logger.write(toString(), Logger.ERROR, "Failed to add "+className+" to the plugin alerter pipeline."); |
92 |
|
|
_logger.write(toString(), Logger.ERROR, e.toString()); |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
_logger.write(toString(), Logger.SYSMSG, "The alerter pipeline has been set up with "+_alerterPipeline.size()+" plugin alerters."); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
//---PUBLIC METHODS--- |
99 |
|
|
|
100 |
|
|
/** |
101 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
102 |
|
|
* method to provide clean logging (every class should have this). |
103 |
|
|
* |
104 |
tdb |
1.3 |
* This uses the uk.org.iscream.util.FormatName class |
105 |
ajm |
1.1 |
* to format the toString() |
106 |
|
|
* |
107 |
|
|
* @return the name of this class and its CVS revision |
108 |
|
|
*/ |
109 |
|
|
public String toString() { |
110 |
|
|
return FormatName.getName( |
111 |
|
|
_name, |
112 |
|
|
getClass().getName(), |
113 |
|
|
REVISION); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
//---PRIVATE METHODS--- |
117 |
|
|
|
118 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
119 |
ajm |
1.5 |
|
120 |
|
|
/** |
121 |
|
|
* Allows alerters to obtain a reference |
122 |
|
|
* to the alerting queue so that they can |
123 |
|
|
* process any alerts |
124 |
|
|
* |
125 |
|
|
* @return a reference to the alert queue |
126 |
|
|
*/ |
127 |
|
|
public Queue getQueue() { |
128 |
tdb |
1.8 |
return ClientMain._alerterQueue; |
129 |
ajm |
1.5 |
} |
130 |
ajm |
1.1 |
|
131 |
|
|
//---ATTRIBUTES--- |
132 |
|
|
|
133 |
|
|
/** |
134 |
|
|
* This is the friendly identifier of the |
135 |
|
|
* component this class is running in. |
136 |
|
|
* eg, a Filter may be called "filter1", |
137 |
|
|
* If this class does not have an owning |
138 |
|
|
* component, a name from the configuration |
139 |
|
|
* can be placed here. This name could also |
140 |
|
|
* be changed to null for utility classes. |
141 |
|
|
*/ |
142 |
|
|
private String _name = ClientMain.NAME; |
143 |
|
|
|
144 |
|
|
/** |
145 |
|
|
* This holds a reference to the |
146 |
|
|
* system logger that is being used. |
147 |
|
|
*/ |
148 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
149 |
|
|
|
150 |
|
|
/** |
151 |
|
|
* A reference to the reference manager in use |
152 |
|
|
*/ |
153 |
|
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
154 |
|
|
|
155 |
|
|
/** |
156 |
|
|
* file name suffix for plugin alerter classes: |
157 |
|
|
*/ |
158 |
|
|
private final String _suffix = "__Alerter"; |
159 |
|
|
|
160 |
|
|
/** |
161 |
|
|
* LinkedList for holding the PluginAlerter objects (the pipeline). |
162 |
|
|
*/ |
163 |
|
|
private LinkedList _alerterPipeline = new LinkedList(); |
164 |
|
|
|
165 |
|
|
//---STATIC ATTRIBUTES--- |
166 |
|
|
|
167 |
|
|
/** |
168 |
|
|
* A reference to the single instance of this class |
169 |
|
|
*/ |
170 |
|
|
private static AlerterManager _instance; |
171 |
|
|
|
172 |
|
|
} |