1 |
tdb |
1.35 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
tdb |
1.36 |
* http://www.i-scream.org.uk |
4 |
tdb |
1.35 |
* 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.31 |
package uk.org.iscream.cms.server.filter; |
23 |
tdb |
1.1 |
|
24 |
|
|
//---IMPORTS--- |
25 |
tdb |
1.38 |
import uk.org.iscream.cms.util.*; |
26 |
tdb |
1.31 |
import uk.org.iscream.cms.server.core.*; |
27 |
|
|
import uk.org.iscream.cms.server.componentmanager.*; |
28 |
|
|
import uk.org.iscream.cms.server.filter.*; |
29 |
tdb |
1.1 |
|
30 |
|
|
/** |
31 |
|
|
* A Filter Startup Class |
32 |
ajm |
1.16 |
* A filter is an iscream component. |
33 |
tdb |
1.1 |
* |
34 |
tdb |
1.32 |
* @author $Author: tdb $ |
35 |
tdb |
1.39 |
* @version $Id: FilterMain.java,v 1.38 2003/02/05 16:43:47 tdb Exp $ |
36 |
tdb |
1.1 |
*/ |
37 |
tdb |
1.19 |
public class FilterMain implements Component { |
38 |
tdb |
1.1 |
|
39 |
|
|
//---FINAL ATTRIBUTES--- |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* The current CVS revision of this class |
43 |
|
|
*/ |
44 |
tdb |
1.39 |
public static final String REVISION = "$Revision: 1.38 $"; |
45 |
tdb |
1.1 |
|
46 |
|
|
//---STATIC METHODS--- |
47 |
|
|
|
48 |
ajm |
1.16 |
//---CONSTRUCTORS--- |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Constructs a Filter with the name given |
52 |
|
|
* |
53 |
|
|
* @param givenName the name |
54 |
|
|
*/ |
55 |
|
|
public FilterMain(String givenName) { |
56 |
|
|
NAME = givenName; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
//---PUBLIC METHODS--- |
60 |
|
|
|
61 |
|
|
/** |
62 |
|
|
* Starts the Filter component |
63 |
|
|
*/ |
64 |
|
|
public void start() throws ComponentStartException { |
65 |
ajm |
1.24 |
// get references to key objects |
66 |
tdb |
1.27 |
_logger = _refman.getLogger(); |
67 |
ajm |
1.24 |
|
68 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
69 |
tdb |
1.20 |
|
70 |
tdb |
1.25 |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
71 |
ajm |
1.16 |
|
72 |
tdb |
1.32 |
// which input methods do we need to activate? |
73 |
|
|
// default to activating them |
74 |
|
|
boolean activateUDPReader = true; |
75 |
|
|
boolean activateCORBAReader = true; |
76 |
|
|
|
77 |
|
|
// check for UDP Reader |
78 |
|
|
try { |
79 |
tdb |
1.33 |
int udp = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.ActivateUDPReader")); |
80 |
tdb |
1.32 |
activateUDPReader = (udp == 1); |
81 |
|
|
} catch (PropertyNotFoundException e) { |
82 |
|
|
activateUDPReader = false; |
83 |
|
|
} catch (NumberFormatException e) { |
84 |
|
|
activateUDPReader = false; |
85 |
|
|
} |
86 |
|
|
// check for CORBA Reader |
87 |
tdb |
1.25 |
try { |
88 |
tdb |
1.33 |
int corba = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.ActivateCORBAReader")); |
89 |
tdb |
1.32 |
activateCORBAReader = (corba == 1); |
90 |
tdb |
1.25 |
} catch (PropertyNotFoundException e) { |
91 |
tdb |
1.32 |
activateCORBAReader = false; |
92 |
|
|
} catch (NumberFormatException e) { |
93 |
|
|
activateCORBAReader = false; |
94 |
tdb |
1.25 |
} |
95 |
ajm |
1.13 |
|
96 |
tdb |
1.32 |
// need to use the Queue later on |
97 |
tdb |
1.30 |
Queue queue; |
98 |
tdb |
1.32 |
|
99 |
|
|
// there's little point starting a Queue and a FilterThread |
100 |
|
|
// if nothing is going to be giving us any data |
101 |
tdb |
1.39 |
if(activateUDPReader || activateCORBAReader) { |
102 |
tdb |
1.32 |
// see if this Queue needs a size limit |
103 |
|
|
try { |
104 |
tdb |
1.33 |
int queueSizeLimit = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Queue.SizeLimit")); |
105 |
|
|
String queueRemoveAlgorithm = cp.getProperty("Filter." + FilterMain.NAME, "Queue.RemoveAlgorithm"); |
106 |
tdb |
1.32 |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
107 |
|
|
if(algorithm != -1) { |
108 |
|
|
_logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
109 |
|
|
// we have valid values, so lets start it. |
110 |
|
|
queue = new Queue(queueSizeLimit, algorithm); |
111 |
|
|
} |
112 |
|
|
else { |
113 |
|
|
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
114 |
|
|
// just don't activate a limit |
115 |
|
|
queue = new Queue(); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
} catch (PropertyNotFoundException e) { |
119 |
|
|
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
120 |
|
|
// just don't activate a limit |
121 |
|
|
queue = new Queue(); |
122 |
|
|
} catch (NumberFormatException e) { |
123 |
|
|
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
124 |
tdb |
1.30 |
// just don't activate a limit |
125 |
|
|
queue = new Queue(); |
126 |
|
|
} |
127 |
|
|
|
128 |
tdb |
1.32 |
// startup a monitor on this queue |
129 |
|
|
try { |
130 |
|
|
// try to get the interval, if this fails, we won't start up the monitor |
131 |
tdb |
1.33 |
int queueMonitorInterval = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Queue.MonitorInterval")); |
132 |
tdb |
1.32 |
String queueName = NAME + " Filter"; |
133 |
|
|
queue.startMonitor(queueMonitorInterval*1000, queueName); |
134 |
|
|
} catch (PropertyNotFoundException e) { |
135 |
|
|
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
// Start a filter thread |
139 |
|
|
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
140 |
|
|
FilterThread filterThread = new FilterThread(queue); |
141 |
|
|
filterThread.start(); |
142 |
|
|
} |
143 |
|
|
else { |
144 |
|
|
// it's pointless carrying on really... |
145 |
|
|
throw new ComponentStartException("Can't start Filter without any inbound data feeds"); |
146 |
tdb |
1.30 |
} |
147 |
tdb |
1.25 |
|
148 |
tdb |
1.32 |
// the corba listener needs these to be set, so lets |
149 |
|
|
// make them something obviously invalid initially |
150 |
|
|
int UDPListenPort = -1; |
151 |
|
|
|
152 |
|
|
// UDP Reader start (for inbound host data) |
153 |
|
|
if(activateUDPReader) { |
154 |
|
|
try { |
155 |
|
|
// get the port number from the configuration |
156 |
tdb |
1.33 |
UDPListenPort = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.UDPListenPort")); |
157 |
tdb |
1.32 |
// start the UDPReader |
158 |
|
|
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
159 |
|
|
UDPReader udpReader = new UDPReader(UDPListenPort, queue); |
160 |
|
|
udpReader.start(); |
161 |
|
|
} catch (PropertyNotFoundException e) { |
162 |
|
|
_logger.write(toString(), Logger.WARNING, "Unable to start UDPReader due to missing configuration: " + e); |
163 |
|
|
} catch (NumberFormatException e) { |
164 |
|
|
_logger.write(toString(), Logger.WARNING, "Unable to start UDPReader due to invalid configuration: " + e); |
165 |
|
|
} |
166 |
|
|
} |
167 |
tdb |
1.18 |
|
168 |
ajm |
1.13 |
// FilterServant start (for inbound child filter data) |
169 |
tdb |
1.32 |
if(activateCORBAReader) { |
170 |
|
|
// start the FilterServant |
171 |
|
|
_logger.write(toString(), Logger.SYSINIT, "starting Servant to listen for downstream filters"); |
172 |
tdb |
1.34 |
FilterServant filterServant = new FilterServant(queue); |
173 |
tdb |
1.37 |
_refman.bindToOrb(filterServant, "iscream.Filter\\." + FilterMain.NAME); |
174 |
tdb |
1.32 |
} |
175 |
tdb |
1.34 |
|
176 |
|
|
// FilterInfoServant start (to provide filter information to the server) |
177 |
|
|
_logger.write(toString(), Logger.SYSINIT, "starting Servant to provide filter information"); |
178 |
tdb |
1.39 |
FilterInfoServant filterInfoServant = new FilterInfoServant(UDPListenPort); |
179 |
tdb |
1.37 |
_refman.bindToOrb(filterInfoServant, "iscream.FilterInfo\\." + FilterMain.NAME); |
180 |
ajm |
1.13 |
|
181 |
ajm |
1.16 |
_logger.write(toString(), Logger.SYSINIT, "started"); |
182 |
tdb |
1.1 |
} |
183 |
tdb |
1.26 |
|
184 |
|
|
/** |
185 |
|
|
* Does a dependency check. Used mainly at startup to |
186 |
|
|
* see if the required dependencies (components) are up |
187 |
|
|
* and running. |
188 |
|
|
* |
189 |
|
|
* @return a boolean value, true if the depdencies are satisfied |
190 |
|
|
*/ |
191 |
|
|
public boolean depCheck() { |
192 |
|
|
try { |
193 |
|
|
org.omg.CORBA.Object obj; |
194 |
|
|
// first check the ConfigurationManager is alive |
195 |
|
|
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
196 |
|
|
// then suss out our parent filter |
197 |
|
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
198 |
tdb |
1.33 |
String parentFilterName = cp.getProperty("Filter." + FilterMain.NAME, "Filter.parentFilter"); |
199 |
tdb |
1.26 |
// finally check the parent filter is alive |
200 |
tdb |
1.37 |
obj = _refman.getCORBARef("iscream.Filter\\." + parentFilterName); |
201 |
tdb |
1.26 |
} catch(ComponentCORBAException e) { |
202 |
tdb |
1.28 |
System.err.println(toString() + ": Dependency Failure: "+e); |
203 |
tdb |
1.26 |
return false; |
204 |
|
|
} catch(PropertyNotFoundException e) { |
205 |
tdb |
1.28 |
System.err.println(toString() + ": Unable to obtain configuration: "+e); |
206 |
tdb |
1.26 |
return false; |
207 |
|
|
} |
208 |
|
|
// dependency check suceeded |
209 |
|
|
return true; |
210 |
|
|
} |
211 |
|
|
|
212 |
ajm |
1.16 |
/** |
213 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
214 |
|
|
* method to provide clean logging (every class should have this). |
215 |
|
|
* |
216 |
tdb |
1.38 |
* This uses the uk.org.iscream.cms.util.NameFormat class |
217 |
ajm |
1.16 |
* to format the toString() |
218 |
|
|
* |
219 |
|
|
* @return the name of this class and its CVS revision |
220 |
|
|
*/ |
221 |
|
|
public String toString() { |
222 |
|
|
return FormatName.getName( |
223 |
ajm |
1.17 |
NAME, |
224 |
ajm |
1.16 |
getClass().getName(), |
225 |
|
|
REVISION); |
226 |
tdb |
1.1 |
} |
227 |
|
|
|
228 |
|
|
//---PRIVATE METHODS--- |
229 |
|
|
|
230 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
231 |
|
|
|
232 |
|
|
//---ATTRIBUTES--- |
233 |
ajm |
1.16 |
|
234 |
|
|
/** |
235 |
|
|
* This holds a reference to the |
236 |
|
|
* system logger that is being used. |
237 |
|
|
*/ |
238 |
ajm |
1.24 |
private Logger _logger; |
239 |
ajm |
1.16 |
|
240 |
|
|
/** |
241 |
|
|
* A reference to the reference manager in use |
242 |
|
|
*/ |
243 |
tdb |
1.27 |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
244 |
ajm |
1.16 |
|
245 |
tdb |
1.1 |
//---STATIC ATTRIBUTES--- |
246 |
ajm |
1.16 |
|
247 |
|
|
/** |
248 |
|
|
* The friendly name for this component, used by |
249 |
|
|
* all related classes. |
250 |
|
|
* This is set from the configuration. |
251 |
|
|
*/ |
252 |
|
|
public static String NAME; |
253 |
tdb |
1.1 |
|
254 |
tdb |
1.21 |
} |