ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/WebFeeder__Monitor.java
Revision: 1.9
Committed: Tue May 21 16:47:16 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.8: +3 -2 lines
Log Message:
Added URL to GPL headers.

File Contents

# User Rev Content
1 tdb 1.8 /*
2     * i-scream central monitoring system
3 tdb 1.9 * http://www.i-scream.org.uk
4 tdb 1.8 * 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 tdb 1.1 //---PACKAGE DECLARATION---
22 tdb 1.7 package uk.org.iscream.cms.server.client.monitors;
23 tdb 1.1
24     //---IMPORTS---
25 tdb 1.7 import uk.org.iscream.cms.server.client.*;
26     import uk.org.iscream.cms.server.core.*;
27     import uk.org.iscream.cms.server.util.*;
28     import uk.org.iscream.cms.server.componentmanager.*;
29 tdb 1.1
30     /**
31     * Provides a full XMLPacket feed to the WebFeeder
32     *
33 tdb 1.8 * @author $Author: tdb $
34 tdb 1.9 * @version $Id: WebFeeder__Monitor.java,v 1.8 2002/05/18 18:16:00 tdb Exp $
35 tdb 1.1 */
36 ajm 1.4 public class WebFeeder__Monitor extends Thread implements PluginMonitor {
37 tdb 1.1
38     //---FINAL ATTRIBUTES---
39    
40     /**
41     * The current CVS revision of this class
42     */
43 tdb 1.9 public static final String REVISION = "$Revision: 1.8 $";
44 tdb 1.1
45 tdb 1.6 /**
46     * A description of this monitor
47     */
48 tdb 1.1 public static final String DESC = "Provides a feed to WebFeeder";
49    
50     //---STATIC METHODS---
51    
52     //---CONSTRUCTORS---
53 tdb 1.6
54     /**
55     * Constructs a new instance of this hook for the WebFeeder.
56     */
57 tdb 1.1 public WebFeeder__Monitor() {
58 ajm 1.4 this.start();
59 tdb 1.1 }
60    
61     //---PUBLIC METHODS---
62 tdb 1.6
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 ajm 1.4 public void run() {
69 ajm 1.5 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 ajm 1.4 }
76     }
77 tdb 1.6
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 tdb 1.1 public void analysePacket(XMLPacket packet) {
85 tdb 1.2 try {
86     ConfigurationProxy.getInstance().getProperty("WebFeeder", "WebFeeder.latestActive");
87 tdb 1.6 WebFeeder.getInstance().receiveXMLPacket(packet);
88 tdb 1.2 } catch (PropertyNotFoundException e) {
89     // we don't care, this means we shouldn't be active
90     }
91 tdb 1.1 }
92 tdb 1.6
93     /**
94     * return the String representation of what the monitor does
95     */
96 tdb 1.1 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 tdb 1.7 * This uses the uk.org.iscream.cms.server.util.FormatName class
105 tdb 1.1 * 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 tdb 1.6
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 ajm 1.4 protected Queue getQueue() {
128     return MonitorManager.getInstance().getAllQueue();
129     }
130 tdb 1.6
131     /**
132     * Gets us a queue within the Queue we're using.
133     *
134     * @return a unique queue id number
135     */
136 ajm 1.4 protected int getQueueId() {
137     if (_qID == -1) {
138     _qID = getQueue().getQueue();
139     }
140     return _qID;
141     }
142 tdb 1.6
143 tdb 1.1 //---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 ajm 1.4
162 tdb 1.6 /**
163     * Holds our queue ID number. Starts with -1, which
164     * indicates we don't have a queue.
165     */
166 ajm 1.4 protected int _qID = -1;
167 ajm 1.5
168 tdb 1.6 /**
169     * A flag so we can stop if required.
170     */
171 ajm 1.5 protected boolean _running = true;
172 tdb 1.1
173     //---STATIC ATTRIBUTES---
174    
175     }