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 |
+ |
_refman = ReferenceManager.getInstance(); |
43 |
+ |
_logger = ReferenceManager.getInstance().getLogger(); |
44 |
+ |
|
45 |
+ |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
46 |
+ |
|
47 |
+ |
// configuration variables we require |
48 |
+ |
int queueMonitorInterval = 0; |
49 |
+ |
|
50 |
+ |
Configuration config = _refman.getCM().getConfiguration("LocalClient"); |
51 |
+ |
if (config == null) { |
52 |
+ |
throw new ComponentStartException("Unable to obtain configuration for component"); |
53 |
|
} |
54 |
< |
catch (Exception e) { |
55 |
< |
System.out.println("ERROR : " + e); |
56 |
< |
e.printStackTrace(System.out); |
54 |
> |
else { |
55 |
> |
try { |
56 |
> |
// get the configuration properties we need |
57 |
> |
queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); |
58 |
> |
} catch (org.omg.CORBA.MARSHAL e) { |
59 |
> |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
60 |
> |
} |
61 |
|
} |
62 |
+ |
|
63 |
+ |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
64 |
+ |
|
65 |
+ |
// setup the servant |
66 |
+ |
_logger.write(toString(), Logger.SYSINIT, "starting servant"); |
67 |
+ |
|
68 |
+ |
Client client; |
69 |
+ |
|
70 |
+ |
try { |
71 |
+ |
ClientServant ref = new ClientServant(); |
72 |
+ |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
73 |
+ |
client = ClientHelper.narrow(objRef); |
74 |
+ |
|
75 |
+ |
// this name maybe shouldn't be static |
76 |
+ |
objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener"); |
77 |
+ |
CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef); |
78 |
+ |
|
79 |
+ |
_logger.write(toString(), Logger.SYSINIT, "connecting"); |
80 |
+ |
CorbaControlHandler handler = listener.connect(client); |
81 |
+ |
handler.startData(); |
82 |
+ |
} |
83 |
+ |
catch(Exception e) { |
84 |
+ |
// not sure what to do here |
85 |
+ |
// so we just log the error |
86 |
+ |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
_logger.write(toString(), Logger.SYSINIT, "started"); |
90 |
+ |
|
91 |
|
} |
92 |
+ |
|
93 |
+ |
/** |
94 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
95 |
+ |
* method to provide clean logging (every class should have this). |
96 |
+ |
* |
97 |
+ |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
98 |
+ |
* to format the toString() |
99 |
+ |
* |
100 |
+ |
* @return the name of this class and its CVS revision |
101 |
+ |
*/ |
102 |
+ |
public String toString() { |
103 |
+ |
return FormatName.getName( |
104 |
+ |
NAME, |
105 |
+ |
getClass().getName(), |
106 |
+ |
REVISION); |
107 |
+ |
} |
108 |
+ |
|
109 |
+ |
//---PRIVATE METHODS--- |
110 |
+ |
|
111 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
112 |
+ |
|
113 |
+ |
//---ATTRIBUTES--- |
114 |
+ |
|
115 |
+ |
/** |
116 |
+ |
* This holds a reference to the |
117 |
+ |
* system logger that is being used. |
118 |
+ |
*/ |
119 |
+ |
private Logger _logger; |
120 |
+ |
|
121 |
+ |
/** |
122 |
+ |
* A reference to the reference manager in use |
123 |
+ |
*/ |
124 |
+ |
private ReferenceManager _refman; |
125 |
+ |
|
126 |
+ |
//---STATIC ATTRIBUTES--- |
127 |
|
|
128 |
|
} |