1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
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.ac.ukc.iscream.filter; |
22 |
> |
package uk.org.iscream.cms.server.filter; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.util.*; |
26 |
< |
import uk.ac.ukc.iscream.core.*; |
27 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
28 |
< |
import uk.ac.ukc.iscream.filter.*; |
25 |
> |
import uk.org.iscream.cms.util.*; |
26 |
> |
import uk.org.iscream.cms.server.core.*; |
27 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
28 |
> |
import uk.org.iscream.cms.server.filter.*; |
29 |
|
|
30 |
|
/** |
31 |
|
* A Filter Startup Class |
63 |
|
*/ |
64 |
|
public void start() throws ComponentStartException { |
65 |
|
// get references to key objects |
66 |
< |
_refman = ReferenceManager.getInstance(); |
47 |
< |
_logger = ReferenceManager.getInstance().getLogger(); |
66 |
> |
_logger = _refman.getLogger(); |
67 |
|
|
68 |
|
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
50 |
– |
|
51 |
– |
// configuration variables we require |
52 |
– |
int UDPListenPort = 0; |
53 |
– |
int TCPListenPort = 0; |
54 |
– |
String parentFilterName = null; |
55 |
– |
int queueMonitorInterval = 0; |
69 |
|
|
70 |
< |
Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME); |
71 |
< |
if (config == null) { |
72 |
< |
throw new ComponentStartException("Unable to obtain configuration for component"); |
70 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
71 |
> |
|
72 |
> |
// which input methods do we need to activate? |
73 |
> |
// default to activating them |
74 |
> |
boolean activateTCPReader = true; |
75 |
> |
boolean activateUDPReader = true; |
76 |
> |
boolean activateCORBAReader = true; |
77 |
> |
|
78 |
> |
// check for TCP Reader |
79 |
> |
try { |
80 |
> |
int tcp = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.ActivateTCPReader")); |
81 |
> |
activateTCPReader = (tcp == 1); |
82 |
> |
} catch (PropertyNotFoundException e) { |
83 |
> |
activateTCPReader = false; |
84 |
> |
} catch (NumberFormatException e) { |
85 |
> |
activateTCPReader = false; |
86 |
|
} |
87 |
< |
else { |
87 |
> |
// check for UDP Reader |
88 |
> |
try { |
89 |
> |
int udp = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.ActivateUDPReader")); |
90 |
> |
activateUDPReader = (udp == 1); |
91 |
> |
} catch (PropertyNotFoundException e) { |
92 |
> |
activateUDPReader = false; |
93 |
> |
} catch (NumberFormatException e) { |
94 |
> |
activateUDPReader = false; |
95 |
> |
} |
96 |
> |
// check for CORBA Reader |
97 |
> |
try { |
98 |
> |
int corba = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.ActivateCORBAReader")); |
99 |
> |
activateCORBAReader = (corba == 1); |
100 |
> |
} catch (PropertyNotFoundException e) { |
101 |
> |
activateCORBAReader = false; |
102 |
> |
} catch (NumberFormatException e) { |
103 |
> |
activateCORBAReader = false; |
104 |
> |
} |
105 |
> |
|
106 |
> |
// need to use the Queue later on |
107 |
> |
Queue queue; |
108 |
> |
|
109 |
> |
// there's little point starting a Queue and a FilterThread |
110 |
> |
// if nothing is going to be giving us any data |
111 |
> |
if(activateTCPReader || activateUDPReader || activateCORBAReader) { |
112 |
> |
// see if this Queue needs a size limit |
113 |
|
try { |
114 |
< |
// get the configuration properties we need |
115 |
< |
UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort")); |
116 |
< |
TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort")); |
117 |
< |
parentFilterName = config.getProperty("Filter.parentFilter"); |
118 |
< |
queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); |
119 |
< |
} catch (org.omg.CORBA.MARSHAL e) { |
120 |
< |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
114 |
> |
int queueSizeLimit = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Queue.SizeLimit")); |
115 |
> |
String queueRemoveAlgorithm = cp.getProperty("Filter." + FilterMain.NAME, "Queue.RemoveAlgorithm"); |
116 |
> |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
117 |
> |
if(algorithm != -1) { |
118 |
> |
_logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
119 |
> |
// we have valid values, so lets start it. |
120 |
> |
queue = new Queue(queueSizeLimit, algorithm); |
121 |
> |
} |
122 |
> |
else { |
123 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
124 |
> |
// just don't activate a limit |
125 |
> |
queue = new Queue(); |
126 |
> |
} |
127 |
> |
|
128 |
> |
} catch (PropertyNotFoundException e) { |
129 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
130 |
> |
// just don't activate a limit |
131 |
> |
queue = new Queue(); |
132 |
> |
} catch (NumberFormatException e) { |
133 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
134 |
> |
// just don't activate a limit |
135 |
> |
queue = new Queue(); |
136 |
|
} |
137 |
+ |
|
138 |
+ |
// startup a monitor on this queue |
139 |
+ |
try { |
140 |
+ |
// try to get the interval, if this fails, we won't start up the monitor |
141 |
+ |
int queueMonitorInterval = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Queue.MonitorInterval")); |
142 |
+ |
String queueName = NAME + " Filter"; |
143 |
+ |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
144 |
+ |
} catch (PropertyNotFoundException e) { |
145 |
+ |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
// Start a filter thread |
149 |
+ |
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
150 |
+ |
FilterThread filterThread = new FilterThread(queue); |
151 |
+ |
filterThread.start(); |
152 |
|
} |
153 |
+ |
else { |
154 |
+ |
// it's pointless carrying on really... |
155 |
+ |
throw new ComponentStartException("Can't start Filter without any inbound data feeds"); |
156 |
+ |
} |
157 |
|
|
158 |
< |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
158 |
> |
// the corba listener needs these to be set, so lets |
159 |
> |
// make them something obviously invalid initially |
160 |
> |
int TCPListenPort = -1; |
161 |
> |
int UDPListenPort = -1; |
162 |
|
|
163 |
< |
// get parent |
164 |
< |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
163 |
> |
// TCP Reader start (for heartbeats) |
164 |
> |
if(activateTCPReader) { |
165 |
> |
try { |
166 |
> |
// get the port number from the configuration |
167 |
> |
TCPListenPort = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.TCPListenPort")); |
168 |
> |
// start the TCPReader |
169 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener"); |
170 |
> |
TCPReader tcpReader = new TCPReader(TCPListenPort, queue); |
171 |
> |
tcpReader.start(); |
172 |
> |
} catch (PropertyNotFoundException e) { |
173 |
> |
_logger.write(toString(), Logger.WARNING, "Unable to start TCPReader due to missing configuration: " + e); |
174 |
> |
} catch (NumberFormatException e) { |
175 |
> |
_logger.write(toString(), Logger.WARNING, "Unable to start TCPReader due to invalid configuration: " + e); |
176 |
> |
} |
177 |
> |
} |
178 |
|
|
179 |
< |
// setup a queue |
180 |
< |
Queue queue = new Queue(); |
181 |
< |
// startup a monitor on this queue, every minute |
182 |
< |
String queueName = NAME + " Filter"; |
183 |
< |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
179 |
> |
// UDP Reader start (for inbound host data) |
180 |
> |
if(activateUDPReader) { |
181 |
> |
try { |
182 |
> |
// get the port number from the configuration |
183 |
> |
UDPListenPort = Integer.parseInt(cp.getProperty("Filter." + FilterMain.NAME, "Filter.UDPListenPort")); |
184 |
> |
// start the UDPReader |
185 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
186 |
> |
UDPReader udpReader = new UDPReader(UDPListenPort, queue); |
187 |
> |
udpReader.start(); |
188 |
> |
} catch (PropertyNotFoundException e) { |
189 |
> |
_logger.write(toString(), Logger.WARNING, "Unable to start UDPReader due to missing configuration: " + e); |
190 |
> |
} catch (NumberFormatException e) { |
191 |
> |
_logger.write(toString(), Logger.WARNING, "Unable to start UDPReader due to invalid configuration: " + e); |
192 |
> |
} |
193 |
> |
} |
194 |
|
|
84 |
– |
// Start a filter thread |
85 |
– |
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
86 |
– |
FilterThread filterThread = new FilterThread(queue, parentFilter); |
87 |
– |
filterThread.start(); |
88 |
– |
|
195 |
|
// FilterServant start (for inbound child filter data) |
196 |
< |
_logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
197 |
< |
FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue); |
198 |
< |
_refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME); |
199 |
< |
|
200 |
< |
// UDL Reader start (for inbound host data) |
201 |
< |
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
96 |
< |
UDPReader udpReader = new UDPReader(UDPListenPort, queue); |
97 |
< |
udpReader.start(); |
98 |
< |
|
99 |
< |
// TCP Reader start (for heartbeats) |
100 |
< |
_logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener"); |
101 |
< |
TCPReader tcpReader = new TCPReader(TCPListenPort, queue); |
102 |
< |
tcpReader.start(); |
196 |
> |
if(activateCORBAReader) { |
197 |
> |
// start the FilterServant |
198 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Servant to listen for downstream filters"); |
199 |
> |
FilterServant filterServant = new FilterServant(queue); |
200 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter\\." + FilterMain.NAME); |
201 |
> |
} |
202 |
|
|
203 |
+ |
// FilterInfoServant start (to provide filter information to the server) |
204 |
+ |
_logger.write(toString(), Logger.SYSINIT, "starting Servant to provide filter information"); |
205 |
+ |
FilterInfoServant filterInfoServant = new FilterInfoServant(TCPListenPort, UDPListenPort); |
206 |
+ |
_refman.bindToOrb(filterInfoServant, "iscream.FilterInfo\\." + FilterMain.NAME); |
207 |
+ |
|
208 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
209 |
|
} |
210 |
< |
|
210 |
> |
|
211 |
|
/** |
212 |
+ |
* Does a dependency check. Used mainly at startup to |
213 |
+ |
* see if the required dependencies (components) are up |
214 |
+ |
* and running. |
215 |
+ |
* |
216 |
+ |
* @return a boolean value, true if the depdencies are satisfied |
217 |
+ |
*/ |
218 |
+ |
public boolean depCheck() { |
219 |
+ |
try { |
220 |
+ |
org.omg.CORBA.Object obj; |
221 |
+ |
// first check the ConfigurationManager is alive |
222 |
+ |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
223 |
+ |
// then suss out our parent filter |
224 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
225 |
+ |
String parentFilterName = cp.getProperty("Filter." + FilterMain.NAME, "Filter.parentFilter"); |
226 |
+ |
// finally check the parent filter is alive |
227 |
+ |
obj = _refman.getCORBARef("iscream.Filter\\." + parentFilterName); |
228 |
+ |
} catch(ComponentCORBAException e) { |
229 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
230 |
+ |
return false; |
231 |
+ |
} catch(PropertyNotFoundException e) { |
232 |
+ |
System.err.println(toString() + ": Unable to obtain configuration: "+e); |
233 |
+ |
return false; |
234 |
+ |
} |
235 |
+ |
// dependency check suceeded |
236 |
+ |
return true; |
237 |
+ |
} |
238 |
+ |
|
239 |
+ |
/** |
240 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
241 |
|
* method to provide clean logging (every class should have this). |
242 |
|
* |
243 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
243 |
> |
* This uses the uk.org.iscream.cms.util.NameFormat class |
244 |
|
* to format the toString() |
245 |
|
* |
246 |
|
* @return the name of this class and its CVS revision |
267 |
|
/** |
268 |
|
* A reference to the reference manager in use |
269 |
|
*/ |
270 |
< |
private ReferenceManager _refman; |
270 |
> |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
271 |
|
|
272 |
|
//---STATIC ATTRIBUTES--- |
273 |
|
|