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.rootfilter; |
22 |
tdb |
1.1 |
|
23 |
|
|
//---IMPORTS--- |
24 |
tdb |
1.10 |
import uk.org.iscream.cms.server.core.*; |
25 |
|
|
import uk.org.iscream.cms.server.componentmanager.*; |
26 |
|
|
import uk.org.iscream.cms.server.clientinterface.*; |
27 |
|
|
import uk.org.iscream.cms.server.util.*; |
28 |
tdb |
1.1 |
|
29 |
|
|
/** |
30 |
|
|
* A ClientInterface wrapper - the CI objects are pushed data, |
31 |
|
|
* yet data is pulled from the queue. This will sit inbetween |
32 |
|
|
* for now, until the CI design is changed. |
33 |
|
|
* |
34 |
tdb |
1.12 |
* @author $Author: tdb $ |
35 |
tdb |
1.1 |
* @version $Id $ |
36 |
|
|
*/ |
37 |
|
|
public class CIWrapper extends Thread { |
38 |
|
|
|
39 |
|
|
//---FINAL ATTRIBUTES--- |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* The current CVS revision of this class |
43 |
|
|
*/ |
44 |
tdb |
1.12 |
public final String REVISION = "$Revision: 1.11 $"; |
45 |
tdb |
1.1 |
|
46 |
|
|
//---STATIC METHODS--- |
47 |
|
|
|
48 |
|
|
//---CONSTRUCTORS--- |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Sets up the wrapper, with a single destination and a queue. |
52 |
|
|
* |
53 |
|
|
* @param destination the client interface to send the xml to |
54 |
|
|
* @param queue a reference to a queue to use |
55 |
|
|
*/ |
56 |
|
|
public CIWrapper(ClientInterface destination, Queue queue){ |
57 |
tdb |
1.7 |
// set the Thread name |
58 |
|
|
setName("rootfilter.CIWrapper"); |
59 |
|
|
|
60 |
tdb |
1.1 |
_destination = destination; |
61 |
|
|
_queue = queue; |
62 |
tdb |
1.5 |
_queueID = queue.getQueue(); |
63 |
tdb |
1.1 |
} |
64 |
|
|
|
65 |
|
|
//---PUBLIC METHODS--- |
66 |
|
|
|
67 |
|
|
/** |
68 |
|
|
* start the thread and thus gets and sends data |
69 |
|
|
*/ |
70 |
|
|
public void run() { |
71 |
tdb |
1.3 |
String xml = null; |
72 |
tdb |
1.11 |
boolean run = true; |
73 |
|
|
while(run) { |
74 |
|
|
// get a line of XML from the queue |
75 |
tdb |
1.1 |
try { |
76 |
tdb |
1.6 |
xml = (String) _queue.get(_queueID); |
77 |
tdb |
1.1 |
} |
78 |
|
|
catch (InvalidQueueException e) { |
79 |
|
|
_logger.write(toString(), Logger.ERROR, "Queue error: "+e); |
80 |
|
|
} |
81 |
tdb |
1.11 |
// pass it on to the destination |
82 |
|
|
try { |
83 |
|
|
_destination.receiveXML(xml); |
84 |
|
|
} |
85 |
|
|
catch (org.omg.CORBA.COMM_FAILURE e) { |
86 |
|
|
run = false; |
87 |
|
|
_logger.write(toString(), Logger.ERROR, "Connection failure (COMM_FAILURE), client interface shutdown? : "+e); |
88 |
|
|
} |
89 |
|
|
catch (org.omg.CORBA.TRANSIENT e) { |
90 |
|
|
run = false; |
91 |
|
|
_logger.write(toString(), Logger.ERROR, "Connection failure (TRANSIENT), client interface shutdown? : "+e); |
92 |
|
|
} |
93 |
tdb |
1.1 |
} |
94 |
tdb |
1.11 |
// looks like something when wrong in communication |
95 |
|
|
// rather than fall over in a heap, lets just stop |
96 |
|
|
// cleanly and shutdown our queue... |
97 |
|
|
_logger.write(toString(), Logger.SYSMSG, "Shutting Down..."); |
98 |
|
|
_queue.removeQueue(_queueID); |
99 |
tdb |
1.1 |
} |
100 |
|
|
|
101 |
|
|
/** |
102 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
103 |
|
|
* method to provide clean logging (every class should have this). |
104 |
|
|
* |
105 |
tdb |
1.10 |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
106 |
tdb |
1.8 |
* to format the toString() |
107 |
|
|
* |
108 |
tdb |
1.1 |
* @return the name of this class and its CVS revision |
109 |
|
|
*/ |
110 |
|
|
public String toString() { |
111 |
tdb |
1.8 |
return FormatName.getName( |
112 |
|
|
_name, |
113 |
|
|
getClass().getName(), |
114 |
|
|
REVISION); |
115 |
tdb |
1.1 |
} |
116 |
|
|
|
117 |
|
|
//---PRIVATE METHODS--- |
118 |
|
|
|
119 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
120 |
|
|
|
121 |
|
|
//---ATTRIBUTES--- |
122 |
|
|
|
123 |
|
|
/** |
124 |
|
|
* A reference to a Queue object. |
125 |
|
|
*/ |
126 |
|
|
private Queue _queue; |
127 |
tdb |
1.5 |
|
128 |
|
|
/** |
129 |
|
|
* Our Queue id. |
130 |
|
|
*/ |
131 |
|
|
private int _queueID; |
132 |
tdb |
1.1 |
|
133 |
|
|
/** |
134 |
|
|
* the interface this thread is sending data to |
135 |
|
|
*/ |
136 |
|
|
private ClientInterface _destination; |
137 |
|
|
|
138 |
|
|
/** |
139 |
|
|
* This is the friendly identifier of the |
140 |
|
|
* component this class is running in. |
141 |
|
|
* eg, a Filter may be called "filter1", |
142 |
|
|
* If this class does not have an owning |
143 |
|
|
* component, a name from the configuration |
144 |
|
|
* can be placed here. This name could also |
145 |
|
|
* be changed to null for utility classes. |
146 |
|
|
*/ |
147 |
|
|
private String _name = RootFilter.NAME; |
148 |
|
|
|
149 |
|
|
/** |
150 |
|
|
* This holds a reference to the |
151 |
|
|
* system logger that is being used. |
152 |
|
|
*/ |
153 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
154 |
|
|
|
155 |
|
|
//---STATIC ATTRIBUTES--- |
156 |
|
|
|
157 |
|
|
} |