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