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.4
Committed: Thu Mar 15 22:12:22 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.3: +15 -5 lines
Log Message:
Seems I missed updating the configuration sections in these files.

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     * A manager for the Monitors.
12     *
13 tdb 1.3 * @author $Author: tdb1 $
14 tdb 1.4 * @version $Id: AlerterManager.java,v 1.3 2001/03/14 23:25:29 tdb1 Exp $
15 ajm 1.1 */
16     class AlerterManager extends Thread {
17    
18     //---FINAL ATTRIBUTES---
19    
20     /**
21     * The current CVS revision of this class
22     */
23 tdb 1.4 public static final String REVISION = "$Revision: 1.3 $";
24 ajm 1.1
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 tdb 1.2 private AlerterManager() {
41     // set our name
42     setName("client.AlerterManager");
43    
44 ajm 1.1 _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 tdb 1.4 // get the config proxy
50     ConfigurationProxy cp = ConfigurationProxy.getInstance();
51    
52 ajm 1.1 // get the configuration for this plug-in setup
53 tdb 1.4 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 ajm 1.1
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     public void run() {
92    
93     boolean run=true;
94     while(run) {
95     // attempt to get some data from the Queue
96     Alert alert = null;
97     try {
98     alert = (Alert) _queue.get(_qID);
99     }
100     catch(InvalidQueueException e) {
101     _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
102     }
103    
104     // for each alerter in the pipeline...
105     Iterator pluginAlerters = _alerterPipeline.iterator();
106     while (pluginAlerters.hasNext()){
107     PluginAlerter alerter = (PluginAlerter)pluginAlerters.next();
108     alerter.sendAlert(alert);
109     }
110     }
111     }
112    
113     /**
114     * Overrides the {@link java.lang.Object#toString() Object.toString()}
115     * method to provide clean logging (every class should have this).
116     *
117 tdb 1.3 * This uses the uk.org.iscream.util.FormatName class
118 ajm 1.1 * to format the toString()
119     *
120     * @return the name of this class and its CVS revision
121     */
122     public String toString() {
123     return FormatName.getName(
124     _name,
125     getClass().getName(),
126     REVISION);
127     }
128    
129     //---PRIVATE METHODS---
130    
131     //---ACCESSOR/MUTATOR METHODS---
132    
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     }