1 |
+ |
//---PACKAGE DECLARATION--- |
2 |
|
package uk.ac.ukc.iscream.client; |
3 |
|
|
4 |
< |
import uk.ac.ukc.iscream.client.*; |
4 |
> |
//---IMPORTS--- |
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.*; |
7 |
> |
import uk.ac.ukc.iscream.core.*; |
8 |
> |
import uk.ac.ukc.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 |
> |
* |
13 |
> |
* @author $Author$ |
14 |
> |
* @version $Id$ |
15 |
> |
*/ |
16 |
> |
public class ClientMain implements Component { |
17 |
|
|
18 |
< |
ClientServant corbaServant = new ClientServant(); |
19 |
< |
org.omg.CORBA.Object o = _refman.getRootPOA().servant_to_reference(corbaServant); |
20 |
< |
Client client = ClientHelper.narrow(o); |
18 |
> |
//---FINAL ATTRIBUTES--- |
19 |
|
|
20 |
< |
o = _refman.getCORBARef("iscream.ClientInterface.CorbaListener"); |
21 |
< |
CorbaClientListener lRef = CorbaClientListenerHelper.narrow(o); |
20 |
> |
/** |
21 |
> |
* The current CVS revision of this class |
22 |
> |
*/ |
23 |
> |
public static final String REVISION = "$Revision$"; |
24 |
> |
|
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 |
< |
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 -- "); |
33 |
> |
//---CONSTRUCTORS--- |
34 |
|
|
35 |
+ |
//---PUBLIC METHODS--- |
36 |
+ |
|
37 |
+ |
/** |
38 |
+ |
* This starts the Local Client component |
39 |
+ |
*/ |
40 |
+ |
public void start() throws ComponentStartException { |
41 |
+ |
// get references to key objects |
42 |
+ |
_logger = _refman.getLogger(); |
43 |
+ |
|
44 |
+ |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
45 |
+ |
|
46 |
+ |
// configuration variables we require |
47 |
+ |
int queueMonitorInterval = 0; |
48 |
+ |
|
49 |
+ |
Configuration config = _refman.getCM().getConfiguration("LocalClient"); |
50 |
+ |
if (config == null) { |
51 |
+ |
throw new ComponentStartException("Unable to obtain configuration for component"); |
52 |
|
} |
53 |
< |
catch (Exception e) { |
54 |
< |
System.out.println("ERROR : " + e); |
55 |
< |
e.printStackTrace(System.out); |
53 |
> |
else { |
54 |
> |
try { |
55 |
> |
// get the configuration properties we need |
56 |
> |
queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); |
57 |
> |
} catch (org.omg.CORBA.MARSHAL e) { |
58 |
> |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
59 |
> |
} |
60 |
|
} |
61 |
+ |
|
62 |
+ |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
63 |
+ |
|
64 |
+ |
// setup the queues, this must be done before both managers are setup |
65 |
+ |
String queueName; |
66 |
+ |
// setup a Queue for the servant -> monitor manager |
67 |
+ |
_monitorQueue = new Queue(); |
68 |
+ |
|
69 |
+ |
// setup a Queue for the monitors -> alert manager |
70 |
+ |
_alerterQueue = new Queue(); |
71 |
+ |
|
72 |
+ |
|
73 |
+ |
|
74 |
+ |
// setup the servant and connect |
75 |
+ |
_logger.write(toString(), Logger.SYSINIT, "starting servant and connecting"); |
76 |
+ |
try { |
77 |
+ |
ClientServant ref = new ClientServant(_monitorQueue); |
78 |
+ |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
79 |
+ |
Client client = ClientHelper.narrow(objRef); |
80 |
+ |
|
81 |
+ |
// this name maybe shouldn't be static |
82 |
+ |
objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener"); |
83 |
+ |
CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef); |
84 |
+ |
|
85 |
+ |
_logger.write(toString(), Logger.SYSINIT, "connecting"); |
86 |
+ |
CorbaControlHandler handler = listener.connect(client, NAME); |
87 |
+ |
handler.startData(); |
88 |
+ |
} |
89 |
+ |
catch(Exception e) { |
90 |
+ |
// not sure what to do here |
91 |
+ |
// so we just log the error |
92 |
+ |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); |
93 |
+ |
} |
94 |
+ |
|
95 |
+ |
// setup the MonitorManager |
96 |
+ |
MonitorManager monMan = MonitorManager.getInstance(); |
97 |
+ |
monMan.start(); |
98 |
+ |
|
99 |
+ |
// setup the AlerterManager |
100 |
+ |
AlerterManager alertMan = AlerterManager.getInstance(); |
101 |
+ |
alertMan.start(); |
102 |
+ |
|
103 |
+ |
_logger.write(toString(), Logger.SYSINIT, "started"); |
104 |
+ |
|
105 |
|
} |
106 |
+ |
|
107 |
+ |
/** |
108 |
+ |
* Does a dependency check. Used mainly at startup to |
109 |
+ |
* see if the required dependencies (components) are up |
110 |
+ |
* and running. |
111 |
+ |
* |
112 |
+ |
* @return a boolean value, true if the depdencies are satisfied |
113 |
+ |
*/ |
114 |
+ |
public boolean depCheck() { |
115 |
+ |
try { |
116 |
+ |
org.omg.CORBA.Object obj; |
117 |
+ |
// first check the ConfigurationManager is alive |
118 |
+ |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
119 |
+ |
// then get some info on the CLI |
120 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
121 |
+ |
String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName"); |
122 |
+ |
// finally check the CLI is alive |
123 |
+ |
obj = _refman.getCORBARef("iscream.ClientInterface." + cli); |
124 |
+ |
} catch(ComponentCORBAException e) { |
125 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
126 |
+ |
return false; |
127 |
+ |
} catch(PropertyNotFoundException e) { |
128 |
+ |
System.err.println(toString() + ": Unable to obtain configuration: "+e); |
129 |
+ |
return false; |
130 |
+ |
} |
131 |
+ |
// dependency check suceeded |
132 |
+ |
return true; |
133 |
+ |
} |
134 |
+ |
|
135 |
+ |
/** |
136 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
137 |
+ |
* method to provide clean logging (every class should have this). |
138 |
+ |
* |
139 |
+ |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
140 |
+ |
* to format the toString() |
141 |
+ |
* |
142 |
+ |
* @return the name of this class and its CVS revision |
143 |
+ |
*/ |
144 |
+ |
public String toString() { |
145 |
+ |
return FormatName.getName( |
146 |
+ |
NAME, |
147 |
+ |
getClass().getName(), |
148 |
+ |
REVISION); |
149 |
+ |
} |
150 |
+ |
|
151 |
+ |
//---PRIVATE METHODS--- |
152 |
+ |
|
153 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
154 |
+ |
|
155 |
+ |
//---ATTRIBUTES--- |
156 |
+ |
|
157 |
+ |
/** |
158 |
+ |
* This holds a reference to the |
159 |
+ |
* system logger that is being used. |
160 |
+ |
*/ |
161 |
+ |
private Logger _logger; |
162 |
+ |
|
163 |
+ |
/** |
164 |
+ |
* A reference to the reference manager in use |
165 |
+ |
*/ |
166 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
167 |
+ |
|
168 |
+ |
//---STATIC ATTRIBUTES--- |
169 |
+ |
|
170 |
+ |
/** |
171 |
+ |
* A queue for the alerter manager |
172 |
+ |
*/ |
173 |
+ |
public static Queue _alerterQueue; |
174 |
+ |
|
175 |
+ |
/** |
176 |
+ |
* A queue for the monitor manager |
177 |
+ |
*/ |
178 |
+ |
public static Queue _monitorQueue; |
179 |
|
|
180 |
|
} |