1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.org.iscream.client.monitors; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.org.iscream.client.*; |
6 |
import uk.org.iscream.core.*; |
7 |
import uk.org.iscream.util.*; |
8 |
import uk.org.iscream.componentmanager.*; |
9 |
|
10 |
/** |
11 |
* Provides a full XMLPacket feed to the WebFeeder |
12 |
* |
13 |
* @author $Author: ajm4 $ |
14 |
* @version $Id: WebFeeder__Monitor.java,v 1.5 2001/03/22 18:28:24 ajm4 Exp $ |
15 |
*/ |
16 |
public class WebFeeder__Monitor extends Thread implements PluginMonitor { |
17 |
|
18 |
//---FINAL ATTRIBUTES--- |
19 |
|
20 |
/** |
21 |
* The current CVS revision of this class |
22 |
*/ |
23 |
public static final String REVISION = "$Revision: 1.5 $"; |
24 |
|
25 |
/** |
26 |
* A description of this monitor |
27 |
*/ |
28 |
public static final String DESC = "Provides a feed to WebFeeder"; |
29 |
|
30 |
//---STATIC METHODS--- |
31 |
|
32 |
//---CONSTRUCTORS--- |
33 |
|
34 |
/** |
35 |
* Constructs a new instance of this hook for the WebFeeder. |
36 |
*/ |
37 |
public WebFeeder__Monitor() { |
38 |
this.start(); |
39 |
} |
40 |
|
41 |
//---PUBLIC METHODS--- |
42 |
|
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 |
public void run() { |
49 |
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 |
} |
56 |
} |
57 |
|
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 |
public void analysePacket(XMLPacket packet) { |
65 |
try { |
66 |
ConfigurationProxy.getInstance().getProperty("WebFeeder", "WebFeeder.latestActive"); |
67 |
WebFeeder.getInstance().receiveXMLPacket(packet); |
68 |
} catch (PropertyNotFoundException e) { |
69 |
// we don't care, this means we shouldn't be active |
70 |
} |
71 |
} |
72 |
|
73 |
/** |
74 |
* return the String representation of what the monitor does |
75 |
*/ |
76 |
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 |
* This uses the uk.org.iscream.util.FormatName class |
85 |
* 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 |
|
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 |
protected Queue getQueue() { |
108 |
return MonitorManager.getInstance().getAllQueue(); |
109 |
} |
110 |
|
111 |
/** |
112 |
* Gets us a queue within the Queue we're using. |
113 |
* |
114 |
* @return a unique queue id number |
115 |
*/ |
116 |
protected int getQueueId() { |
117 |
if (_qID == -1) { |
118 |
_qID = getQueue().getQueue(); |
119 |
} |
120 |
return _qID; |
121 |
} |
122 |
|
123 |
//---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 |
|
142 |
/** |
143 |
* Holds our queue ID number. Starts with -1, which |
144 |
* indicates we don't have a queue. |
145 |
*/ |
146 |
protected int _qID = -1; |
147 |
|
148 |
/** |
149 |
* A flag so we can stop if required. |
150 |
*/ |
151 |
protected boolean _running = true; |
152 |
|
153 |
//---STATIC ATTRIBUTES--- |
154 |
|
155 |
} |