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