1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.ac.ukc.iscream.clientinterface; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
|
|
import uk.ac.ukc.iscream.util.*; |
6 |
|
|
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
|
|
import uk.ac.ukc.iscream.core.*; |
8 |
|
|
import uk.ac.ukc.iscream.client.*; |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
/** |
12 |
tdb |
1.3 |
* Acts as a Control Handler to a CORBA based client. |
13 |
tdb |
1.1 |
* |
14 |
|
|
* !!! FUNDAMENTAL DESIGN PROBLEM !!! |
15 |
|
|
* !!! Need a way to "shutdown" this class !!! |
16 |
|
|
* |
17 |
tdb |
1.4 |
* @author $Author: tdb1 $ |
18 |
tdb |
1.8 |
* @version $Id: CorbaControlHandlerServant.java,v 1.7 2001/03/13 18:37:08 tdb1 Exp $ |
19 |
tdb |
1.1 |
*/ |
20 |
tdb |
1.3 |
class CorbaControlHandlerServant extends CorbaControlHandlerPOA { |
21 |
tdb |
1.1 |
|
22 |
|
|
//---FINAL ATTRIBUTES--- |
23 |
|
|
|
24 |
|
|
/** |
25 |
|
|
* The current CVS revision of this class |
26 |
|
|
*/ |
27 |
tdb |
1.8 |
public final String REVISION = "$Revision: 1.7 $"; |
28 |
tdb |
1.1 |
|
29 |
|
|
//---STATIC METHODS--- |
30 |
|
|
|
31 |
|
|
//---CONSTRUCTORS--- |
32 |
|
|
|
33 |
|
|
/** |
34 |
tdb |
1.3 |
* Construct a new CorbaControlHandlerServant. |
35 |
tdb |
1.1 |
* |
36 |
|
|
* @param packetSorter A reference to the PacketSorter in the component |
37 |
|
|
* @param client A reference to the "servant" part of the connecting client. |
38 |
tdb |
1.5 |
* @param queueMonitorInterval The interval at which to monitor our Queue. |
39 |
tdb |
1.6 |
* @param clientname A name to identify the client. |
40 |
tdb |
1.1 |
*/ |
41 |
tdb |
1.7 |
public CorbaControlHandlerServant(PacketSorter packetSorter, Client client, String clientname) { |
42 |
tdb |
1.1 |
_packetSorter = packetSorter; |
43 |
|
|
_hostList = ""; |
44 |
|
|
_client = client; |
45 |
tdb |
1.6 |
_clientname = clientname; |
46 |
tdb |
1.3 |
_dataHandler = null; |
47 |
tdb |
1.1 |
_logger.write(toString(), Logger.SYSINIT, "created"); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
//---PUBLIC METHODS--- |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* Start sending data to the client. |
54 |
|
|
* |
55 |
|
|
* @return a boolean stating whether the attempt to start succeeded |
56 |
|
|
*/ |
57 |
|
|
public boolean startData() { |
58 |
tdb |
1.3 |
if(_dataHandler == null) { |
59 |
|
|
// create a new DataHandler |
60 |
|
|
CorbaDataHandler dh = new CorbaDataHandler(_client); |
61 |
tdb |
1.1 |
// register the Queue |
62 |
tdb |
1.3 |
_packetSorter.register(dh.getQueue(), _hostList); |
63 |
tdb |
1.7 |
try { |
64 |
|
|
// startup a monitor on the DataHandler's queue |
65 |
|
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
66 |
|
|
int queueMonitorInterval = Integer.parseInt(cp.getProperty("ClientInterface", "Queue.MonitorInterval")); |
67 |
|
|
String queueName = _name + " CorbaHandler:"+_clientname; |
68 |
|
|
dh.getQueue().startMonitor(queueMonitorInterval*1000, _packetSorter.getQueue(), queueName); |
69 |
|
|
} catch (PropertyNotFoundException e) { |
70 |
|
|
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
71 |
|
|
} |
72 |
tdb |
1.3 |
// start the DataHandler running |
73 |
|
|
dh.start(); |
74 |
|
|
// keep a reference |
75 |
|
|
_dataHandler = dh; |
76 |
tdb |
1.1 |
return true; |
77 |
|
|
} |
78 |
|
|
else { |
79 |
|
|
return false; |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
* Stop sending data to the client. |
85 |
|
|
* |
86 |
|
|
* @return a boolean stating whether the attempt to stop succeeded |
87 |
|
|
*/ |
88 |
|
|
public boolean stopData() { |
89 |
tdb |
1.3 |
if(_dataHandler != null) { |
90 |
tdb |
1.1 |
// deregister the Queue |
91 |
tdb |
1.3 |
_packetSorter.deregister(_dataHandler.getQueue(), _hostList); |
92 |
|
|
// stop the DataHandler |
93 |
|
|
_dataHandler.shutdown(); |
94 |
|
|
// destroy the reference |
95 |
|
|
_dataHandler = null; |
96 |
tdb |
1.1 |
return true; |
97 |
|
|
} |
98 |
|
|
else { |
99 |
|
|
return false; |
100 |
|
|
} |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
/** |
104 |
|
|
* Sets the host list for the Client to the requested semi-colon separated |
105 |
|
|
* list of hostnames. This will only succeed if we are not sending data. |
106 |
|
|
* |
107 |
|
|
* @param hostList A semi-colon separated list of hostnames to use. |
108 |
|
|
* @return Whether the request succeeded. |
109 |
|
|
*/ |
110 |
|
|
public boolean setHostList(String hostList) { |
111 |
tdb |
1.3 |
if(_dataHandler == null) { |
112 |
tdb |
1.1 |
_hostList = hostList; |
113 |
|
|
return true; |
114 |
|
|
} |
115 |
|
|
else { |
116 |
|
|
return false; |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/** |
121 |
tdb |
1.8 |
* Disconnect, this will shutdown the data and unhook from |
122 |
|
|
* the CORBA ORB. |
123 |
|
|
*/ |
124 |
|
|
public void disconnect() { |
125 |
|
|
// close the data handler |
126 |
|
|
stopData(); |
127 |
|
|
// disconnect from the ORB |
128 |
|
|
try { |
129 |
|
|
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(this); |
130 |
|
|
_refman.getORB().disconnect(objRef); |
131 |
|
|
} catch(Exception e) { |
132 |
|
|
_logger.write(this.toString(), Logger.ERROR, "disconnect failed: "+e); |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
/** |
137 |
tdb |
1.1 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
138 |
|
|
* method to provide clean logging (every class should have this). |
139 |
|
|
* |
140 |
|
|
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
141 |
|
|
* to format the toString() |
142 |
|
|
* |
143 |
|
|
* @return the name of this class and its CVS revision |
144 |
|
|
*/ |
145 |
|
|
public String toString() { |
146 |
|
|
return FormatName.getName( |
147 |
|
|
_name, |
148 |
|
|
getClass().getName(), |
149 |
|
|
REVISION); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
//---PRIVATE METHODS--- |
153 |
|
|
|
154 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
155 |
|
|
|
156 |
|
|
//---ATTRIBUTES--- |
157 |
|
|
|
158 |
|
|
/** |
159 |
|
|
* This is the friendly identifier of the |
160 |
|
|
* component this class is running in. |
161 |
|
|
* eg, a Filter may be called "filter1", |
162 |
|
|
* If this class does not have an owning |
163 |
|
|
* component, a name from the configuration |
164 |
|
|
* can be placed here. This name could also |
165 |
|
|
* be changed to null for utility classes. |
166 |
|
|
*/ |
167 |
|
|
private String _name = ClientInterfaceMain.NAME; |
168 |
|
|
|
169 |
|
|
/** |
170 |
|
|
* This holds a reference to the |
171 |
|
|
* system logger that is being used. |
172 |
|
|
*/ |
173 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
174 |
tdb |
1.8 |
|
175 |
|
|
/** |
176 |
|
|
* A reference to the reference manager in use |
177 |
|
|
*/ |
178 |
|
|
private ReferenceManager _refman = ReferenceManager.getInstance(); |
179 |
tdb |
1.1 |
|
180 |
|
|
/** |
181 |
|
|
* A reference to the PacketSorter. |
182 |
|
|
*/ |
183 |
|
|
private PacketSorter _packetSorter; |
184 |
|
|
|
185 |
|
|
/** |
186 |
|
|
* The host list the Client has requested |
187 |
|
|
*/ |
188 |
|
|
private String _hostList; |
189 |
|
|
|
190 |
|
|
/** |
191 |
|
|
* The "servant" part of the client we're connected to. |
192 |
|
|
*/ |
193 |
|
|
private Client _client; |
194 |
|
|
|
195 |
|
|
/** |
196 |
tdb |
1.3 |
* A reference to our DataHandler, if we have one |
197 |
tdb |
1.1 |
*/ |
198 |
tdb |
1.3 |
private CorbaDataHandler _dataHandler; |
199 |
tdb |
1.6 |
|
200 |
|
|
/** |
201 |
|
|
* A name to identify the client |
202 |
|
|
*/ |
203 |
|
|
private String _clientname; |
204 |
tdb |
1.1 |
|
205 |
|
|
//---STATIC ATTRIBUTES--- |
206 |
|
|
|
207 |
|
|
} |