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.ac.ukc.iscream.clientinterface; |
22 |
> |
package uk.org.iscream.cms.server.clientinterface; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.util.*; |
26 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
27 |
< |
import uk.ac.ukc.iscream.core.*; |
8 |
< |
import uk.ac.ukc.iscream.client.*; |
25 |
> |
import uk.org.iscream.cms.util.*; |
26 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
27 |
> |
import uk.org.iscream.cms.server.core.*; |
28 |
|
|
29 |
|
|
30 |
|
/** |
50 |
|
* Construct a new CorbaDataHandler. |
51 |
|
* |
52 |
|
* @param client A reference to the "servant" part of the connecting client. |
53 |
+ |
* @param cchServer A reference to the class that is control us. |
54 |
|
*/ |
55 |
< |
public CorbaDataHandler(Client client) { |
56 |
< |
_queue = new Queue(); |
55 |
> |
public CorbaDataHandler(Client client, CorbaControlHandlerServant cchServant) { |
56 |
> |
// set the Thread name |
57 |
> |
setName("clientinterface.CorbaDataHandler"); |
58 |
> |
|
59 |
> |
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 |
|
_client = client; |
88 |
+ |
_cchServant = cchServant; |
89 |
|
_logger.write(toString(), Logger.SYSINIT, "created"); |
90 |
|
} |
91 |
|
|
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 |
< |
// !!! SOME CHECKS REQUIRED HERE !!! |
112 |
< |
_client.receiveXML(xml); |
111 |
> |
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 |
> |
_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 |
> |
} |
124 |
|
} |
125 |
|
} |
126 |
|
catch(InvalidQueueException e) { |
129 |
|
_logger.write(toString(), Logger.ERROR, "Queue failure: "+e); |
130 |
|
} |
131 |
|
} |
132 |
+ |
// disconnect the servant above us, or at least try |
133 |
+ |
_cchServant.disconnect(); |
134 |
|
// 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 |
+ |
_queue.stopMonitor(); |
139 |
|
} |
140 |
|
|
141 |
|
/** |
155 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
156 |
|
* method to provide clean logging (every class should have this). |
157 |
|
* |
158 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
158 |
> |
* This uses the uk.org.iscream.cms.util.NameFormat class |
159 |
|
* to format the toString() |
160 |
|
* |
161 |
|
* @return the name of this class and its CVS revision |
169 |
|
|
170 |
|
//---PRIVATE METHODS--- |
171 |
|
|
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 |
+ |
|
181 |
|
//---ACCESSOR/MUTATOR METHODS--- |
182 |
|
|
183 |
|
/** |
228 |
|
* The flag that dictates whether the main loop should *completely* exit |
229 |
|
*/ |
230 |
|
private boolean run; |
231 |
+ |
|
232 |
+ |
/** |
233 |
+ |
* A reference to our controlling class |
234 |
+ |
*/ |
235 |
+ |
private CorbaControlHandlerServant _cchServant; |
236 |
|
|
237 |
|
//---STATIC ATTRIBUTES--- |
238 |
|
|