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 |
|
} |
61 |
– |
else { |
62 |
– |
try { |
63 |
– |
// get the configuration properties we need |
64 |
– |
UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort")); |
65 |
– |
TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort")); |
66 |
– |
parentFilterName = config.getProperty("Filter.parentFilter"); |
67 |
– |
queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); |
68 |
– |
} catch (org.omg.CORBA.MARSHAL e) { |
69 |
– |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
70 |
– |
} |
71 |
– |
} |
59 |
|
|
73 |
– |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
74 |
– |
|
75 |
– |
// get parent |
76 |
– |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
77 |
– |
|
60 |
|
// setup a queue |
61 |
|
Queue queue = new Queue(); |
80 |
– |
// startup a monitor on this queue, every minute |
81 |
– |
String queueName = NAME + " Filter"; |
82 |
– |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
62 |
|
|
63 |
+ |
// startup a monitor on this queue |
64 |
+ |
try { |
65 |
+ |
// try to get the interval, if this fails, we won't start up the monitor |
66 |
+ |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(FilterMain.NAME, "Queue.MonitorInterval")); |
67 |
+ |
String queueName = NAME + " Filter"; |
68 |
+ |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
69 |
+ |
} catch (PropertyNotFoundException e) { |
70 |
+ |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
71 |
+ |
} |
72 |
+ |
|
73 |
|
// Start a filter thread |
74 |
|
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
75 |
< |
FilterThread filterThread = new FilterThread(queue, parentFilter); |
75 |
> |
FilterThread filterThread = new FilterThread(queue); |
76 |
|
filterThread.start(); |
77 |
|
|
78 |
|
// FilterServant start (for inbound child filter data) |
79 |
< |
_logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
79 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Servant to listen for downstream filters"); |
80 |
|
FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue); |
81 |
|
_refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME); |
82 |
|
|
92 |
|
|
93 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
94 |
|
} |
95 |
< |
|
95 |
> |
|
96 |
|
/** |
97 |
+ |
* Does a dependency check. Used mainly at startup to |
98 |
+ |
* see if the required dependencies (components) are up |
99 |
+ |
* and running. |
100 |
+ |
* |
101 |
+ |
* @return a boolean value, true if the depdencies are satisfied |
102 |
+ |
*/ |
103 |
+ |
public boolean depCheck() { |
104 |
+ |
try { |
105 |
+ |
org.omg.CORBA.Object obj; |
106 |
+ |
// first check the ConfigurationManager is alive |
107 |
+ |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
108 |
+ |
// then suss out our parent filter |
109 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
110 |
+ |
String parentFilterName = cp.getProperty(NAME, "Filter.parentFilter"); |
111 |
+ |
// finally check the parent filter is alive |
112 |
+ |
obj = _refman.getCORBARef("iscream.Filter." + parentFilterName); |
113 |
+ |
} catch(ComponentCORBAException e) { |
114 |
+ |
_logger.write(toString(), Logger.WARNING, "Dependency Failure: "+e); |
115 |
+ |
return false; |
116 |
+ |
} catch(PropertyNotFoundException e) { |
117 |
+ |
_logger.write(toString(), Logger.WARNING, "Unable to obtain configuration: "+e); |
118 |
+ |
return false; |
119 |
+ |
} |
120 |
+ |
// dependency check suceeded |
121 |
+ |
return true; |
122 |
+ |
} |
123 |
+ |
|
124 |
+ |
/** |
125 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
126 |
|
* method to provide clean logging (every class should have this). |
127 |
|
* |
152 |
|
/** |
153 |
|
* A reference to the reference manager in use |
154 |
|
*/ |
155 |
< |
private ReferenceManager _refman; |
155 |
> |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
156 |
|
|
157 |
|
//---STATIC ATTRIBUTES--- |
158 |
|
|