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.7
Committed: Fri Mar 23 02:30:44 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.6: +15 -4 lines
Log Message:
Javadoc'd the whole bally lot.

File Contents

# User Rev Content
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     * @author $Author: tdb1 $
20     * @version $Id: AlerterManager.java,v 1.6 2001/03/23 00:05:23 tdb1 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 ajm 1.7 public static final String REVISION = "$Revision: 1.6 $";
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 _queue = ClientMain._alerterQueue;
56     _qID = _queue.getQueue();
57     _logger.write(toString(), Logger.SYSINIT, "Initialising");
58     _logger.write(toString(), Logger.SYSMSG, "Creating alerter pipeline for plugin alerters ...");
59    
60 tdb 1.4 // get the config proxy
61     ConfigurationProxy cp = ConfigurationProxy.getInstance();
62    
63 ajm 1.1 // get the configuration for this plug-in setup
64 tdb 1.4 String pluginsPackage, pluginsList;
65     try {
66     pluginsPackage = cp.getProperty(_name, "Alerter.PluginsPackage");
67     pluginsList = cp.getProperty(_name, "Alerter.Plugins");
68     } catch(PropertyNotFoundException e) {
69     _logger.write(toString(), Logger.WARNING, "Unable to get required configuration, Alerter's will not be activated: "+e);
70     // setting these will ensure we don't build a pipeline
71     pluginsPackage = "";
72     pluginsList = "";
73     }
74 ajm 1.1
75     StringTokenizer st = new StringTokenizer(pluginsList, ";");
76    
77     while(st.hasMoreTokens()) {
78     String className = pluginsPackage + "." + st.nextToken() + _suffix;
79     _logger.write(toString(), Logger.DEBUG, "Attempting to create plugin: "+className);
80    
81     // Create an instance of the specified PluginAlerter to include
82     // within the alerterPipe. Add it to the alerterPipeline
83     try {
84     PluginAlerter pa = (PluginAlerter)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
85     _alerterPipeline.add(pa);
86     _logger.write(toString(), Logger.DEBUG, "Added alerter: "+className+" ("+pa.getDescription()+")");
87     }
88     catch (InstantiationException e){
89     _logger.write(toString(), Logger.ERROR, "Failed to instantiate "+className+" to the plugin alerter pipeline.");
90     _logger.write(toString(), Logger.ERROR, e.getMessage());
91     }
92     catch (Exception e){
93     _logger.write(toString(), Logger.ERROR, "Failed to add "+className+" to the plugin alerter pipeline.");
94     _logger.write(toString(), Logger.ERROR, e.toString());
95     }
96     }
97     _logger.write(toString(), Logger.SYSMSG, "The alerter pipeline has been set up with "+_alerterPipeline.size()+" plugin alerters.");
98     }
99    
100     //---PUBLIC METHODS---
101    
102     /**
103     * Overrides the {@link java.lang.Object#toString() Object.toString()}
104     * method to provide clean logging (every class should have this).
105     *
106 tdb 1.3 * This uses the uk.org.iscream.util.FormatName class
107 ajm 1.1 * to format the toString()
108     *
109     * @return the name of this class and its CVS revision
110     */
111     public String toString() {
112     return FormatName.getName(
113     _name,
114     getClass().getName(),
115     REVISION);
116     }
117    
118     //---PRIVATE METHODS---
119    
120     //---ACCESSOR/MUTATOR METHODS---
121 ajm 1.5
122     /**
123     * Allows alerters to obtain a reference
124     * to the alerting queue so that they can
125     * process any alerts
126     *
127     * @return a reference to the alert queue
128     */
129     public Queue getQueue() {
130     return _queue;
131     }
132 ajm 1.1
133     //---ATTRIBUTES---
134    
135     /**
136     * This is the friendly identifier of the
137     * component this class is running in.
138     * eg, a Filter may be called "filter1",
139     * If this class does not have an owning
140     * component, a name from the configuration
141     * can be placed here. This name could also
142     * be changed to null for utility classes.
143     */
144     private String _name = ClientMain.NAME;
145    
146     /**
147     * This holds a reference to the
148     * system logger that is being used.
149     */
150     private Logger _logger = ReferenceManager.getInstance().getLogger();
151    
152     /**
153     * A reference to the reference manager in use
154     */
155     private ReferenceManager _refman = ReferenceManager.getInstance();
156    
157     /**
158     * A reference to our Queue
159     */
160     private Queue _queue;
161    
162     /**
163     * Our queue ID
164     */
165     private int _qID;
166    
167     /**
168     * file name suffix for plugin alerter classes:
169     */
170     private final String _suffix = "__Alerter";
171    
172     /**
173     * LinkedList for holding the PluginAlerter objects (the pipeline).
174     */
175     private LinkedList _alerterPipeline = new LinkedList();
176    
177     //---STATIC ATTRIBUTES---
178    
179     /**
180     * A reference to the single instance of this class
181     */
182     private static AlerterManager _instance;
183    
184     }