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.23
Committed: Fri Sep 6 15:10:48 2002 UTC (21 years, 8 months ago) by tdb
Branch: MAIN
Changes since 1.22: +4 -4 lines
Log Message:
Fix for upgrade to Jacorb 1.4.1. It's our fault actually, we've not been
correctly using the names when binding to the Naming Service. This needs to
be fixed properly at some point, but for now I've changed changed the code
so it "means" the same as it did before the upgrade.

File Contents

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