1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.filter; |
2 |
> |
package uk.org.iscream.filter; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import uk.ac.ukc.iscream.core.*; |
7 |
< |
import uk.ac.ukc.iscream.filter.*; |
5 |
> |
import uk.org.iscream.util.*; |
6 |
> |
import uk.org.iscream.core.*; |
7 |
> |
import uk.org.iscream.componentmanager.*; |
8 |
> |
import uk.org.iscream.filter.*; |
9 |
|
|
10 |
|
/** |
11 |
|
* A Filter Startup Class |
14 |
|
* @author $Author$ |
15 |
|
* @version $Id$ |
16 |
|
*/ |
17 |
< |
public class FilterMain implements uk.ac.ukc.iscream.util.Component { |
17 |
> |
public class FilterMain implements Component { |
18 |
|
|
19 |
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
42 |
|
* Starts the Filter component |
43 |
|
*/ |
44 |
|
public void start() throws ComponentStartException { |
45 |
< |
|
45 |
> |
// get references to key objects |
46 |
> |
_logger = _refman.getLogger(); |
47 |
> |
|
48 |
|
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
46 |
– |
|
47 |
– |
// 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 { |
59 |
– |
try { |
60 |
– |
UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort")); |
61 |
– |
TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort")); |
62 |
– |
parentFilterName = config.getProperty("Filter.parentFilter"); |
63 |
– |
} catch (org.omg.CORBA.MARSHAL e) { |
64 |
– |
System.err.println ("CRITICAL:Unable to obtain required configuration property" + |
65 |
– |
"\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); |
68 |
– |
} |
69 |
– |
} |
70 |
– |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
49 |
|
|
50 |
< |
// get parent |
73 |
< |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
50 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
51 |
|
|
52 |
+ |
int UDPListenPort, TCPListenPort; |
53 |
+ |
try { |
54 |
+ |
UDPListenPort = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Filter.UDPListenPort")); |
55 |
+ |
TCPListenPort = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Filter.TCPListenPort")); |
56 |
+ |
} catch (PropertyNotFoundException e) { |
57 |
+ |
throw new ComponentStartException("Unable to obtain requried configuration property for component: " + e); |
58 |
+ |
} |
59 |
+ |
|
60 |
|
// setup a queue |
61 |
< |
Queue queue = new Queue(); |
61 |
> |
Queue queue; |
62 |
> |
// see if this Queue needs a size limit |
63 |
> |
try { |
64 |
> |
int queueSizeLimit = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Queue.SizeLimit")); |
65 |
> |
String queueRemoveAlgorithm = cp.getProperty(FilterMain.NAME, "Queue.RemoveAlgorithm"); |
66 |
> |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
67 |
> |
if(algorithm != -1) { |
68 |
> |
_logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
69 |
> |
// we have valid values, so lets start it. |
70 |
> |
queue = new Queue(queueSizeLimit, algorithm); |
71 |
> |
} |
72 |
> |
else { |
73 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
74 |
> |
// just don't activate a limit |
75 |
> |
queue = new Queue(); |
76 |
> |
} |
77 |
> |
|
78 |
> |
} catch (PropertyNotFoundException e) { |
79 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
80 |
> |
// just don't activate a limit |
81 |
> |
queue = new Queue(); |
82 |
> |
} catch (NumberFormatException e) { |
83 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
84 |
> |
// just don't activate a limit |
85 |
> |
queue = new Queue(); |
86 |
> |
} |
87 |
|
|
88 |
+ |
// startup a monitor on this queue |
89 |
+ |
try { |
90 |
+ |
// try to get the interval, if this fails, we won't start up the monitor |
91 |
+ |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Queue.MonitorInterval")); |
92 |
+ |
String queueName = NAME + " Filter"; |
93 |
+ |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
94 |
+ |
} catch (PropertyNotFoundException e) { |
95 |
+ |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
96 |
+ |
} |
97 |
+ |
|
98 |
|
// Start a filter thread |
99 |
|
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
100 |
< |
FilterThread filterThread = new FilterThread(queue, parentFilter); |
100 |
> |
FilterThread filterThread = new FilterThread(queue); |
101 |
|
filterThread.start(); |
102 |
|
|
103 |
|
// FilterServant start (for inbound child filter data) |
104 |
< |
_logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
104 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters"); |
105 |
|
FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue); |
106 |
|
_refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME); |
107 |
|
|
117 |
|
|
118 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
119 |
|
} |
120 |
< |
|
120 |
> |
|
121 |
|
/** |
122 |
+ |
* Does a dependency check. Used mainly at startup to |
123 |
+ |
* see if the required dependencies (components) are up |
124 |
+ |
* and running. |
125 |
+ |
* |
126 |
+ |
* @return a boolean value, true if the depdencies are satisfied |
127 |
+ |
*/ |
128 |
+ |
public boolean depCheck() { |
129 |
+ |
try { |
130 |
+ |
org.omg.CORBA.Object obj; |
131 |
+ |
// first check the ConfigurationManager is alive |
132 |
+ |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
133 |
+ |
// then suss out our parent filter |
134 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
135 |
+ |
String parentFilterName = cp.getProperty(NAME, "Filter.parentFilter"); |
136 |
+ |
// finally check the parent filter is alive |
137 |
+ |
obj = _refman.getCORBARef("iscream.Filter." + parentFilterName); |
138 |
+ |
} catch(ComponentCORBAException e) { |
139 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
140 |
+ |
return false; |
141 |
+ |
} catch(PropertyNotFoundException e) { |
142 |
+ |
System.err.println(toString() + ": Unable to obtain configuration: "+e); |
143 |
+ |
return false; |
144 |
+ |
} |
145 |
+ |
// dependency check suceeded |
146 |
+ |
return true; |
147 |
+ |
} |
148 |
+ |
|
149 |
+ |
/** |
150 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
151 |
|
* method to provide clean logging (every class should have this). |
152 |
|
* |
153 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
153 |
> |
* This uses the uk.org.iscream.util.NameFormat class |
154 |
|
* to format the toString() |
155 |
|
* |
156 |
|
* @return the name of this class and its CVS revision |
172 |
|
* This holds a reference to the |
173 |
|
* system logger that is being used. |
174 |
|
*/ |
175 |
< |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
175 |
> |
private Logger _logger; |
176 |
|
|
177 |
|
/** |
178 |
|
* A reference to the reference manager in use |
188 |
|
*/ |
189 |
|
public static String NAME; |
190 |
|
|
191 |
< |
} |
191 |
> |
} |