1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.org.iscream.client.alerters; |
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 Alert feed to the WebFeeder |
12 |
* |
13 |
* @author $Author: tdb1 $ |
14 |
* @version $Id: WebFeeder__Alerter.java,v 1.4 2001/03/22 00:05:29 tdb1 Exp $ |
15 |
*/ |
16 |
public class WebFeeder__Alerter extends Thread implements PluginAlerter { |
17 |
|
18 |
//---FINAL ATTRIBUTES--- |
19 |
|
20 |
/** |
21 |
* The current CVS revision of this class |
22 |
*/ |
23 |
public static final String REVISION = "$Revision: 1.4 $"; |
24 |
|
25 |
public static final String DESC = "Provides a feed to WebFeeder"; |
26 |
|
27 |
public final String DEFAULT_LEVEL = Alert.alertLevels[0]; |
28 |
|
29 |
//---STATIC METHODS--- |
30 |
|
31 |
//---CONSTRUCTORS--- |
32 |
|
33 |
public WebFeeder__Alerter() { |
34 |
_webFeeder = WebFeeder.getInstance(); |
35 |
this.start(); |
36 |
} |
37 |
|
38 |
//---PUBLIC METHODS--- |
39 |
|
40 |
public void run() { |
41 |
while(_running) { |
42 |
try { |
43 |
sendAlert((Alert) getQueue().get(getQueueId())); |
44 |
} catch (InvalidQueueException e) { |
45 |
_logger.write(this.toString(), Logger.ERROR, "Unable to get queue."); |
46 |
} |
47 |
} |
48 |
} |
49 |
|
50 |
public void sendAlert(Alert alert) { |
51 |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
52 |
String levelName; |
53 |
try { |
54 |
levelName = cp.getProperty(_name, "WebFeeder.alertLevel"); |
55 |
} catch (PropertyNotFoundException e) { |
56 |
levelName = DEFAULT_LEVEL; |
57 |
_logger.write(toString(), Logger.WARNING, "WebFeeder.alertLevel value unavailable using default of " + levelName); |
58 |
} |
59 |
int level = StringUtils.getStringPos(levelName, Alert.alertLevels); |
60 |
// only send if it's equal (or above) our level |
61 |
if(((alert.getLevel() == 0) && (alert.getLastLevel() >= level)) || (alert.getLevel() >= level)) { |
62 |
try { |
63 |
ConfigurationProxy.getInstance().getProperty("WebFeeder", "WebFeeder.alertActive"); |
64 |
_webFeeder.receiveAlert(alert); |
65 |
} catch (PropertyNotFoundException e) { |
66 |
// we don't care, this means we shouldn't be active |
67 |
} |
68 |
} |
69 |
} |
70 |
|
71 |
public String getDescription() { |
72 |
return DESC; |
73 |
} |
74 |
|
75 |
/** |
76 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
77 |
* method to provide clean logging (every class should have this). |
78 |
* |
79 |
* This uses the uk.org.iscream.util.FormatName class |
80 |
* to format the toString() |
81 |
* |
82 |
* @return the name of this class and its CVS revision |
83 |
*/ |
84 |
public String toString() { |
85 |
return FormatName.getName( |
86 |
_name, |
87 |
getClass().getName(), |
88 |
REVISION); |
89 |
} |
90 |
|
91 |
//---PRIVATE METHODS--- |
92 |
|
93 |
//---ACCESSOR/MUTATOR METHODS--- |
94 |
|
95 |
protected Queue getQueue() { |
96 |
return AlerterManager.getInstance().getQueue(); |
97 |
} |
98 |
|
99 |
protected int getQueueId() { |
100 |
if (_qID == -1) { |
101 |
_qID = getQueue().getQueue(); |
102 |
_logger.write(toString(), Logger.DEBUG, "Assigned Queue - " + _qID); |
103 |
} |
104 |
return _qID; |
105 |
} |
106 |
|
107 |
//---ATTRIBUTES--- |
108 |
|
109 |
/** |
110 |
* A reference to the WebFeeder |
111 |
*/ |
112 |
private WebFeeder _webFeeder; |
113 |
|
114 |
/** |
115 |
* This is the friendly identifier of the |
116 |
* component this class is running in. |
117 |
* eg, a Filter may be called "filter1", |
118 |
* If this class does not have an owning |
119 |
* component, a name from the configuration |
120 |
* can be placed here. This name could also |
121 |
* be changed to null for utility classes. |
122 |
*/ |
123 |
private String _name = "WebFeeder"; |
124 |
|
125 |
/** |
126 |
* This holds a reference to the |
127 |
* system logger that is being used. |
128 |
*/ |
129 |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
130 |
|
131 |
/** |
132 |
* The queue id for this alerters queue in the alert queue |
133 |
*/ |
134 |
private int _qID = -1; |
135 |
|
136 |
/** |
137 |
* The running status of the alerter |
138 |
*/ |
139 |
private boolean _running = true; |
140 |
|
141 |
//---STATIC ATTRIBUTES--- |
142 |
|
143 |
} |