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/CorbaDataHandler.java
Revision: 1.10
Committed: Tue May 29 17:02:34 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.9: +8 -8 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 tdb 1.10 package uk.org.iscream.cms.server.clientinterface;
3 tdb 1.1
4     //---IMPORTS---
5 tdb 1.10 import uk.org.iscream.cms.server.util.*;
6     import uk.org.iscream.cms.server.componentmanager.*;
7     import uk.org.iscream.cms.server.core.*;
8     import uk.org.iscream.cms.server.client.*;
9 tdb 1.1
10    
11     /**
12     * Acts as a Data Handler to a CORBA based client.
13     *
14 tdb 1.2 * @author $Author: tdb1 $
15 tdb 1.10 * @version $Id: CorbaDataHandler.java,v 1.9 2001/03/16 16:11:31 tdb1 Exp $
16 tdb 1.1 */
17     class CorbaDataHandler extends Thread {
18    
19     //---FINAL ATTRIBUTES---
20    
21     /**
22     * The current CVS revision of this class
23     */
24 tdb 1.10 public final String REVISION = "$Revision: 1.9 $";
25 tdb 1.1
26     //---STATIC METHODS---
27    
28     //---CONSTRUCTORS---
29    
30     /**
31     * Construct a new CorbaDataHandler.
32     *
33     * @param client A reference to the "servant" part of the connecting client.
34 tdb 1.7 * @param cchServer A reference to the class that is control us.
35 tdb 1.1 */
36 tdb 1.7 public CorbaDataHandler(Client client, CorbaControlHandlerServant cchServant) {
37 tdb 1.5 // set the Thread name
38     setName("clientinterface.CorbaDataHandler");
39    
40 tdb 1.9 ConfigurationProxy cp = ConfigurationProxy.getInstance();
41     String configName = "ClientInterface";
42     // see if this Queue needs a size limit
43     try {
44     int queueSizeLimit = Integer.parseInt(cp.getProperty(configName, "Queue.SizeLimit"));
45     String queueRemoveAlgorithm = cp.getProperty(configName, "Queue.RemoveAlgorithm");
46     int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms);
47     if(algorithm != -1) {
48     _logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm);
49     // we have valid values, so lets start it.
50     _queue = new Queue(queueSizeLimit, algorithm);
51     }
52     else {
53     _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
54     // just don't activate a limit
55     _queue = new Queue();
56     }
57    
58     } catch (PropertyNotFoundException e) {
59     _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
60     // just don't activate a limit
61     _queue = new Queue();
62     } catch (NumberFormatException e) {
63     _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
64     // just don't activate a limit
65     _queue = new Queue();
66     }
67    
68 tdb 1.1 _client = client;
69 tdb 1.7 _cchServant = cchServant;
70 tdb 1.1 _logger.write(toString(), Logger.SYSINIT, "created");
71     }
72    
73     //---PUBLIC METHODS---
74    
75     /**
76     * This method loops round until such a point as we shutdown. It keeps
77     * grabbing data items from it's Queue, then sends them on to the connected
78     * client over CORBA.
79     */
80     public void run() {
81     // get a queue
82     _queueID = _queue.getQueue();
83     // we'll keep going until someone implements a "shutdown" :)
84     run = true;
85     // loop sending data
86     while(run) {
87     try {
88     String xml = (String) _queue.get(_queueID);
89     // if it's not null (which could happen if we're "released")
90     // send it on to the client that we're connected to.
91     if(xml != null) {
92 tdb 1.3 try {
93     _client.receiveXML(xml);
94     }
95     catch (org.omg.CORBA.COMM_FAILURE e) {
96     // lets stop sending, the client has quit
97     run = false;
98     _logger.write(toString(), Logger.ERROR, "Connection failure, client shutdown? : "+e);
99 tdb 1.7 // disconnect the servant above us, or at least try
100     _cchServant.disconnect();
101 tdb 1.3 }
102 tdb 1.1 }
103     }
104     catch(InvalidQueueException e) {
105     // lets stop sending.
106     run = false;
107     _logger.write(toString(), Logger.ERROR, "Queue failure: "+e);
108     }
109     }
110     // if we get here we've been told to stop
111     _logger.write(toString(), Logger.SYSMSG, "Shutting Down");
112     // remove ourselves from the queue
113     _queue.removeQueue(_queueID);
114 tdb 1.4 _queue.stopMonitor();
115 tdb 1.1 }
116    
117     /**
118     * Method to shutdown this Data Handler. All this actually does
119     * is set a flag which the main loop will see and commence shutting
120     * down. This method will return before the main loop stops.
121     */
122     public void shutdown() {
123     // set the main loop to stop
124     run=false;
125     // if the main loop is waiting for data it won't notice the
126     // above flag to stop. This bumps it out of the blocked get.
127     _queue.releaseQueue(_queueID);
128     }
129    
130     /**
131     * Overrides the {@link java.lang.Object#toString() Object.toString()}
132     * method to provide clean logging (every class should have this).
133     *
134 tdb 1.10 * This uses the uk.org.iscream.cms.server.util.NameFormat class
135 tdb 1.1 * to format the toString()
136     *
137     * @return the name of this class and its CVS revision
138     */
139     public String toString() {
140     return FormatName.getName(
141     _name,
142     getClass().getName(),
143     REVISION);
144     }
145    
146     //---PRIVATE METHODS---
147 tdb 1.8
148     /**
149     * Overridden for debugging purposes
150     * to see when an instance of this class
151     * is destroyed
152     */
153     protected void finalize() throws Throwable {
154     _logger.write(this.toString(), Logger.DEBUG, "finalized by GC");
155     }
156 tdb 1.1
157     //---ACCESSOR/MUTATOR METHODS---
158    
159     /**
160     * Accessor to our Queue. The Control Handler needs to
161     * get this reference to register us.
162     *
163     * @return a reference to our Queue
164     */
165     public Queue getQueue() {
166     return _queue;
167     }
168    
169     //---ATTRIBUTES---
170    
171     /**
172     * This is the friendly identifier of the
173     * component this class is running in.
174     * eg, a Filter may be called "filter1",
175     * If this class does not have an owning
176     * component, a name from the configuration
177     * can be placed here. This name could also
178     * be changed to null for utility classes.
179     */
180     private String _name = ClientInterfaceMain.NAME;
181    
182     /**
183     * This holds a reference to the
184     * system logger that is being used.
185     */
186     private Logger _logger = ReferenceManager.getInstance().getLogger();
187    
188     /**
189     * The Queue we'll use for buffering data to the client.
190     */
191     private Queue _queue;
192    
193     /**
194     * The "servant" part of the client we're connected to.
195     */
196     private Client _client;
197    
198     /**
199     * Our queue number within our Queue
200     */
201     private int _queueID;
202    
203     /**
204     * The flag that dictates whether the main loop should *completely* exit
205     */
206     private boolean run;
207 tdb 1.7
208     /**
209     * A reference to our controlling class
210     */
211     private CorbaControlHandlerServant _cchServant;
212 tdb 1.1
213     //---STATIC ATTRIBUTES---
214    
215     }