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/MonitorManager.java
Revision: 1.7
Committed: Thu Mar 15 18:59:50 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.6: +5 -4 lines
Log Message:
A small change to make the code more proper in creation of strings.

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 tdb 1.6 package uk.org.iscream.client;
3 tdb 1.1
4     //---IMPORTS---
5 tdb 1.6 import uk.org.iscream.componentmanager.*;
6     import uk.org.iscream.core.*;
7     import uk.org.iscream.util.*;
8 tdb 1.1 import java.util.*;
9    
10     /**
11     * A manager for the Monitors.
12     *
13 tdb 1.5 * @author $Author: tdb1 $
14 tdb 1.7 * @version $Id: MonitorManager.java,v 1.6 2001/03/14 23:25:29 tdb1 Exp $
15 tdb 1.1 */
16 ajm 1.3 class MonitorManager extends Thread {
17 tdb 1.1
18     //---FINAL ATTRIBUTES---
19    
20     /**
21     * The current CVS revision of this class
22     */
23 tdb 1.7 public static final String REVISION = "$Revision: 1.6 $";
24 tdb 1.1
25     //---STATIC METHODS---
26    
27 ajm 1.3 /**
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 MonitorManager getInstance() {
32     if (_instance == null){
33     _instance = new MonitorManager();
34     }
35     return _instance;
36     }
37    
38 tdb 1.1 //---CONSTRUCTORS---
39    
40 ajm 1.3 private MonitorManager() {
41 tdb 1.5 // set our name
42     setName("client.MonitorManager");
43    
44 ajm 1.3 _queue = ClientMain._monitorQueue;
45     _qID = _queue.getQueue();
46     _logger.write(toString(), Logger.SYSINIT, "Initialising");
47     _logger.write(toString(), Logger.SYSMSG, "Creating monitor pipeline for plugin monitors ...");
48    
49     // get the configuration for this plug-in setup
50     Configuration config = _refman.getCM().getConfiguration(_name);
51     String pluginsPackage = config.getProperty("Monitor.PluginsPackage");
52     String pluginsList = config.getProperty("Monitor.Plugins");
53    
54     StringTokenizer st = new StringTokenizer(pluginsList, ";");
55    
56     while(st.hasMoreTokens()) {
57     String className = pluginsPackage + "." + st.nextToken() + _suffix;
58     _logger.write(toString(), Logger.DEBUG, "Attempting to create plugin: "+className);
59    
60     // Create an instance of the specified PluginMonitor to include
61     // within the monitorPipe. Add it to the monitorPipeline
62     try {
63     PluginMonitor pm = (PluginMonitor)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
64     _monitorPipeline.add(pm);
65     _logger.write(toString(), Logger.DEBUG, "Added monitor: "+className+" ("+pm.getDescription()+")");
66     }
67     catch (InstantiationException e){
68     _logger.write(toString(), Logger.ERROR, "Failed to instantiate "+className+" to the plugin monitor pipeline.");
69     _logger.write(toString(), Logger.ERROR, e.getMessage());
70     }
71     catch (Exception e){
72     _logger.write(toString(), Logger.ERROR, "Failed to add "+className+" to the plugin monitor pipeline.");
73     _logger.write(toString(), Logger.ERROR, e.toString());
74     }
75     }
76     _logger.write(toString(), Logger.SYSMSG, "The monitor pipeline has been set up with "+_monitorPipeline.size()+" plugin monitors.");
77 tdb 1.1 }
78    
79     //---PUBLIC METHODS---
80    
81     public void run() {
82 tdb 1.4 // construct now, and use multiple times
83     XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
84 ajm 1.3
85 tdb 1.1 boolean run=true;
86 tdb 1.7
87     // keep these out here, saves recreating the object
88     String xml = null;
89 tdb 1.1 while(run) {
90     try {
91 ajm 1.3 xml = (String) _queue.get(_qID);
92 tdb 1.1 }
93     catch(InvalidQueueException e) {
94     _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
95     }
96    
97     // make an XML packet
98 tdb 1.2 XMLPacket packet = null;
99 tdb 1.1
100 tdb 1.2 try {
101 tdb 1.4 packet = xmlPacketMaker.createXMLPacket(xml);
102 tdb 1.2 } catch(InvalidXMLException e) {
103     _logger.write(toString(), Logger.ERROR, "Invalid XML: "+e);
104     // skip the rest of this loop iteration
105     continue;
106     }
107    
108 ajm 1.3 // for each monitor in the pipeline...
109     Iterator pluginMonitors = _monitorPipeline.iterator();
110     while (pluginMonitors.hasNext()){
111     PluginMonitor monitor = (PluginMonitor)pluginMonitors.next();
112     monitor.analysePacket(packet);
113 tdb 1.1 }
114     }
115     }
116    
117     /**
118     * Overrides the {@link java.lang.Object#toString() Object.toString()}
119     * method to provide clean logging (every class should have this).
120     *
121 tdb 1.6 * This uses the uk.org.iscream.util.FormatName class
122 tdb 1.1 * to format the toString()
123     *
124     * @return the name of this class and its CVS revision
125     */
126     public String toString() {
127     return FormatName.getName(
128     _name,
129     getClass().getName(),
130     REVISION);
131     }
132    
133     //---PRIVATE METHODS---
134    
135     //---ACCESSOR/MUTATOR METHODS---
136    
137     //---ATTRIBUTES---
138    
139     /**
140     * This is the friendly identifier of the
141     * component this class is running in.
142     * eg, a Filter may be called "filter1",
143     * If this class does not have an owning
144     * component, a name from the configuration
145     * can be placed here. This name could also
146     * be changed to null for utility classes.
147     */
148     private String _name = ClientMain.NAME;
149    
150     /**
151     * This holds a reference to the
152     * system logger that is being used.
153     */
154     private Logger _logger = ReferenceManager.getInstance().getLogger();
155    
156     /**
157 ajm 1.3 * A reference to the reference manager in use
158     */
159     private ReferenceManager _refman = ReferenceManager.getInstance();
160    
161     /**
162     * A reference to our Queue
163 tdb 1.1 */
164     private Queue _queue;
165 ajm 1.3
166     /**
167     * Our queue ID
168     */
169     private int _qID;
170    
171     /**
172     * file name suffix for plugin monitor classes:
173     */
174     private final String _suffix = "__Monitor";
175    
176     /**
177     * LinkedList for holding the PluginMonitor objects (the pipeline).
178     */
179     private LinkedList _monitorPipeline = new LinkedList();
180 tdb 1.1
181     //---STATIC ATTRIBUTES---
182 ajm 1.3
183     /**
184     * A reference to the single instance of this class
185     */
186     private static MonitorManager _instance;
187 tdb 1.1
188     }