ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/AlerterManager.java
Revision: 1.5
Committed: Thu Mar 22 22:07:14 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.4: +15 -26 lines
Log Message:
Rejigged to use the same queuing structure as the Monitors.

File Contents

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