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.rootfilter; |
22 |
> |
package uk.org.iscream.cms.server.rootfilter; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.core.*; |
26 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
27 |
< |
import uk.ac.ukc.iscream.clientinterface.*; |
28 |
< |
import uk.ac.ukc.iscream.util.*; |
25 |
> |
import uk.org.iscream.cms.server.core.*; |
26 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
27 |
> |
import uk.org.iscream.cms.server.clientinterface.*; |
28 |
> |
import uk.org.iscream.cms.util.*; |
29 |
|
|
30 |
|
/** |
31 |
|
* A ClientInterface wrapper - the CI objects are pushed data, |
55 |
|
* @param queue a reference to a queue to use |
56 |
|
*/ |
57 |
|
public CIWrapper(ClientInterface destination, Queue queue){ |
58 |
+ |
// set the Thread name |
59 |
+ |
setName("rootfilter.CIWrapper"); |
60 |
+ |
|
61 |
|
_destination = destination; |
62 |
|
_queue = queue; |
63 |
+ |
_queueID = queue.getQueue(); |
64 |
|
} |
65 |
|
|
66 |
|
//---PUBLIC METHODS--- |
69 |
|
* start the thread and thus gets and sends data |
70 |
|
*/ |
71 |
|
public void run() { |
48 |
– |
int n = _queue.getQueue(); |
72 |
|
String xml = null; |
73 |
< |
while(true) { |
73 |
> |
boolean run = true; |
74 |
> |
while(run) { |
75 |
> |
// get a line of XML from the queue |
76 |
|
try { |
77 |
< |
xml = (String) _queue.get(n); |
77 |
> |
xml = (String) _queue.get(_queueID); |
78 |
|
} |
79 |
|
catch (InvalidQueueException e) { |
80 |
|
_logger.write(toString(), Logger.ERROR, "Queue error: "+e); |
81 |
|
} |
82 |
< |
_destination.receiveXML(xml); |
82 |
> |
// pass it on to the destination |
83 |
> |
try { |
84 |
> |
_destination.receiveXML(xml); |
85 |
> |
} |
86 |
> |
catch (org.omg.CORBA.COMM_FAILURE e) { |
87 |
> |
run = false; |
88 |
> |
_logger.write(toString(), Logger.ERROR, "Connection failure (COMM_FAILURE), client interface shutdown? : "+e); |
89 |
> |
} |
90 |
> |
catch (org.omg.CORBA.TRANSIENT e) { |
91 |
> |
run = false; |
92 |
> |
_logger.write(toString(), Logger.ERROR, "Connection failure (TRANSIENT), client interface shutdown? : "+e); |
93 |
> |
} |
94 |
|
} |
95 |
+ |
// looks like something when wrong in communication |
96 |
+ |
// rather than fall over in a heap, lets just stop |
97 |
+ |
// cleanly and shutdown our queue... |
98 |
+ |
_logger.write(toString(), Logger.SYSMSG, "Shutting Down..."); |
99 |
+ |
_queue.removeQueue(_queueID); |
100 |
|
} |
101 |
|
|
102 |
|
/** |
103 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
104 |
|
* method to provide clean logging (every class should have this). |
105 |
|
* |
106 |
+ |
* This uses the uk.org.iscream.cms.util.NameFormat class |
107 |
+ |
* to format the toString() |
108 |
+ |
* |
109 |
|
* @return the name of this class and its CVS revision |
110 |
|
*/ |
111 |
|
public String toString() { |
112 |
< |
return this.getClass().getName() + "{" + _name + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
112 |
> |
return FormatName.getName( |
113 |
> |
_name, |
114 |
> |
getClass().getName(), |
115 |
> |
REVISION); |
116 |
|
} |
117 |
|
|
118 |
|
//---PRIVATE METHODS--- |
125 |
|
* A reference to a Queue object. |
126 |
|
*/ |
127 |
|
private Queue _queue; |
128 |
+ |
|
129 |
+ |
/** |
130 |
+ |
* Our Queue id. |
131 |
+ |
*/ |
132 |
+ |
private int _queueID; |
133 |
|
|
134 |
|
/** |
135 |
|
* the interface this thread is sending data to |