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.3 by tdb, Mon Feb 5 02:58:54 2001 UTC vs.
Revision 1.19 by ajm, Fri Mar 23 02:30:44 2001 UTC

# Line 1 | Line 1
1 < package uk.ac.ukc.iscream.client;
1 > //---PACKAGE DECLARATION---
2 > package uk.org.iscream.client;
3  
4 < import uk.ac.ukc.iscream.client.*;
5 < import uk.ac.ukc.iscream.clientinterface.*;
6 < import uk.ac.ukc.iscream.componentmanager.*;
7 < import org.omg.CosNaming.*;
8 < import org.omg.CORBA.*;
8 < import org.omg.PortableServer.*;
4 > //---IMPORTS---
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 < public class ClientMain {
11 <    public static void main(String args[]) {
12 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
13 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
14 <        try {
15 <            ReferenceManager _refman = ReferenceManager.getInstance();
16 <            _refman.activatePOA();
10 > /**
11 > * A startup component for the Local Clients.
12 > * 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 > *
20 > * @author  $Author$
21 > * @version $Id$
22 > */
23 > public class ClientMain implements Component {
24  
25 <            ClientServant corbaServant = new ClientServant();
19 <            org.omg.CORBA.Object o = _refman.getRootPOA().servant_to_reference(corbaServant);
20 <            Client client = ClientHelper.narrow(o);
25 > //---FINAL ATTRIBUTES---
26  
27 <            o = _refman.getCORBARef("iscream.ClientInterface.CorbaListener");
28 <            CorbaClientListener lRef = CorbaClientListenerHelper.narrow(o);
27 >    /**
28 >     * The current CVS revision of this class
29 >     */
30 >    public static final String REVISION = "$Revision$";
31 >    
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 <            boolean result;
26 <            System.out.println(" -- connecting -- ");
27 <            CorbaControlHandler handler = lRef.connect(client);
28 <            System.out.println(" -- starting data -- ");
29 <            result = handler.startData();
30 <            System.out.println(" -- sleep for 30s -- ");
31 <            Thread.sleep(30000);
32 <            System.out.println(" -- stopping data -- ");
33 <            result = handler.stopData();
34 <            Thread.sleep(2000);
35 <            System.out.println(" -- completed -- ");
40 > //---CONSTRUCTORS---
41  
42 + //---PUBLIC METHODS---
43 +
44 +    /**
45 +     * 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 +     */
52 +    public void start() throws ComponentStartException {
53 +        // get references to key objects
54 +        _logger = _refman.getLogger();
55 +
56 +        _logger.write(toString(), Logger.SYSINIT, "coming up");
57 +        
58 +        // 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 <        catch (Exception e) {
90 <            System.out.println("ERROR : " + e);
91 <            e.printStackTrace(System.out);
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 >            _alerterQueue.startMonitor(queueMonitorInterval*1000, _monitorQueue, NAME + " Alerter");
95 >            _monitorQueue.startMonitor(queueMonitorInterval*1000, _monitorQueue, NAME + " Monitor");
96 >        } catch (PropertyNotFoundException e) {
97 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
98 >        }        
99 >        
100 >        // setup the servant and connect
101 >        _logger.write(toString(), Logger.SYSINIT, "starting servant and connecting");          
102 >        try {
103 >            ClientServant ref = new ClientServant(_monitorQueue);
104 >            org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
105 >            Client client = ClientHelper.narrow(objRef);
106 >            
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 >            CorbaControlHandler handler = listener.connect(client, NAME);
113 >            handler.startData();
114          }
115 +        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 +        }
120 +        
121 +        // setup the MonitorManager
122 +        MonitorManager monMan = MonitorManager.getInstance();
123 +        monMan.start();
124 +        
125 +        // setup the AlerterManager
126 +        AlerterManager alertMan = AlerterManager.getInstance();
127 +        alertMan.start();
128 +      
129 +        _logger.write(toString(), Logger.SYSINIT, "started");
130      }
131 +    
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 +            System.err.println(toString() + ": Dependency Failure: "+e);
151 +            return false;
152 +        } catch(PropertyNotFoundException e) {
153 +            System.err.println(toString() + ": Unable to obtain configuration: "+e);
154 +            return false;
155 +        }
156 +        // dependency check suceeded
157 +        return true;
158 +    }
159 +    
160 +    /**
161 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
162 +     * method to provide clean logging (every class should have this).
163 +     *
164 +     * This uses the uk.org.iscream.util.FormatName class
165 +     * 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 +    }
175 +
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 +    private Logger _logger;
187 +
188 +    /**
189 +     * A reference to the reference manager in use
190 +     */
191 +    private ReferenceManager _refman = ReferenceManager.getInstance();
192 +
193 + //---STATIC ATTRIBUTES---
194 +
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  
205   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines