ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/CorbaControlHandlerServant.java
Revision: 1.6
Committed: Wed Feb 28 19:04:00 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.5: +11 -4 lines
Log Message:
Now requires a client send a name. This is to enable each handler to be
identified from the others. With TCP ones, this was quite easily done with the
hostname (which isn't perfect), but with corba a name was required.

File Contents

# Content
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 * Acts as a Control Handler to a CORBA based client.
13 *
14 * !!! FUNDAMENTAL DESIGN PROBLEM !!!
15 * !!! Need a way to "shutdown" this class !!!
16 *
17 * @author $Author: tdb1 $
18 * @version $Id: CorbaControlHandlerServant.java,v 1.5 2001/02/21 19:11:28 tdb1 Exp $
19 */
20 class CorbaControlHandlerServant extends CorbaControlHandlerPOA {
21
22 //---FINAL ATTRIBUTES---
23
24 /**
25 * The current CVS revision of this class
26 */
27 public final String REVISION = "$Revision: 1.5 $";
28
29 //---STATIC METHODS---
30
31 //---CONSTRUCTORS---
32
33 /**
34 * Construct a new CorbaControlHandlerServant.
35 *
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 * @param queueMonitorInterval The interval at which to monitor our Queue.
39 * @param clientname A name to identify the client.
40 */
41 public CorbaControlHandlerServant(PacketSorter packetSorter, Client client, int queueMonitorInterval, String clientname) {
42 _packetSorter = packetSorter;
43 _queueMonitorInterval = queueMonitorInterval;
44 _hostList = "";
45 _client = client;
46 _clientname = clientname;
47 _dataHandler = null;
48 _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 if(_dataHandler == null) {
60 // create a new DataHandler
61 CorbaDataHandler dh = new CorbaDataHandler(_client);
62 // register the Queue
63 _packetSorter.register(dh.getQueue(), _hostList);
64 // startup a monitor on the DataHandler's queue, every minute
65 String queueName = _name + " CorbaHandler:"+_clientname;
66 dh.getQueue().startMonitor(_queueMonitorInterval*1000, _packetSorter.getQueue(), queueName);
67 // start the DataHandler running
68 dh.start();
69 // keep a reference
70 _dataHandler = dh;
71 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 if(_dataHandler != null) {
85 // deregister the Queue
86 _packetSorter.deregister(_dataHandler.getQueue(), _hostList);
87 // stop the DataHandler
88 _dataHandler.shutdown();
89 // destroy the reference
90 _dataHandler = null;
91 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 if(_dataHandler == null) {
107 _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 * A reference to our DataHandler, if we have one
171 */
172 private CorbaDataHandler _dataHandler;
173
174 /**
175 * The interval at which to monitor our Queue
176 */
177 private int _queueMonitorInterval;
178
179 /**
180 * A name to identify the client
181 */
182 private String _clientname;
183
184 //---STATIC ATTRIBUTES---
185
186 }