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.12
Committed: Wed Feb 5 16:43:44 2003 UTC (21 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.11: +4 -4 lines
Log Message:
Changed the server to use the external util package. Quite a minor change,
but does affect a lot of files.

File Contents

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