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.componentmanager.*; |
8 |
< |
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 |
43 |
|
*/ |
44 |
|
public void start() throws ComponentStartException { |
45 |
|
// get references to key objects |
46 |
< |
_refman = ReferenceManager.getInstance(); |
47 |
< |
_logger = ReferenceManager.getInstance().getLogger(); |
46 |
> |
_logger = _refman.getLogger(); |
47 |
|
|
48 |
|
_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; |
49 |
|
|
50 |
< |
Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME); |
51 |
< |
if (config == null) { |
52 |
< |
throw new ComponentStartException("Unable to obtain configuration for component"); |
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 |
< |
else { |
60 |
< |
try { |
61 |
< |
// get the configuration properties we need |
62 |
< |
UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort")); |
63 |
< |
TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort")); |
64 |
< |
parentFilterName = config.getProperty("Filter.parentFilter"); |
65 |
< |
queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); |
66 |
< |
} catch (org.omg.CORBA.MARSHAL e) { |
67 |
< |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
59 |
> |
|
60 |
> |
// setup a 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 |
< |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
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 |
|
|
75 |
– |
// get parent |
76 |
– |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
77 |
– |
|
78 |
– |
// setup a queue |
79 |
– |
Queue queue = new Queue(); |
80 |
– |
// startup a monitor on this queue, every minute |
81 |
– |
String queueName = NAME + " Filter"; |
82 |
– |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
83 |
– |
|
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 |
177 |
|
/** |
178 |
|
* A reference to the reference manager in use |
179 |
|
*/ |
180 |
< |
private ReferenceManager _refman; |
180 |
> |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
181 |
|
|
182 |
|
//---STATIC ATTRIBUTES--- |
183 |
|
|