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