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.7 by tdb, Thu Mar 15 18:59:50 2001 UTC vs.
Revision 1.16 by tdb, Tue May 21 16:47:16 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org.uk
4 + * Copyright (C) 2000-2002 i-scream
5 + *
6 + * This program is free software; you can redistribute it and/or
7 + * modify it under the terms of the GNU General Public License
8 + * as published by the Free Software Foundation; either version 2
9 + * of the License, or (at your option) any later version.
10 + *
11 + * This program is distributed in the hope that it will be useful,
12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 + * GNU General Public License for more details.
15 + *
16 + * You should have received a copy of the GNU General Public License
17 + * along with this program; if not, write to the Free Software
18 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + */
20 +
21   //---PACKAGE DECLARATION---
22 < package uk.org.iscream.client;
22 > package uk.org.iscream.cms.server.client;
23  
24   //---IMPORTS---
25 < import uk.org.iscream.componentmanager.*;
26 < import uk.org.iscream.core.*;
27 < import uk.org.iscream.util.*;
25 > import uk.org.iscream.cms.server.componentmanager.*;
26 > import uk.org.iscream.cms.server.core.*;
27 > import uk.org.iscream.cms.server.util.*;
28   import java.util.*;
29  
30   /**
31   * A manager for the Monitors.
32   *
33 + * This class starts by loading all the monitors as specificed in the configuration.
34 + * These monitors should implement the PluginMonitor interface.
35 + *
36 + * This class then takes the feed of data coming in over CORBA from
37 + * the ClientServant queue.  This data is then looked at to determine
38 + * type.  It then places it into either a data queue, a heartbeat queue or
39 + * an other queue, and all data in the the all queue.
40 + *
41 + * Monitors then read the data off the queue that they are interested in
42 + * and process the data accordingly.
43 + *
44   * @author  $Author$
45   * @version $Id$
46   */
47 < class MonitorManager extends Thread {
47 > public class MonitorManager extends Thread {
48  
49   //---FINAL ATTRIBUTES---
50  
# Line 28 | Line 59 | class MonitorManager extends Thread {
59       * Return a reference to the single class.
60       * Construct it if it does not already exist, otherwise just return the reference.
61       */
62 <    public static MonitorManager getInstance() {
62 >    public synchronized static MonitorManager getInstance() {
63          if (_instance == null){
64              _instance = new MonitorManager();
65          }
# Line 37 | Line 68 | class MonitorManager extends Thread {
68  
69   //---CONSTRUCTORS---
70  
71 +    /**
72 +     * Constructs a new MonitorManager.
73 +     * This initialises all the queues and loads
74 +     * all the Monitors that have been specified in the configuration
75 +     */
76      private MonitorManager() {
77          // set our name
78          setName("client.MonitorManager");
# Line 46 | Line 82 | class MonitorManager extends Thread {
82          _logger.write(toString(), Logger.SYSINIT, "Initialising");
83          _logger.write(toString(), Logger.SYSMSG, "Creating monitor pipeline for plugin monitors ...");
84          
85 +        // get the config proxy
86 +        ConfigurationProxy cp = ConfigurationProxy.getInstance();
87 +        
88 +        // get the configuration for our outgoing queue's
89 +        
90 +        // see if these Queue's need a size limit
91 +        try {
92 +            int queueSizeLimit = Integer.parseInt(cp.getProperty(_name, "Queue.SizeLimit"));
93 +            String queueRemoveAlgorithm = cp.getProperty(_name, "Queue.RemoveAlgorithm");
94 +            int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms);
95 +            if(algorithm != -1) {
96 +                _logger.write(toString(), Logger.DEBUG, "Starting 4 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm);
97 +                // we have valid values, so lets start it.
98 +                _dataQueue = new Queue(queueSizeLimit, algorithm);
99 +                _heartbeatQueue = new Queue(queueSizeLimit, algorithm);
100 +                _otherQueue = new Queue(queueSizeLimit, algorithm);
101 +                _allQueue = new Queue(queueSizeLimit, algorithm);
102 +            }
103 +            else {
104 +                _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
105 +                // just don't activate a limit
106 +                _dataQueue = new Queue();
107 +                _heartbeatQueue = new Queue();
108 +                _otherQueue = new Queue();
109 +                _allQueue = new Queue();
110 +            }
111 +        } catch (PropertyNotFoundException e) {
112 +            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
113 +            // just don't activate a limit
114 +            _dataQueue = new Queue();
115 +            _heartbeatQueue = new Queue();
116 +            _otherQueue = new Queue();
117 +            _allQueue = new Queue();
118 +        } catch (NumberFormatException e) {
119 +            _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
120 +            // just don't activate a limit
121 +            _dataQueue = new Queue();
122 +            _heartbeatQueue = new Queue();
123 +            _otherQueue = new Queue();
124 +            _allQueue = new Queue();
125 +        }
126 +        
127 +        // startup monitors on these queues
128 +        try {
129 +            // try to get the interval, if this fails, we won't start up the monitor
130 +            int queueMonitorInterval = Integer.parseInt(cp.getProperty(_name, "Queue.MonitorInterval"));
131 +            _dataQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " DataQueue");
132 +            _heartbeatQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " HeartbeatQueue");
133 +            _otherQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " OtherQueue");
134 +            _allQueue.startMonitor(queueMonitorInterval*1000, ClientMain._monitorQueue, _name + " AllQueue");
135 +        } catch (PropertyNotFoundException e) {
136 +            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
137 +        }
138 +        
139          // get the configuration for this plug-in setup
140 <        Configuration config = _refman.getCM().getConfiguration(_name);
141 <        String pluginsPackage = config.getProperty("Monitor.PluginsPackage");
142 <        String pluginsList = config.getProperty("Monitor.Plugins");
140 >        String pluginsPackage, pluginsList;
141 >        try {
142 >            pluginsPackage = cp.getProperty(_name, "Monitor.PluginsPackage");
143 >            pluginsList = cp.getProperty(_name, "Monitor.Plugins");
144 >        } catch(PropertyNotFoundException e) {
145 >            _logger.write(toString(), Logger.WARNING, "Unable to get required configuration, Monitor's will not be activated: "+e);
146 >            // setting these will ensure we don't build a pipeline
147 >            pluginsPackage = "";
148 >            pluginsList = "";
149 >        }
150          
151          StringTokenizer st = new StringTokenizer(pluginsList, ";");
152          
# Line 78 | Line 175 | class MonitorManager extends Thread {
175  
176   //---PUBLIC METHODS---
177      
178 +    /**
179 +     * Runs the MonitorManager.  This reads data from the
180 +     * inbound queue (from the ClientServant).  And passes
181 +     * it into the appropriate queue for processing by the monitor
182 +     * threads.
183 +     */
184      public void run() {
185          // construct now, and use multiple times
186          XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
# Line 104 | Line 207 | class MonitorManager extends Thread {
207                  // skip the rest of this loop iteration
208                  continue;
209              }
210 <                        
211 <            // for each monitor in the pipeline...
212 <            Iterator pluginMonitors = _monitorPipeline.iterator();
213 <            while (pluginMonitors.hasNext()){
111 <                PluginMonitor monitor = (PluginMonitor)pluginMonitors.next();
112 <                monitor.analysePacket(packet);
210 >            
211 >            // examine the packet and place it in the relevant outgoing queue
212 >            if(packet.getParam("packet.attributes.type").equals("data")) {
213 >                _dataQueue.add(packet);
214              }
215 +            else if(packet.getParam("packet.attributes.type").equals("heartbeat")) {
216 +                _heartbeatQueue.add(packet);
217 +            }
218 +            else {
219 +                _otherQueue.add(packet);
220 +            }
221 +            // always add to all queue
222 +            _allQueue.add(packet);
223          }
224      }
225  
# Line 118 | Line 227 | class MonitorManager extends Thread {
227       * Overrides the {@link java.lang.Object#toString() Object.toString()}
228       * method to provide clean logging (every class should have this).
229       *
230 <     * This uses the uk.org.iscream.util.FormatName class
230 >     * This uses the uk.org.iscream.cms.server.util.FormatName class
231       * to format the toString()
232       *
233       * @return the name of this class and its CVS revision
# Line 133 | Line 242 | class MonitorManager extends Thread {
242   //---PRIVATE METHODS---
243  
244   //---ACCESSOR/MUTATOR METHODS---
245 <
245 >    
246 >    /**
247 >     * Allows Monitors to obtain
248 >     * the queue of data packets
249 >     */
250 >    public Queue getDataQueue() {
251 >        return _dataQueue;
252 >    }
253 >    
254 >    /**
255 >     * Allows Monitors to obtain
256 >     * the queue of heatbeat packets
257 >     */
258 >    public Queue getHeartbeatQueue() {
259 >        return _heartbeatQueue;
260 >    }
261 >    
262 >    /**
263 >     * Allows Monitors to obtain
264 >     * the queue of all other packets
265 >     */
266 >    public Queue getOtherQueue() {
267 >        return _otherQueue;
268 >    }
269 >    
270 >    /**
271 >     * In case a Monitor wants more
272 >     * than one type of packet,
273 >     * this queue can be obtained.
274 >     */
275 >    public Queue getAllQueue() {
276 >        return _allQueue;
277 >    }
278 >    
279   //---ATTRIBUTES---
280  
281      /**
# Line 159 | Line 301 | class MonitorManager extends Thread {
301      private ReferenceManager _refman = ReferenceManager.getInstance();
302      
303      /**
304 <     * A reference to our Queue
304 >     * A reference to our incoming Queue
305       */
306      private Queue _queue;
307      
308      /**
309 <     * Our queue ID
309 >     * Our incoming queue ID
310       */
311      private int _qID;
312      
# Line 177 | Line 319 | class MonitorManager extends Thread {
319       * LinkedList for holding the PluginMonitor objects (the pipeline).
320       */
321      private LinkedList _monitorPipeline = new LinkedList();
322 <
322 >    
323 >    /**
324 >     * Outgoing data Queue
325 >     */
326 >    private Queue _dataQueue;
327 >    
328 >    /**
329 >     * Outgoing heartbeat Queue
330 >     */
331 >    private Queue _heartbeatQueue;
332 >    
333 >    /**
334 >     * Outgoing other Queue
335 >     */
336 >    private Queue _otherQueue;
337 >    
338 >    /**
339 >     * Outgoing ALL Queue
340 >     */
341 >    private Queue _allQueue;
342 >    
343   //---STATIC ATTRIBUTES---
344  
345      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines