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.14
Committed: Wed Feb 5 16:43:46 2003 UTC (21 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.13: +4 -4 lines
Log Message:
Changed the server to use the external util package. Quite a minor change,
but does affect a lot of files.

File Contents

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