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
Revision: 1.19
Committed: Fri Mar 23 02:30:44 2001 UTC (23 years, 1 month ago) by ajm
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Changes since 1.18: +15 -4 lines
Log Message:
Javadoc'd the whole bally lot.

File Contents

# User Rev Content
1 tdb 1.5 //---PACKAGE DECLARATION---
2 tdb 1.15 package uk.org.iscream.client;
3 tdb 1.1
4 tdb 1.5 //---IMPORTS---
5 tdb 1.15 import uk.org.iscream.clientinterface.*;
6     import uk.org.iscream.componentmanager.*;
7     import uk.org.iscream.core.*;
8     import uk.org.iscream.util.*;
9 tdb 1.5
10     /**
11     * A startup component for the Local Clients.
12 ajm 1.19 * This class starts the CORBA client used for alerting
13     * purposes. It reads data using the ClientServant from CORBA
14     * calls by the i-scream client interface. This data is then
15     * used by the MonitorManager to pass to Monitors. Monitors then
16     * analyse the data and raise alerts if needed, these are passed to
17     * the Alerters, which send out alerts. They are looked after by
18     * the AlerterManager.
19 tdb 1.5 *
20 tdb 1.13 * @author $Author: tdb1 $
21 ajm 1.19 * @version $Id: ClientMain.java,v 1.18 2001/03/22 18:18:14 tdb1 Exp $
22 tdb 1.5 */
23     public class ClientMain implements Component {
24    
25     //---FINAL ATTRIBUTES---
26    
27     /**
28     * The current CVS revision of this class
29     */
30 ajm 1.19 public static final String REVISION = "$Revision: 1.18 $";
31 tdb 1.5
32     /**
33     * The friendly name for this component, used by
34     * all related classes.
35     */
36     public static final String NAME = "LocalClient";
37    
38     //---STATIC METHODS---
39    
40     //---CONSTRUCTORS---
41    
42     //---PUBLIC METHODS---
43    
44     /**
45 ajm 1.19 * This starts the Local Client component.
46     * This starts the ClientServant, the MonitorManager and
47     * the AlerterManager, aswell as initialising any queues
48     * and obtaining any initial configuration.
49     *
50     * @throws ComponentStartException if the component fails to start
51 tdb 1.5 */
52     public void start() throws ComponentStartException {
53 tdb 1.6 // get references to key objects
54 tdb 1.13 _logger = _refman.getLogger();
55 tdb 1.5
56     _logger.write(toString(), Logger.SYSINIT, "coming up");
57    
58 tdb 1.17 // get a reference to the configuration proxy
59     ConfigurationProxy cp = ConfigurationProxy.getInstance();
60    
61     // see if these Queue's need a size limit
62     try {
63     int queueSizeLimit = Integer.parseInt(cp.getProperty(NAME, "Queue.SizeLimit"));
64     String queueRemoveAlgorithm = cp.getProperty(NAME, "Queue.RemoveAlgorithm");
65     int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms);
66     if(algorithm != -1) {
67     _logger.write(toString(), Logger.DEBUG, "Starting 2 Queues with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm);
68     // we have valid values, so lets start it.
69     _alerterQueue = new Queue(queueSizeLimit, algorithm);
70     _monitorQueue = new Queue(queueSizeLimit, algorithm);
71     }
72     else {
73     _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
74     // just don't activate a limit
75     _alerterQueue = new Queue();
76     _monitorQueue = new Queue();
77     }
78     } catch (PropertyNotFoundException e) {
79     _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
80     // just don't activate a limit
81     _alerterQueue = new Queue();
82     _monitorQueue = new Queue();
83     } catch (NumberFormatException e) {
84     _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
85     // just don't activate a limit
86     _alerterQueue = new Queue();
87     _monitorQueue = new Queue();
88     }
89    
90     // startup monitors on these queues
91     try {
92     // try to get the interval, if this fails, we won't start up the monitor
93     int queueMonitorInterval = Integer.parseInt(cp.getProperty(NAME, "Queue.MonitorInterval"));
94 tdb 1.18 _alerterQueue.startMonitor(queueMonitorInterval*1000, _monitorQueue, NAME + " Alerter");
95     _monitorQueue.startMonitor(queueMonitorInterval*1000, _monitorQueue, NAME + " Monitor");
96 tdb 1.17 } catch (PropertyNotFoundException e) {
97     _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
98     }
99 tdb 1.5
100 tdb 1.7 // setup the servant and connect
101     _logger.write(toString(), Logger.SYSINIT, "starting servant and connecting");
102 tdb 1.1 try {
103 ajm 1.9 ClientServant ref = new ClientServant(_monitorQueue);
104 tdb 1.5 org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
105 tdb 1.7 Client client = ClientHelper.narrow(objRef);
106 tdb 1.5
107     // this name maybe shouldn't be static
108     objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener");
109     CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef);
110    
111     _logger.write(toString(), Logger.SYSINIT, "connecting");
112 tdb 1.8 CorbaControlHandler handler = listener.connect(client, NAME);
113 tdb 1.5 handler.startData();
114 tdb 1.1 }
115 tdb 1.5 catch(Exception e) {
116     // not sure what to do here
117     // so we just log the error
118     _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
119 tdb 1.1 }
120 tdb 1.7
121     // setup the MonitorManager
122 ajm 1.9 MonitorManager monMan = MonitorManager.getInstance();
123     monMan.start();
124    
125     // setup the AlerterManager
126     AlerterManager alertMan = AlerterManager.getInstance();
127     alertMan.start();
128    
129 tdb 1.5 _logger.write(toString(), Logger.SYSINIT, "started");
130     }
131 tdb 1.12
132     /**
133     * Does a dependency check. Used mainly at startup to
134     * see if the required dependencies (components) are up
135     * and running.
136     *
137     * @return a boolean value, true if the depdencies are satisfied
138     */
139     public boolean depCheck() {
140     try {
141     org.omg.CORBA.Object obj;
142     // first check the ConfigurationManager is alive
143     obj = _refman.getCORBARef("iscream.ConfigurationManager");
144     // then get some info on the CLI
145     ConfigurationProxy cp = ConfigurationProxy.getInstance();
146     String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName");
147     // finally check the CLI is alive
148     obj = _refman.getCORBARef("iscream.ClientInterface." + cli);
149     } catch(ComponentCORBAException e) {
150 tdb 1.14 System.err.println(toString() + ": Dependency Failure: "+e);
151 tdb 1.12 return false;
152     } catch(PropertyNotFoundException e) {
153 tdb 1.14 System.err.println(toString() + ": Unable to obtain configuration: "+e);
154 tdb 1.12 return false;
155     }
156     // dependency check suceeded
157     return true;
158     }
159    
160 tdb 1.5 /**
161     * Overrides the {@link java.lang.Object#toString() Object.toString()}
162     * method to provide clean logging (every class should have this).
163     *
164 tdb 1.15 * This uses the uk.org.iscream.util.FormatName class
165 tdb 1.5 * to format the toString()
166     *
167     * @return the name of this class and its CVS revision
168     */
169     public String toString() {
170     return FormatName.getName(
171     NAME,
172     getClass().getName(),
173     REVISION);
174 tdb 1.1 }
175 tdb 1.5
176     //---PRIVATE METHODS---
177    
178     //---ACCESSOR/MUTATOR METHODS---
179    
180     //---ATTRIBUTES---
181    
182     /**
183     * This holds a reference to the
184     * system logger that is being used.
185     */
186 tdb 1.6 private Logger _logger;
187 tdb 1.5
188     /**
189     * A reference to the reference manager in use
190     */
191 tdb 1.13 private ReferenceManager _refman = ReferenceManager.getInstance();
192 tdb 1.5
193     //---STATIC ATTRIBUTES---
194 ajm 1.9
195     /**
196     * A queue for the alerter manager
197     */
198     public static Queue _alerterQueue;
199    
200     /**
201     * A queue for the monitor manager
202     */
203     public static Queue _monitorQueue;
204 tdb 1.1
205     }