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.12
Committed: Sat May 18 18:16:01 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.11: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

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