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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/MonitorManager.java (file contents):
Revision 1.2 by tdb, Thu Mar 1 16:52:25 2001 UTC vs.
Revision 1.3 by ajm, Fri Mar 2 00:15:59 2001 UTC

# Line 13 | Line 13 | import java.util.*;
13   * @author  $Author$
14   * @version $Id$
15   */
16 < class MonitorManager extends Thread{
16 > class MonitorManager extends Thread {
17  
18   //---FINAL ATTRIBUTES---
19  
# Line 24 | Line 24 | class MonitorManager extends Thread{
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 <    public MonitorManager(Queue queue) {
41 <        _queue = queue;
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 <        LinkedList monitors = setupMonitors();
37 <        int qID = _queue.getQueue();
79 >        
80          boolean run=true;
81          while(run) {
82              // attempt to get some data from the Queue
83              String xml = "";
84              try {
85 <                xml = (String) _queue.get(qID);
85 >                xml = (String) _queue.get(_qID);
86              }
87              catch(InvalidQueueException e) {
88                  _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
# Line 58 | Line 100 | class MonitorManager extends Thread{
100                  continue;
101              }
102                          
103 <            //send to monitors
104 <            Iterator i = monitors.iterator();
105 <            while(i.hasNext()) {
106 <                ((Monitor) i.next()).analysePacket(packet);
103 >            // for each monitor in the pipeline...
104 >            Iterator pluginMonitors = _monitorPipeline.iterator();
105 >            while (pluginMonitors.hasNext()){
106 >                PluginMonitor monitor = (PluginMonitor)pluginMonitors.next();
107 >                monitor.analysePacket(packet);
108              }
66            
67            // is that all ?
109          }
110      }
111  
# Line 85 | Line 126 | class MonitorManager extends Thread{
126      }
127  
128   //---PRIVATE METHODS---
88    
89    // this should be changed to do something a bit
90    // more interesting :)
91    private LinkedList setupMonitors() {
92        LinkedList monitors = new LinkedList();
93        // add monitors - this should use config/reflection...
94        monitors.add(new uk.ac.ukc.iscream.client.monitors.CPU__Monitor());
95        return monitors;
96    }
129  
130   //---ACCESSOR/MUTATOR METHODS---
131  
# Line 117 | Line 149 | class MonitorManager extends Thread{
149      private Logger _logger = ReferenceManager.getInstance().getLogger();
150      
151      /**
152 <     * A reference to our QUeue
152 >     * A reference to the reference manager in use
153       */
154 +    private ReferenceManager _refman = ReferenceManager.getInstance();
155 +    
156 +    /**
157 +     * A reference to our Queue
158 +     */
159      private Queue _queue;
160 +    
161 +    /**
162 +     * Our queue ID
163 +     */
164 +    private int _qID;
165 +    
166 +    /**
167 +     * file name suffix for plugin monitor classes:
168 +     */
169 +    private final String _suffix = "__Monitor";
170 +    
171 +    /**
172 +     * LinkedList for holding the PluginMonitor objects (the pipeline).
173 +     */
174 +    private LinkedList _monitorPipeline = new LinkedList();
175  
176   //---STATIC ATTRIBUTES---
177 +
178 +    /**
179 +     * A reference to the single instance of this class
180 +     */
181 +    private static MonitorManager _instance;
182  
183   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines