1 |
tdb |
1.5 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.1 |
package uk.ac.ukc.iscream.client; |
3 |
|
|
|
4 |
tdb |
1.5 |
//---IMPORTS--- |
5 |
tdb |
1.1 |
import uk.ac.ukc.iscream.clientinterface.*; |
6 |
|
|
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
tdb |
1.5 |
import uk.ac.ukc.iscream.core.*; |
8 |
|
|
import uk.ac.ukc.iscream.util.*; |
9 |
|
|
|
10 |
|
|
/** |
11 |
|
|
* A startup component for the Local Clients. |
12 |
|
|
* |
13 |
tdb |
1.6 |
* @author $Author: tdb1 $ |
14 |
tdb |
1.8 |
* @version $Id: ClientMain.java,v 1.7 2001/02/27 01:01:33 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.8 |
public static final String REVISION = "$Revision: 1.7 $"; |
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 |
|
|
_refman = ReferenceManager.getInstance(); |
43 |
|
|
_logger = ReferenceManager.getInstance().getLogger(); |
44 |
tdb |
1.5 |
|
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 |
|
|
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 |
tdb |
1.7 |
// setup a Queue for the servant -> monitor manager |
66 |
|
|
Queue queue = new Queue(); |
67 |
|
|
// startup a monitor on this queue |
68 |
|
|
String queueName = NAME + " ServantToMonMan"; |
69 |
|
|
queue.startMonitor(queueMonitorInterval*1000, queueName); |
70 |
tdb |
1.5 |
|
71 |
tdb |
1.7 |
// setup the servant and connect |
72 |
|
|
_logger.write(toString(), Logger.SYSINIT, "starting servant and connecting"); |
73 |
tdb |
1.1 |
try { |
74 |
tdb |
1.7 |
ClientServant ref = new ClientServant(queue); |
75 |
tdb |
1.5 |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
76 |
tdb |
1.7 |
Client client = ClientHelper.narrow(objRef); |
77 |
tdb |
1.5 |
|
78 |
|
|
// this name maybe shouldn't be static |
79 |
|
|
objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener"); |
80 |
|
|
CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef); |
81 |
|
|
|
82 |
|
|
_logger.write(toString(), Logger.SYSINIT, "connecting"); |
83 |
tdb |
1.8 |
CorbaControlHandler handler = listener.connect(client, NAME); |
84 |
tdb |
1.5 |
handler.startData(); |
85 |
tdb |
1.1 |
} |
86 |
tdb |
1.5 |
catch(Exception e) { |
87 |
|
|
// not sure what to do here |
88 |
|
|
// so we just log the error |
89 |
|
|
_logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); |
90 |
tdb |
1.1 |
} |
91 |
tdb |
1.7 |
|
92 |
|
|
// setup the MonitorManager |
93 |
|
|
MonitorManager monMan = new MonitorManager(queue); |
94 |
tdb |
1.5 |
|
95 |
|
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
96 |
|
|
|
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/** |
100 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
101 |
|
|
* method to provide clean logging (every class should have this). |
102 |
|
|
* |
103 |
|
|
* This uses the uk.ac.ukc.iscream.util.FormatName class |
104 |
|
|
* to format the toString() |
105 |
|
|
* |
106 |
|
|
* @return the name of this class and its CVS revision |
107 |
|
|
*/ |
108 |
|
|
public String toString() { |
109 |
|
|
return FormatName.getName( |
110 |
|
|
NAME, |
111 |
|
|
getClass().getName(), |
112 |
|
|
REVISION); |
113 |
tdb |
1.1 |
} |
114 |
tdb |
1.5 |
|
115 |
|
|
//---PRIVATE METHODS--- |
116 |
|
|
|
117 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
118 |
|
|
|
119 |
|
|
//---ATTRIBUTES--- |
120 |
|
|
|
121 |
|
|
/** |
122 |
|
|
* This holds a reference to the |
123 |
|
|
* system logger that is being used. |
124 |
|
|
*/ |
125 |
tdb |
1.6 |
private Logger _logger; |
126 |
tdb |
1.5 |
|
127 |
|
|
/** |
128 |
|
|
* A reference to the reference manager in use |
129 |
|
|
*/ |
130 |
tdb |
1.6 |
private ReferenceManager _refman; |
131 |
tdb |
1.5 |
|
132 |
|
|
//---STATIC ATTRIBUTES--- |
133 |
tdb |
1.1 |
|
134 |
|
|
} |