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