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.6
Committed: Wed Mar 14 23:25:29 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.5: +7 -7 lines
Log Message:
The whole server package structure has been changed.
Old Package: uk.ac.ukc.iscream.*
New Package: uk.org.iscream.*

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 Monitors.
12 *
13 * @author $Author: tdb1 $
14 * @version $Id: MonitorManager.java,v 1.5 2001/03/13 02:19:41 tdb1 Exp $
15 */
16 class MonitorManager 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.5 $";
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 MonitorManager getInstance() {
32 if (_instance == null){
33 _instance = new MonitorManager();
34 }
35 return _instance;
36 }
37
38 //---CONSTRUCTORS---
39
40 private MonitorManager() {
41 // set our name
42 setName("client.MonitorManager");
43
44 _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 }
78
79 //---PUBLIC METHODS---
80
81 public void run() {
82 // construct now, and use multiple times
83 XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
84
85 boolean run=true;
86 while(run) {
87 // attempt to get some data from the Queue
88 String xml = "";
89 try {
90 xml = (String) _queue.get(_qID);
91 }
92 catch(InvalidQueueException e) {
93 _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
94 }
95
96 // make an XML packet
97 XMLPacket packet = null;
98
99 try {
100 packet = xmlPacketMaker.createXMLPacket(xml);
101 } catch(InvalidXMLException e) {
102 _logger.write(toString(), Logger.ERROR, "Invalid XML: "+e);
103 // skip the rest of this loop iteration
104 continue;
105 }
106
107 // for each monitor in the pipeline...
108 Iterator pluginMonitors = _monitorPipeline.iterator();
109 while (pluginMonitors.hasNext()){
110 PluginMonitor monitor = (PluginMonitor)pluginMonitors.next();
111 monitor.analysePacket(packet);
112 }
113 }
114 }
115
116 /**
117 * Overrides the {@link java.lang.Object#toString() Object.toString()}
118 * method to provide clean logging (every class should have this).
119 *
120 * This uses the uk.org.iscream.util.FormatName class
121 * to format the toString()
122 *
123 * @return the name of this class and its CVS revision
124 */
125 public String toString() {
126 return FormatName.getName(
127 _name,
128 getClass().getName(),
129 REVISION);
130 }
131
132 //---PRIVATE METHODS---
133
134 //---ACCESSOR/MUTATOR METHODS---
135
136 //---ATTRIBUTES---
137
138 /**
139 * This is the friendly identifier of the
140 * component this class is running in.
141 * eg, a Filter may be called "filter1",
142 * If this class does not have an owning
143 * component, a name from the configuration
144 * can be placed here. This name could also
145 * be changed to null for utility classes.
146 */
147 private String _name = ClientMain.NAME;
148
149 /**
150 * This holds a reference to the
151 * system logger that is being used.
152 */
153 private Logger _logger = ReferenceManager.getInstance().getLogger();
154
155 /**
156 * A reference to the reference manager in use
157 */
158 private ReferenceManager _refman = ReferenceManager.getInstance();
159
160 /**
161 * A reference to our Queue
162 */
163 private Queue _queue;
164
165 /**
166 * Our queue ID
167 */
168 private int _qID;
169
170 /**
171 * file name suffix for plugin monitor classes:
172 */
173 private final String _suffix = "__Monitor";
174
175 /**
176 * LinkedList for holding the PluginMonitor objects (the pipeline).
177 */
178 private LinkedList _monitorPipeline = new LinkedList();
179
180 //---STATIC ATTRIBUTES---
181
182 /**
183 * A reference to the single instance of this class
184 */
185 private static MonitorManager _instance;
186
187 }