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