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