1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.7 |
package uk.org.iscream.cms.server.client.monitors; |
3 |
tdb |
1.1 |
|
4 |
|
|
//---IMPORTS--- |
5 |
tdb |
1.7 |
import uk.org.iscream.cms.server.client.*; |
6 |
|
|
import uk.org.iscream.cms.server.core.*; |
7 |
|
|
import uk.org.iscream.cms.server.util.*; |
8 |
|
|
import uk.org.iscream.cms.server.componentmanager.*; |
9 |
tdb |
1.1 |
|
10 |
|
|
/** |
11 |
|
|
* Provides a full XMLPacket feed to the WebFeeder |
12 |
|
|
* |
13 |
tdb |
1.7 |
* @author $Author: tdb1 $ |
14 |
|
|
* @version $Id: WebFeeder__Monitor.java,v 1.6 2001/03/23 02:25:15 tdb1 Exp $ |
15 |
tdb |
1.1 |
*/ |
16 |
ajm |
1.4 |
public class WebFeeder__Monitor extends Thread implements PluginMonitor { |
17 |
tdb |
1.1 |
|
18 |
|
|
//---FINAL ATTRIBUTES--- |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* The current CVS revision of this class |
22 |
|
|
*/ |
23 |
tdb |
1.7 |
public static final String REVISION = "$Revision: 1.6 $"; |
24 |
tdb |
1.1 |
|
25 |
tdb |
1.6 |
/** |
26 |
|
|
* A description of this monitor |
27 |
|
|
*/ |
28 |
tdb |
1.1 |
public static final String DESC = "Provides a feed to WebFeeder"; |
29 |
|
|
|
30 |
|
|
//---STATIC METHODS--- |
31 |
|
|
|
32 |
|
|
//---CONSTRUCTORS--- |
33 |
tdb |
1.6 |
|
34 |
|
|
/** |
35 |
|
|
* Constructs a new instance of this hook for the WebFeeder. |
36 |
|
|
*/ |
37 |
tdb |
1.1 |
public WebFeeder__Monitor() { |
38 |
ajm |
1.4 |
this.start(); |
39 |
tdb |
1.1 |
} |
40 |
|
|
|
41 |
|
|
//---PUBLIC METHODS--- |
42 |
tdb |
1.6 |
|
43 |
|
|
/** |
44 |
|
|
* Keeps getting packets from the queue, and analyses |
45 |
|
|
* them. In reality, this just sends them off to the |
46 |
|
|
* WebFeeder for further processing. |
47 |
|
|
*/ |
48 |
ajm |
1.4 |
public void run() { |
49 |
ajm |
1.5 |
while(_running) { |
50 |
|
|
try { |
51 |
|
|
analysePacket((XMLPacket) getQueue().get(getQueueId())); |
52 |
|
|
} catch (InvalidQueueException e) { |
53 |
|
|
_logger.write(this.toString(), Logger.ERROR, "Unable to get queue."); |
54 |
|
|
} |
55 |
ajm |
1.4 |
} |
56 |
|
|
} |
57 |
tdb |
1.6 |
|
58 |
|
|
/** |
59 |
|
|
* Sends a packet to the WebFeeder for processing, if |
60 |
|
|
* we are active. |
61 |
|
|
* |
62 |
|
|
* @param packet the XMLPacket to send to the WebFeeder |
63 |
|
|
*/ |
64 |
tdb |
1.1 |
public void analysePacket(XMLPacket packet) { |
65 |
tdb |
1.2 |
try { |
66 |
|
|
ConfigurationProxy.getInstance().getProperty("WebFeeder", "WebFeeder.latestActive"); |
67 |
tdb |
1.6 |
WebFeeder.getInstance().receiveXMLPacket(packet); |
68 |
tdb |
1.2 |
} catch (PropertyNotFoundException e) { |
69 |
|
|
// we don't care, this means we shouldn't be active |
70 |
|
|
} |
71 |
tdb |
1.1 |
} |
72 |
tdb |
1.6 |
|
73 |
|
|
/** |
74 |
|
|
* return the String representation of what the monitor does |
75 |
|
|
*/ |
76 |
tdb |
1.1 |
public String getDescription() { |
77 |
|
|
return DESC; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
82 |
|
|
* method to provide clean logging (every class should have this). |
83 |
|
|
* |
84 |
tdb |
1.7 |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
85 |
tdb |
1.1 |
* to format the toString() |
86 |
|
|
* |
87 |
|
|
* @return the name of this class and its CVS revision |
88 |
|
|
*/ |
89 |
|
|
public String toString() { |
90 |
|
|
return FormatName.getName( |
91 |
|
|
_name, |
92 |
|
|
getClass().getName(), |
93 |
|
|
REVISION); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
//---PRIVATE METHODS--- |
97 |
|
|
|
98 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
99 |
tdb |
1.6 |
|
100 |
|
|
/** |
101 |
|
|
* Returns a reference to a specific Queue for this |
102 |
|
|
* monitor. This Queue returns only the data packets |
103 |
|
|
* (based on type) that we want too look at. |
104 |
|
|
* |
105 |
|
|
* @return a reference to a Queue |
106 |
|
|
*/ |
107 |
ajm |
1.4 |
protected Queue getQueue() { |
108 |
|
|
return MonitorManager.getInstance().getAllQueue(); |
109 |
|
|
} |
110 |
tdb |
1.6 |
|
111 |
|
|
/** |
112 |
|
|
* Gets us a queue within the Queue we're using. |
113 |
|
|
* |
114 |
|
|
* @return a unique queue id number |
115 |
|
|
*/ |
116 |
ajm |
1.4 |
protected int getQueueId() { |
117 |
|
|
if (_qID == -1) { |
118 |
|
|
_qID = getQueue().getQueue(); |
119 |
|
|
} |
120 |
|
|
return _qID; |
121 |
|
|
} |
122 |
tdb |
1.6 |
|
123 |
tdb |
1.1 |
//---ATTRIBUTES--- |
124 |
|
|
|
125 |
|
|
/** |
126 |
|
|
* This is the friendly identifier of the |
127 |
|
|
* component this class is running in. |
128 |
|
|
* eg, a Filter may be called "filter1", |
129 |
|
|
* If this class does not have an owning |
130 |
|
|
* component, a name from the configuration |
131 |
|
|
* can be placed here. This name could also |
132 |
|
|
* be changed to null for utility classes. |
133 |
|
|
*/ |
134 |
|
|
private String _name = "WebFeeder"; |
135 |
|
|
|
136 |
|
|
/** |
137 |
|
|
* This holds a reference to the |
138 |
|
|
* system logger that is being used. |
139 |
|
|
*/ |
140 |
|
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
141 |
ajm |
1.4 |
|
142 |
tdb |
1.6 |
/** |
143 |
|
|
* Holds our queue ID number. Starts with -1, which |
144 |
|
|
* indicates we don't have a queue. |
145 |
|
|
*/ |
146 |
ajm |
1.4 |
protected int _qID = -1; |
147 |
ajm |
1.5 |
|
148 |
tdb |
1.6 |
/** |
149 |
|
|
* A flag so we can stop if required. |
150 |
|
|
*/ |
151 |
ajm |
1.5 |
protected boolean _running = true; |
152 |
tdb |
1.1 |
|
153 |
|
|
//---STATIC ATTRIBUTES--- |
154 |
|
|
|
155 |
|
|
} |