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.5
Committed: Wed Feb 21 19:11:28 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.4: +12 -4 lines
Log Message:
Modification to the Queue system;
- interval of monitor is now configurable.
- attempt to identify each Queue better, although this is still hard.

File Contents

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