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