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.17
Committed: Thu Mar 22 17:31:43 2001 UTC (23 years, 1 month ago) by tdb
Branch: MAIN
Changes since 1.16: +43 -7 lines
Log Message:
Radically changed the way data is passed around. Monitor's are now required to
get data from the MonitorManager queue's, rather than being passed it. This
allows them to run in parallel, rather than the serial setup we had before.

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     *
13 tdb 1.13 * @author $Author: tdb1 $
14 tdb 1.17 * @version $Id: ClientMain.java,v 1.16 2001/03/15 22:12:22 tdb1 Exp $
15 tdb 1.5 */
16     public class ClientMain implements Component {
17    
18     //---FINAL ATTRIBUTES---
19    
20     /**
21     * The current CVS revision of this class
22     */
23 tdb 1.17 public static final String REVISION = "$Revision: 1.16 $";
24 tdb 1.5
25     /**
26     * The friendly name for this component, used by
27     * all related classes.
28     */
29     public static final String NAME = "LocalClient";
30    
31     //---STATIC METHODS---
32    
33     //---CONSTRUCTORS---
34    
35     //---PUBLIC METHODS---
36    
37     /**
38     * This starts the Local Client component
39     */
40     public void start() throws ComponentStartException {
41 tdb 1.6 // get references to key objects
42 tdb 1.13 _logger = _refman.getLogger();
43 tdb 1.5
44     _logger.write(toString(), Logger.SYSINIT, "coming up");
45    
46 tdb 1.17 // 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     }
77    
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 + " DataQueue");
83     _monitorQueue.startMonitor(queueMonitorInterval*1000, _monitorQueue, NAME + " HeartbeatQueue");
84     } catch (PropertyNotFoundException e) {
85     _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
86     }
87 tdb 1.5
88 tdb 1.7 // setup the servant and connect
89     _logger.write(toString(), Logger.SYSINIT, "starting servant and connecting");
90 tdb 1.1 try {
91 ajm 1.9 ClientServant ref = new ClientServant(_monitorQueue);
92 tdb 1.5 org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
93 tdb 1.7 Client client = ClientHelper.narrow(objRef);
94 tdb 1.5
95     // this name maybe shouldn't be static
96     objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener");
97     CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef);
98    
99     _logger.write(toString(), Logger.SYSINIT, "connecting");
100 tdb 1.8 CorbaControlHandler handler = listener.connect(client, NAME);
101 tdb 1.5 handler.startData();
102 tdb 1.1 }
103 tdb 1.5 catch(Exception e) {
104     // not sure what to do here
105     // so we just log the error
106     _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
107 tdb 1.1 }
108 tdb 1.7
109     // setup the MonitorManager
110 ajm 1.9 MonitorManager monMan = MonitorManager.getInstance();
111     monMan.start();
112    
113     // setup the AlerterManager
114     AlerterManager alertMan = AlerterManager.getInstance();
115     alertMan.start();
116    
117 tdb 1.5 _logger.write(toString(), Logger.SYSINIT, "started");
118    
119     }
120 tdb 1.12
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 tdb 1.14 System.err.println(toString() + ": Dependency Failure: "+e);
140 tdb 1.12 return false;
141     } catch(PropertyNotFoundException e) {
142 tdb 1.14 System.err.println(toString() + ": Unable to obtain configuration: "+e);
143 tdb 1.12 return false;
144     }
145     // dependency check suceeded
146     return true;
147     }
148    
149 tdb 1.5 /**
150     * Overrides the {@link java.lang.Object#toString() Object.toString()}
151     * method to provide clean logging (every class should have this).
152     *
153 tdb 1.15 * This uses the uk.org.iscream.util.FormatName class
154 tdb 1.5 * to format the toString()
155     *
156     * @return the name of this class and its CVS revision
157     */
158     public String toString() {
159     return FormatName.getName(
160     NAME,
161     getClass().getName(),
162     REVISION);
163 tdb 1.1 }
164 tdb 1.5
165     //---PRIVATE METHODS---
166    
167     //---ACCESSOR/MUTATOR METHODS---
168    
169     //---ATTRIBUTES---
170    
171     /**
172     * This holds a reference to the
173     * system logger that is being used.
174     */
175 tdb 1.6 private Logger _logger;
176 tdb 1.5
177     /**
178     * A reference to the reference manager in use
179     */
180 tdb 1.13 private ReferenceManager _refman = ReferenceManager.getInstance();
181 tdb 1.5
182     //---STATIC ATTRIBUTES---
183 ajm 1.9
184     /**
185     * A queue for the alerter manager
186     */
187     public static Queue _alerterQueue;
188    
189     /**
190     * A queue for the monitor manager
191     */
192     public static Queue _monitorQueue;
193 tdb 1.1
194     }