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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/CorbaControlHandlerServant.java (file contents):
Revision 1.1 by tdb, Sat Feb 3 00:42:54 2001 UTC vs.
Revision 1.4 by tdb, Mon Feb 12 02:23:52 2001 UTC

# Line 9 | Line 9 | import uk.ac.ukc.iscream.client.*;
9  
10  
11   /**
12 < * Acts as a Handler to a CORBA based client.
12 > * Acts as a Control Handler to a CORBA based client.
13   *
14   * !!! FUNDAMENTAL DESIGN PROBLEM !!!
15   * !!! Need a way to "shutdown" this class !!!
# Line 17 | Line 17 | import uk.ac.ukc.iscream.client.*;
17   * @author  $Author$
18   * @version $Id$
19   */
20 < class CorbaHandlerServant extends Thread implements CorbaHandlerOperations {
20 > class CorbaControlHandlerServant extends CorbaControlHandlerPOA {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 31 | Line 31 | class CorbaHandlerServant extends Thread implements Co
31   //---CONSTRUCTORS---
32      
33      /**
34 <     * Construct a new CorbaHandlerServant.
34 >     * Construct a new CorbaControlHandlerServant.
35       *
36       * @param packetSorter A reference to the PacketSorter in the component
37     * @param name The name of the client
37       * @param client A reference to the "servant" part of the connecting client.
38       */
39 <    public CorbaHandlerServant(PacketSorter packetSorter, String name, Client client) {
39 >    public CorbaControlHandlerServant(PacketSorter packetSorter, Client client) {
40          _packetSorter = packetSorter;
42        _clientName = name;
41          _hostList = "";
44        _queue = new Queue();
42          _client = client;
43 +        _dataHandler = null;
44          _logger.write(toString(), Logger.SYSINIT, "created");
45      }
46      
47   //---PUBLIC METHODS---
48      
49      /**
52     * This method loops round until we "shutdown" (not implemented yet). Inside
53     * the main loop we will first wait until the startData() method is called,
54     * then we'll send data constantly until stopData() is called.
55     */
56    public void run() {
57        // get a queue
58        _queueID = _queue.getQueue();
59        // we'll keep going until someone implements a "shutdown" :)
60        run = true;
61        while(run) {
62            // initially lock until someone tells us to start
63            synchronized(this) {
64                try { wait(); } catch(Exception e) {}
65            }
66            // loop sending data
67            while(_sendingData) {
68                try {
69                    String xml = (String) _queue.get(_queueID);
70                    // if it's not null (which could happen if we're "released")
71                    // send it on to the client that we're connected to.
72                    if(xml != null) {
73                        _client.receiveXML(xml);
74                    }
75                }
76                catch(InvalidQueueException e) {
77                    // lets stop sending - maybe stop altogether ?
78                    stopData();
79                    _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
80                }
81            }
82            // now, we've obviously been stopped, so we'll head back round this
83            // while loop until someone starts us again.
84        }
85        // if we get here we've been told to stop
86        _logger.write(toString(), Logger.SYSMSG, "Shutting Down");
87        // remove ourselves from the queue
88        _queue.removeQueue(_queueID);
89    }
90    
91    /**
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 <        if(!_sendingData) {
55 >        if(_dataHandler == null) {
56 >            // create a new DataHandler
57 >            CorbaDataHandler dh = new CorbaDataHandler(_client);
58              // register the Queue
59 <            _packetSorter.register(_queue, _hostList);
60 <            // mark the running flag
61 <            _sendingData = true;
62 <            // bump the loop
63 <            synchronized(this) {
64 <                try { notifyAll(); } catch(Exception e) {}
65 <            }
59 >            _packetSorter.register(dh.getQueue(), _hostList);
60 >            // startup a monitor on the DataHandler's queue, every minute
61 >            dh.getQueue().startMonitor(60*1000, _packetSorter.getQueue(), _name);
62 >            // start the DataHandler running
63 >            dh.start();
64 >            // keep a reference
65 >            _dataHandler = dh;
66              return true;
67          }
68          else {
# Line 116 | Line 76 | class CorbaHandlerServant extends Thread implements Co
76       * @return a boolean stating whether the attempt to stop succeeded
77       */
78      public boolean stopData() {
79 <        if(_sendingData) {
79 >        if(_dataHandler != null) {
80              // deregister the Queue
81 <            _packetSorter.deregister(_queue, _hostList);
82 <            // stop ourselves running
83 <            _sendingData = false;
84 <            // if the main loop is waiting for data it won't notice the
85 <            // above flag to stop. This bumps it out of the blocked get().
126 <            _queue.releaseQueue(_queueID);
81 >            _packetSorter.deregister(_dataHandler.getQueue(), _hostList);
82 >            // stop the DataHandler
83 >            _dataHandler.shutdown();
84 >            // destroy the reference
85 >            _dataHandler = null;
86              return true;
87          }
88          else {
# Line 139 | Line 98 | class CorbaHandlerServant extends Thread implements Co
98       * @return Whether the request succeeded.
99       */
100      public boolean setHostList(String hostList) {
101 <        if(!_sendingData) {
101 >        if(_dataHandler == null) {
102              _hostList = hostList;
103              return true;
104          }
# Line 188 | Line 147 | class CorbaHandlerServant extends Thread implements Co
147      private Logger _logger = ReferenceManager.getInstance().getLogger();
148      
149      /**
191     * A reference to the Configuration Manager the system is using
192     */
193    private ConfigurationManager _configManager = ReferenceManager.getInstance().getCM();
194    
195    /**
150           * A reference to the PacketSorter.
151           */
152      private PacketSorter _packetSorter;
# Line 203 | Line 157 | class CorbaHandlerServant extends Thread implements Co
157      private String _hostList;
158      
159      /**
206     * The name of the connected client.
207     */
208    private String _clientName;
209    
210    /**
211     * Whether we are active and sending data.
212     */
213    private boolean _sendingData;
214    
215    /**
216     * The Queue we'll use for buffering data to the client.
217     */
218    private Queue _queue;
219    
220    /**
160       * The "servant" part of the client we're connected to.
161       */
162      private Client _client;
163      
164      /**
165 <     * Our queue number within our Queue
165 >     * A reference to our DataHandler, if we have one
166       */
167 <    private int _queueID;
229 <    
230 <    /**
231 <     * The flag that dictates whether the main loop should *completely* exit
232 <     */
233 <    private boolean run;
167 >    private CorbaDataHandler _dataHandler;
168      
169   //---STATIC ATTRIBUTES---
170  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines