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.4
Committed: Sat Mar 10 04:03:03 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.3: +6 -5 lines
Log Message:
Changes due to the alterations in the XML creation code. The XMLPacketMaker now
only needs to be created once, and can then be called multiple times to create
XML packets. This should be more efficient in the long run.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.client;
3
4 //---IMPORTS---
5 import uk.ac.ukc.iscream.componentmanager.*;
6 import uk.ac.ukc.iscream.core.*;
7 import uk.ac.ukc.iscream.util.*;
8 import java.util.*;
9
10 /**
11 * A manager for the Monitors.
12 *
13 * @author $Author: ajm4 $
14 * @version $Id: MonitorManager.java,v 1.3 2001/03/02 00:15:59 ajm4 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.3 $";
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 _queue = ClientMain._monitorQueue;
42 _qID = _queue.getQueue();
43 _logger.write(toString(), Logger.SYSINIT, "Initialising");
44 _logger.write(toString(), Logger.SYSMSG, "Creating monitor pipeline for plugin monitors ...");
45
46 // get the configuration for this plug-in setup
47 Configuration config = _refman.getCM().getConfiguration(_name);
48 String pluginsPackage = config.getProperty("Monitor.PluginsPackage");
49 String pluginsList = config.getProperty("Monitor.Plugins");
50
51 StringTokenizer st = new StringTokenizer(pluginsList, ";");
52
53 while(st.hasMoreTokens()) {
54 String className = pluginsPackage + "." + st.nextToken() + _suffix;
55 _logger.write(toString(), Logger.DEBUG, "Attempting to create plugin: "+className);
56
57 // Create an instance of the specified PluginMonitor to include
58 // within the monitorPipe. Add it to the monitorPipeline
59 try {
60 PluginMonitor pm = (PluginMonitor)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
61 _monitorPipeline.add(pm);
62 _logger.write(toString(), Logger.DEBUG, "Added monitor: "+className+" ("+pm.getDescription()+")");
63 }
64 catch (InstantiationException e){
65 _logger.write(toString(), Logger.ERROR, "Failed to instantiate "+className+" to the plugin monitor pipeline.");
66 _logger.write(toString(), Logger.ERROR, e.getMessage());
67 }
68 catch (Exception e){
69 _logger.write(toString(), Logger.ERROR, "Failed to add "+className+" to the plugin monitor pipeline.");
70 _logger.write(toString(), Logger.ERROR, e.toString());
71 }
72 }
73 _logger.write(toString(), Logger.SYSMSG, "The monitor pipeline has been set up with "+_monitorPipeline.size()+" plugin monitors.");
74 }
75
76 //---PUBLIC METHODS---
77
78 public void run() {
79 // construct now, and use multiple times
80 XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
81
82 boolean run=true;
83 while(run) {
84 // attempt to get some data from the Queue
85 String xml = "";
86 try {
87 xml = (String) _queue.get(_qID);
88 }
89 catch(InvalidQueueException e) {
90 _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
91 }
92
93 // make an XML packet
94 XMLPacket packet = null;
95
96 try {
97 packet = xmlPacketMaker.createXMLPacket(xml);
98 } catch(InvalidXMLException e) {
99 _logger.write(toString(), Logger.ERROR, "Invalid XML: "+e);
100 // skip the rest of this loop iteration
101 continue;
102 }
103
104 // for each monitor in the pipeline...
105 Iterator pluginMonitors = _monitorPipeline.iterator();
106 while (pluginMonitors.hasNext()){
107 PluginMonitor monitor = (PluginMonitor)pluginMonitors.next();
108 monitor.analysePacket(packet);
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 * This uses the uk.ac.ukc.iscream.util.FormatName class
118 * 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 monitor classes:
169 */
170 private final String _suffix = "__Monitor";
171
172 /**
173 * LinkedList for holding the PluginMonitor objects (the pipeline).
174 */
175 private LinkedList _monitorPipeline = new LinkedList();
176
177 //---STATIC ATTRIBUTES---
178
179 /**
180 * A reference to the single instance of this class
181 */
182 private static MonitorManager _instance;
183
184 }