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.1 by tdb, Tue Feb 27 01:00:43 2001 UTC vs.
Revision 1.7 by tdb, Thu Mar 15 18:59:50 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.client;
2 > package uk.org.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.*;
5 > import uk.org.iscream.componentmanager.*;
6 > import uk.org.iscream.core.*;
7 > import uk.org.iscream.util.*;
8   import java.util.*;
9  
10   /**
# 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 >        // 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 <        LinkedList monitors = setupMonitors();
83 <        int qID = _queue.getQueue();
82 >        // construct now, and use multiple times
83 >        XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
84 >        
85          boolean run=true;
86 +        
87 +        // keep these out here, saves recreating the object
88 +        String xml = null;
89          while(run) {
40            // attempt to get some data from the Queue
41            String xml = "";
90              try {
91 <                xml = (String) _queue.get(qID);
91 >                xml = (String) _queue.get(_qID);
92              }
93              catch(InvalidQueueException e) {
94                  _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
95              }
96              
97              // make an XML packet
98 <            XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
51 <            XMLPacket packet = xmlPacketMaker.createXMLPacket();
98 >            XMLPacket packet = null;
99              
100 <            //send to monitors
101 <            Iterator i = monitors.iterator();
102 <            while(i.hasNext()) {
103 <                ((Monitor) i.next()).analysePacket(packet);
100 >            try {
101 >                packet = xmlPacketMaker.createXMLPacket(xml);
102 >            } 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 <            // is that all ?
107 >                        
108 >            // 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 >            }
114          }
115      }
116  
# Line 64 | Line 118 | class MonitorManager extends Thread{
118       * Overrides the {@link java.lang.Object#toString() Object.toString()}
119       * method to provide clean logging (every class should have this).
120       *
121 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
121 >     * This uses the uk.org.iscream.util.FormatName class
122       * to format the toString()
123       *
124       * @return the name of this class and its CVS revision
# Line 77 | Line 131 | class MonitorManager extends Thread{
131      }
132  
133   //---PRIVATE METHODS---
80    
81    // this should be changed to do something a bit
82    // more interesting :)
83    private LinkedList setupMonitors() {
84        LinkedList monitors = new LinkedList();
85        // add monitors - this should use config/reflection...
86        monitors.add(new uk.ac.ukc.iscream.client.monitors.CPU__Monitor());
87        return monitors;
88    }
134  
135   //---ACCESSOR/MUTATOR METHODS---
136  
# Line 109 | Line 154 | class MonitorManager extends Thread{
154      private Logger _logger = ReferenceManager.getInstance().getLogger();
155      
156      /**
157 <     * A reference to our QUeue
157 >     * A reference to the reference manager in use
158       */
159 +    private ReferenceManager _refman = ReferenceManager.getInstance();
160 +    
161 +    /**
162 +     * A reference to our Queue
163 +     */
164      private Queue _queue;
165 +    
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  
181   //---STATIC ATTRIBUTES---
182 +
183 +    /**
184 +     * A reference to the single instance of this class
185 +     */
186 +    private static MonitorManager _instance;
187  
188   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines