1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.client; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.clientinterface.*; |
6 |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
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 |
* @author $Author: tdb1 $ |
14 |
* @version $Id: ClientMain.java,v 1.10 2001/03/02 02:47:16 tdb1 Exp $ |
15 |
*/ |
16 |
public class ClientMain implements Component { |
17 |
|
18 |
//---FINAL ATTRIBUTES--- |
19 |
|
20 |
/** |
21 |
* The current CVS revision of this class |
22 |
*/ |
23 |
public static final String REVISION = "$Revision: 1.10 $"; |
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 |
//---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 |
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 queues, this must be done before both managers are setup |
66 |
String queueName; |
67 |
// setup a Queue for the servant -> monitor manager |
68 |
_monitorQueue = new Queue(); |
69 |
|
70 |
// setup a Queue for the monitors -> alert manager |
71 |
_alerterQueue = new Queue(); |
72 |
|
73 |
|
74 |
|
75 |
// setup the servant and connect |
76 |
_logger.write(toString(), Logger.SYSINIT, "starting servant and connecting"); |
77 |
try { |
78 |
ClientServant ref = new ClientServant(_monitorQueue); |
79 |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
80 |
Client client = ClientHelper.narrow(objRef); |
81 |
|
82 |
// this name maybe shouldn't be static |
83 |
objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener"); |
84 |
CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef); |
85 |
|
86 |
_logger.write(toString(), Logger.SYSINIT, "connecting"); |
87 |
CorbaControlHandler handler = listener.connect(client, NAME); |
88 |
handler.startData(); |
89 |
} |
90 |
catch(Exception e) { |
91 |
// not sure what to do here |
92 |
// so we just log the error |
93 |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); |
94 |
} |
95 |
|
96 |
// setup the MonitorManager |
97 |
MonitorManager monMan = MonitorManager.getInstance(); |
98 |
monMan.start(); |
99 |
|
100 |
// setup the AlerterManager |
101 |
AlerterManager alertMan = AlerterManager.getInstance(); |
102 |
alertMan.start(); |
103 |
|
104 |
_logger.write(toString(), Logger.SYSINIT, "started"); |
105 |
|
106 |
} |
107 |
|
108 |
/** |
109 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
110 |
* method to provide clean logging (every class should have this). |
111 |
* |
112 |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
113 |
* to format the toString() |
114 |
* |
115 |
* @return the name of this class and its CVS revision |
116 |
*/ |
117 |
public String toString() { |
118 |
return FormatName.getName( |
119 |
NAME, |
120 |
getClass().getName(), |
121 |
REVISION); |
122 |
} |
123 |
|
124 |
//---PRIVATE METHODS--- |
125 |
|
126 |
//---ACCESSOR/MUTATOR METHODS--- |
127 |
|
128 |
//---ATTRIBUTES--- |
129 |
|
130 |
/** |
131 |
* This holds a reference to the |
132 |
* system logger that is being used. |
133 |
*/ |
134 |
private Logger _logger; |
135 |
|
136 |
/** |
137 |
* A reference to the reference manager in use |
138 |
*/ |
139 |
private ReferenceManager _refman; |
140 |
|
141 |
//---STATIC ATTRIBUTES--- |
142 |
|
143 |
/** |
144 |
* A queue for the alerter manager |
145 |
*/ |
146 |
public static Queue _alerterQueue; |
147 |
|
148 |
/** |
149 |
* A queue for the monitor manager |
150 |
*/ |
151 |
public static Queue _monitorQueue; |
152 |
|
153 |
} |