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.3
Committed: Mon Feb 5 00:58:46 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.2: +25 -94 lines
Log Message:
The original "all in one" class didn't work quite right, so it's been broken
down into two classes; one for control, and one for sending data. The whole lot
functions in a very similar way to the TCP setup, except that communication
happens over CORBA.

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