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.*; |
9 |
|
|
10 |
|
/** |
11 |
|
* A Filter Startup Class |
12 |
+ |
* A filter is an iscream component. |
13 |
|
* |
14 |
|
* @author $Author$ |
15 |
|
* @version $Id$ |
16 |
|
*/ |
17 |
< |
class FilterMain { |
17 |
> |
public class FilterMain implements Component { |
18 |
|
|
19 |
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
25 |
|
|
26 |
|
//---STATIC METHODS--- |
27 |
|
|
28 |
< |
public static void main(String[] args) { |
29 |
< |
// *************************************** |
30 |
< |
// VERY TEMPORARY - will find a better way |
31 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
32 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
33 |
< |
// *************************************** |
28 |
> |
//---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 |
< |
// get our name from the command line |
40 |
< |
String ourName = ""; |
41 |
< |
if (args.length == 1) { |
42 |
< |
ourName = args[0]; |
39 |
> |
//---PUBLIC METHODS--- |
40 |
> |
|
41 |
> |
/** |
42 |
> |
* Starts the Filter component |
43 |
> |
*/ |
44 |
> |
public void start() throws ComponentStartException { |
45 |
> |
// get references to key objects |
46 |
> |
_logger = _refman.getLogger(); |
47 |
> |
|
48 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
49 |
> |
|
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 |
|
} |
38 |
– |
else { |
39 |
– |
usage(); |
40 |
– |
} |
59 |
|
|
60 |
< |
// can't have a real toString() :) |
61 |
< |
String toString = "Filter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
44 |
< |
|
45 |
< |
ReferenceManager refman = ReferenceManager.init(null, ourName); |
60 |
> |
// setup a queue |
61 |
> |
Queue queue = new Queue(); |
62 |
|
|
63 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); |
64 |
< |
|
65 |
< |
// configuration variables we require |
66 |
< |
int UDPListenPort = 0; |
67 |
< |
int TCPListenPort = 0; |
68 |
< |
String parentFilterName = null; |
69 |
< |
|
70 |
< |
Configuration config = refman.getCM().getConfiguration(refman.getName()); |
55 |
< |
if (config == null) { |
56 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain configuration" + |
57 |
< |
" Advise you check the i-scream log for more information."); |
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 |
< |
refman.getLogger().write(toString, Logger.FATAL, "required config property not present"); |
65 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" + |
66 |
< |
" Advise you check the i-scream log for more information."); |
67 |
< |
|
68 |
< |
} |
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 |
|
} |
70 |
– |
refman.getLogger().write(toString, Logger.SYSINIT, "configured"); |
71 |
– |
// get parent |
72 |
– |
Filter parentFilter = FilterHelper.narrow(refman.getCORBARef("iscream.Filter." + parentFilterName)); |
72 |
|
|
73 |
< |
|
73 |
> |
// Start a filter thread |
74 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
75 |
> |
FilterThread filterThread = new FilterThread(queue); |
76 |
> |
filterThread.start(); |
77 |
|
|
78 |
|
// FilterServant start (for inbound child filter data) |
79 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
80 |
< |
FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort); |
81 |
< |
refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName()); |
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 |
|
|
83 |
|
// UDL Reader start (for inbound host data) |
84 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter UDP listener"); |
85 |
< |
UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter); |
84 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
85 |
> |
UDPReader udpReader = new UDPReader(UDPListenPort, queue); |
86 |
|
udpReader.start(); |
87 |
|
|
88 |
|
// TCP Reader start (for heartbeats) |
89 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter TCP listener"); |
90 |
< |
TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter); |
89 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener"); |
90 |
> |
TCPReader tcpReader = new TCPReader(TCPListenPort, queue); |
91 |
|
tcpReader.start(); |
92 |
|
|
93 |
< |
// start the POA off |
92 |
< |
// now we are running, we just need to serve |
93 |
< |
// so we ask the orb to block for us until it has finished |
94 |
< |
refman.activatePOA(); |
95 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "started"); |
96 |
< |
refman.getORB().run(); |
93 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
94 |
|
} |
95 |
< |
|
96 |
< |
/** |
97 |
< |
* A simple method to print the usage of this class. |
98 |
< |
* It never returns, but instead exits to the system |
99 |
< |
* with a value 1, to indicate the system did not start |
100 |
< |
* properly. |
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 static void usage() { |
104 |
< |
System.out.println("USAGE: java FilterMain <name>"); |
105 |
< |
System.out.println("WHERE <name>:"); |
106 |
< |
System.out.println(" The unique identifier for the Filter in the system."); |
107 |
< |
System.exit(1); |
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 |
+ |
* |
128 |
+ |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
129 |
+ |
* to format the toString() |
130 |
+ |
* |
131 |
+ |
* @return the name of this class and its CVS revision |
132 |
+ |
*/ |
133 |
+ |
public String toString() { |
134 |
+ |
return FormatName.getName( |
135 |
+ |
NAME, |
136 |
+ |
getClass().getName(), |
137 |
+ |
REVISION); |
138 |
+ |
} |
139 |
|
|
112 |
– |
//---CONSTRUCTORS--- |
113 |
– |
|
114 |
– |
//---PUBLIC METHODS--- |
115 |
– |
|
140 |
|
//---PRIVATE METHODS--- |
141 |
|
|
142 |
|
//---ACCESSOR/MUTATOR METHODS--- |
143 |
|
|
144 |
|
//---ATTRIBUTES--- |
145 |
|
|
146 |
+ |
/** |
147 |
+ |
* This holds a reference to the |
148 |
+ |
* system logger that is being used. |
149 |
+ |
*/ |
150 |
+ |
private Logger _logger; |
151 |
+ |
|
152 |
+ |
/** |
153 |
+ |
* A reference to the reference manager in use |
154 |
+ |
*/ |
155 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
156 |
+ |
|
157 |
|
//---STATIC ATTRIBUTES--- |
158 |
|
|
159 |
< |
} |
159 |
> |
/** |
160 |
> |
* The friendly name for this component, used by |
161 |
> |
* all related classes. |
162 |
> |
* This is set from the configuration. |
163 |
> |
*/ |
164 |
> |
public static String NAME; |
165 |
> |
|
166 |
> |
} |