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/ClientMain.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/ClientMain.java (file contents):
Revision 1.9 by ajm, Fri Mar 2 00:15:59 2001 UTC vs.
Revision 1.18 by tdb, Thu Mar 22 18:18:14 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.clientinterface.*;
6 < import uk.ac.ukc.iscream.componentmanager.*;
7 < import uk.ac.ukc.iscream.core.*;
8 < import uk.ac.ukc.iscream.util.*;
5 > import uk.org.iscream.clientinterface.*;
6 > import uk.org.iscream.componentmanager.*;
7 > import uk.org.iscream.core.*;
8 > import uk.org.iscream.util.*;
9  
10   /**
11   * A startup component for the Local Clients.
# Line 39 | Line 39 | public class ClientMain implements Component {
39       */
40      public void start() throws ComponentStartException {
41          // get references to key objects
42 <        _refman = ReferenceManager.getInstance();
43 <        _logger = ReferenceManager.getInstance().getLogger();
42 >        _logger = _refman.getLogger();
43  
44          _logger.write(toString(), Logger.SYSINIT, "coming up");
46            
47        // configuration variables we require
48        int queueMonitorInterval = 0;
45          
46 <        Configuration config = _refman.getCM().getConfiguration("LocalClient");
47 <        if (config == null) {
48 <            throw new ComponentStartException("Unable to obtain configuration for component");
49 <        }
50 <        else {
51 <            try {
52 <                // get the configuration properties we need
53 <                queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval"));
54 <            } catch (org.omg.CORBA.MARSHAL e) {
55 <                throw new ComponentStartException("Unable to obtain requried configuration property for component");
46 >        // get a reference to the configuration proxy
47 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
48 >        
49 >        // see if these Queue's need a size limit
50 >        try {
51 >            int queueSizeLimit = Integer.parseInt(cp.getProperty(NAME, "Queue.SizeLimit"));
52 >            String queueRemoveAlgorithm = cp.getProperty(NAME, "Queue.RemoveAlgorithm");
53 >            int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms);
54 >            if(algorithm != -1) {
55 >                _logger.write(toString(), Logger.DEBUG, "Starting 2 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm);
56 >                // we have valid values, so lets start it.
57 >                _alerterQueue = new Queue(queueSizeLimit, algorithm);
58 >                _monitorQueue = new Queue(queueSizeLimit, algorithm);
59              }
60 +            else {
61 +                _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
62 +                // just don't activate a limit
63 +                _alerterQueue = new Queue();
64 +                _monitorQueue = new Queue();
65 +            }
66 +        } catch (PropertyNotFoundException e) {
67 +            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
68 +            // just don't activate a limit
69 +            _alerterQueue = new Queue();
70 +            _monitorQueue = new Queue();
71 +        } catch (NumberFormatException e) {
72 +            _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
73 +            // just don't activate a limit
74 +            _alerterQueue = new Queue();
75 +            _monitorQueue = new Queue();
76          }
62              
63        _logger.write(toString(), Logger.SYSINIT, "configured");
77          
78 <        // setup the queues, this must be done before both managers are setup
79 <        String queueName;
80 <        // setup a Queue for the servant -> monitor manager
81 <        _monitorQueue = new Queue();
82 <        // startup a monitor on this queue
83 <        queueName = NAME + " MonitorManager";
84 <        _monitorQueue.startMonitor(queueMonitorInterval*1000, queueName);
78 >        // startup monitors on these queues
79 >        try {
80 >            // try to get the interval, if this fails, we won't start up the monitor
81 >            int queueMonitorInterval = Integer.parseInt(cp.getProperty(NAME, "Queue.MonitorInterval"));
82 >            _alerterQueue.startMonitor(queueMonitorInterval*1000, _monitorQueue, NAME + " Alerter");
83 >            _monitorQueue.startMonitor(queueMonitorInterval*1000, _monitorQueue, NAME + " Monitor");
84 >        } catch (PropertyNotFoundException e) {
85 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
86 >        }        
87          
73         // setup a Queue for the monitors -> alert manager
74        _alerterQueue = new Queue();
75        // startup a monitor on this queue
76       queueName = NAME + " MonitorManager";
77        _alerterQueue.startMonitor(queueMonitorInterval*1000, queueName);
78        
79        
80        
88          // setup the servant and connect
89          _logger.write(toString(), Logger.SYSINIT, "starting servant and connecting");          
90          try {
# Line 104 | Line 111 | public class ClientMain implements Component {
111          monMan.start();
112          
113          // setup the AlerterManager
107      
108        
114          AlerterManager alertMan = AlerterManager.getInstance();
115          alertMan.start();
116        
117          _logger.write(toString(), Logger.SYSINIT, "started");
118          
119      }
120 <
120 >    
121      /**
122 +     * Does a dependency check. Used mainly at startup to
123 +     * see if the required dependencies (components) are up
124 +     * and running.
125 +     *
126 +     * @return a boolean value, true if the depdencies are satisfied
127 +     */
128 +    public boolean depCheck() {
129 +        try {
130 +            org.omg.CORBA.Object obj;
131 +            // first check the ConfigurationManager is alive
132 +            obj = _refman.getCORBARef("iscream.ConfigurationManager");
133 +            // then get some info on the CLI
134 +            ConfigurationProxy cp = ConfigurationProxy.getInstance();
135 +            String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName");
136 +            // finally check the CLI is alive
137 +            obj = _refman.getCORBARef("iscream.ClientInterface." + cli);
138 +        } catch(ComponentCORBAException e) {
139 +            System.err.println(toString() + ": Dependency Failure: "+e);
140 +            return false;
141 +        } catch(PropertyNotFoundException e) {
142 +            System.err.println(toString() + ": Unable to obtain configuration: "+e);
143 +            return false;
144 +        }
145 +        // dependency check suceeded
146 +        return true;
147 +    }
148 +    
149 +    /**
150       * Overrides the {@link java.lang.Object#toString() Object.toString()}
151       * method to provide clean logging (every class should have this).
152       *
153 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
153 >     * This uses the uk.org.iscream.util.FormatName class
154       * to format the toString()
155       *
156       * @return the name of this class and its CVS revision
# Line 144 | Line 177 | public class ClientMain implements Component {
177      /**
178       * A reference to the reference manager in use
179       */
180 <    private ReferenceManager _refman;
180 >    private ReferenceManager _refman = ReferenceManager.getInstance();
181  
182   //---STATIC ATTRIBUTES---
183  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines