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.6 |
* @version $Id: CorbaControlHandlerServant.java,v 1.5 2001/02/21 19:11:28 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.6 |
public final String REVISION = "$Revision: 1.5 $"; |
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.6 |
public CorbaControlHandlerServant(PacketSorter packetSorter, Client client, int queueMonitorInterval, String clientname) { |
42 |
tdb |
1.1 |
_packetSorter = packetSorter; |
43 |
tdb |
1.5 |
_queueMonitorInterval = queueMonitorInterval; |
44 |
tdb |
1.1 |
_hostList = ""; |
45 |
|
|
_client = client; |
46 |
tdb |
1.6 |
_clientname = clientname; |
47 |
tdb |
1.3 |
_dataHandler = null; |
48 |
tdb |
1.1 |
_logger.write(toString(), Logger.SYSINIT, "created"); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
//---PUBLIC METHODS--- |
52 |
|
|
|
53 |
|
|
/** |
54 |
|
|
* Start sending data to the client. |
55 |
|
|
* |
56 |
|
|
* @return a boolean stating whether the attempt to start succeeded |
57 |
|
|
*/ |
58 |
|
|
public boolean startData() { |
59 |
tdb |
1.3 |
if(_dataHandler == null) { |
60 |
|
|
// create a new DataHandler |
61 |
|
|
CorbaDataHandler dh = new CorbaDataHandler(_client); |
62 |
tdb |
1.1 |
// register the Queue |
63 |
tdb |
1.3 |
_packetSorter.register(dh.getQueue(), _hostList); |
64 |
tdb |
1.4 |
// startup a monitor on the DataHandler's queue, every minute |
65 |
tdb |
1.6 |
String queueName = _name + " CorbaHandler:"+_clientname; |
66 |
tdb |
1.5 |
dh.getQueue().startMonitor(_queueMonitorInterval*1000, _packetSorter.getQueue(), queueName); |
67 |
tdb |
1.3 |
// start the DataHandler running |
68 |
|
|
dh.start(); |
69 |
|
|
// keep a reference |
70 |
|
|
_dataHandler = dh; |
71 |
tdb |
1.1 |
return true; |
72 |
|
|
} |
73 |
|
|
else { |
74 |
|
|
return false; |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
/** |
79 |
|
|
* Stop sending data to the client. |
80 |
|
|
* |
81 |
|
|
* @return a boolean stating whether the attempt to stop succeeded |
82 |
|
|
*/ |
83 |
|
|
public boolean stopData() { |
84 |
tdb |
1.3 |
if(_dataHandler != null) { |
85 |
tdb |
1.1 |
// deregister the Queue |
86 |
tdb |
1.3 |
_packetSorter.deregister(_dataHandler.getQueue(), _hostList); |
87 |
|
|
// stop the DataHandler |
88 |
|
|
_dataHandler.shutdown(); |
89 |
|
|
// destroy the reference |
90 |
|
|
_dataHandler = null; |
91 |
tdb |
1.1 |
return true; |
92 |
|
|
} |
93 |
|
|
else { |
94 |
|
|
return false; |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
/** |
99 |
|
|
* Sets the host list for the Client to the requested semi-colon separated |
100 |
|
|
* list of hostnames. This will only succeed if we are not sending data. |
101 |
|
|
* |
102 |
|
|
* @param hostList A semi-colon separated list of hostnames to use. |
103 |
|
|
* @return Whether the request succeeded. |
104 |
|
|
*/ |
105 |
|
|
public boolean setHostList(String hostList) { |
106 |
tdb |
1.3 |
if(_dataHandler == null) { |
107 |
tdb |
1.1 |
_hostList = hostList; |
108 |
|
|
return true; |
109 |
|
|
} |
110 |
|
|
else { |
111 |
|
|
return false; |
112 |
|
|
} |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
/** |
116 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
117 |
|
|
* method to provide clean logging (every class should have this). |
118 |
|
|
* |
119 |
|
|
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
120 |
|
|
* to format the toString() |
121 |
|
|
* |
122 |
|
|
* @return the name of this class and its CVS revision |
123 |
|
|
*/ |
124 |
|
|
public String toString() { |
125 |
|
|
return FormatName.getName( |
126 |
|
|
_name, |
127 |
|
|
getClass().getName(), |
128 |
|
|
REVISION); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
//---PRIVATE METHODS--- |
132 |
|
|
|
133 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
134 |
|
|
|
135 |
|
|
//---ATTRIBUTES--- |
136 |
|
|
|
137 |
|
|
/** |
138 |
|
|
* This is the friendly identifier of the |
139 |
|
|
* component this class is running in. |
140 |
|
|
* eg, a Filter may be called "filter1", |
141 |
|
|
* If this class does not have an owning |
142 |
|
|
* component, a name from the configuration |
143 |
|
|
* can be placed here. This name could also |
144 |
|
|
* be changed to null for utility classes. |
145 |
|
|
*/ |
146 |
|
|
private String _name = ClientInterfaceMain.NAME; |
147 |
|
|
|
148 |
|
|
/** |
149 |
|
|
* This holds a reference to the |
150 |
|
|
* system logger that is being used. |
151 |
|
|
*/ |
152 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
153 |
|
|
|
154 |
|
|
/** |
155 |
|
|
* A reference to the PacketSorter. |
156 |
|
|
*/ |
157 |
|
|
private PacketSorter _packetSorter; |
158 |
|
|
|
159 |
|
|
/** |
160 |
|
|
* The host list the Client has requested |
161 |
|
|
*/ |
162 |
|
|
private String _hostList; |
163 |
|
|
|
164 |
|
|
/** |
165 |
|
|
* The "servant" part of the client we're connected to. |
166 |
|
|
*/ |
167 |
|
|
private Client _client; |
168 |
|
|
|
169 |
|
|
/** |
170 |
tdb |
1.3 |
* A reference to our DataHandler, if we have one |
171 |
tdb |
1.1 |
*/ |
172 |
tdb |
1.3 |
private CorbaDataHandler _dataHandler; |
173 |
tdb |
1.5 |
|
174 |
|
|
/** |
175 |
|
|
* The interval at which to monitor our Queue |
176 |
|
|
*/ |
177 |
|
|
private int _queueMonitorInterval; |
178 |
tdb |
1.6 |
|
179 |
|
|
/** |
180 |
|
|
* A name to identify the client |
181 |
|
|
*/ |
182 |
|
|
private String _clientname; |
183 |
tdb |
1.1 |
|
184 |
|
|
//---STATIC ATTRIBUTES--- |
185 |
|
|
|
186 |
|
|
} |