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