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]; |
43 |
< |
} |
44 |
< |
else { |
45 |
< |
usage(); |
46 |
< |
} |
41 |
< |
|
42 |
< |
// can't have a real toString() :) |
43 |
< |
String toString = "Filter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
44 |
< |
|
45 |
< |
ReferenceManager refman = ReferenceManager.init(null, ourName); |
46 |
< |
|
47 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); |
39 |
> |
//---PUBLIC METHODS--- |
40 |
> |
|
41 |
> |
/** |
42 |
> |
* Starts the Filter component |
43 |
> |
*/ |
44 |
> |
public void start() throws ComponentStartException { |
45 |
> |
|
46 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
47 |
|
|
48 |
|
// configuration variables we require |
49 |
|
int UDPListenPort = 0; |
50 |
|
int TCPListenPort = 0; |
51 |
|
String parentFilterName = null; |
52 |
< |
|
53 |
< |
Configuration config = refman.getCM().getConfiguration(refman.getName()); |
52 |
> |
int queueMonitorInterval = 0; |
53 |
> |
|
54 |
> |
Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME); |
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 { |
56 |
> |
throw new ComponentStartException("Unable to obtain configuration for component"); |
57 |
> |
} |
58 |
> |
else { |
59 |
|
try { |
60 |
+ |
// get the configuration properties we need |
61 |
|
UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort")); |
62 |
|
TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort")); |
63 |
|
parentFilterName = config.getProperty("Filter.parentFilter"); |
64 |
+ |
queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); |
65 |
|
} catch (org.omg.CORBA.MARSHAL e) { |
66 |
< |
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 |
< |
|
66 |
> |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
67 |
|
} |
68 |
|
} |
69 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "configured"); |
69 |
> |
|
70 |
> |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
71 |
> |
|
72 |
|
// get parent |
73 |
< |
Filter parentFilter = FilterHelper.narrow(refman.getCORBARef("iscream.Filter." + parentFilterName)); |
73 |
> |
Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName)); |
74 |
|
|
75 |
< |
|
75 |
> |
// setup a queue |
76 |
> |
Queue queue = new Queue(); |
77 |
> |
// startup a monitor on this queue, every minute |
78 |
> |
String queueName = NAME + " Filter"; |
79 |
> |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
80 |
|
|
81 |
+ |
// Start a filter thread |
82 |
+ |
_logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer"); |
83 |
+ |
FilterThread filterThread = new FilterThread(queue, parentFilter); |
84 |
+ |
filterThread.start(); |
85 |
+ |
|
86 |
|
// FilterServant start (for inbound child filter data) |
87 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
88 |
< |
FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort); |
89 |
< |
refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName()); |
87 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
88 |
> |
FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue); |
89 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME); |
90 |
|
|
91 |
|
// UDL Reader start (for inbound host data) |
92 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter UDP listener"); |
93 |
< |
UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter); |
92 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener"); |
93 |
> |
UDPReader udpReader = new UDPReader(UDPListenPort, queue); |
94 |
|
udpReader.start(); |
95 |
|
|
96 |
|
// TCP Reader start (for heartbeats) |
97 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter TCP listener"); |
98 |
< |
TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter); |
97 |
> |
_logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener"); |
98 |
> |
TCPReader tcpReader = new TCPReader(TCPListenPort, queue); |
99 |
|
tcpReader.start(); |
100 |
|
|
101 |
< |
// 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(); |
101 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
102 |
|
} |
103 |
|
|
104 |
< |
/** |
105 |
< |
* A simple method to print the usage of this class. |
106 |
< |
* It never returns, but instead exits to the system |
107 |
< |
* with a value 1, to indicate the system did not start |
108 |
< |
* properly. |
104 |
> |
/** |
105 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
106 |
> |
* method to provide clean logging (every class should have this). |
107 |
> |
* |
108 |
> |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
109 |
> |
* to format the toString() |
110 |
> |
* |
111 |
> |
* @return the name of this class and its CVS revision |
112 |
|
*/ |
113 |
< |
public static void usage() { |
114 |
< |
System.out.println("USAGE: java FilterMain <name>"); |
115 |
< |
System.out.println("WHERE <name>:"); |
116 |
< |
System.out.println(" The unique identifier for the Filter in the system."); |
117 |
< |
System.exit(1); |
113 |
> |
public String toString() { |
114 |
> |
return FormatName.getName( |
115 |
> |
NAME, |
116 |
> |
getClass().getName(), |
117 |
> |
REVISION); |
118 |
|
} |
119 |
|
|
112 |
– |
//---CONSTRUCTORS--- |
113 |
– |
|
114 |
– |
//---PUBLIC METHODS--- |
115 |
– |
|
120 |
|
//---PRIVATE METHODS--- |
121 |
|
|
122 |
|
//---ACCESSOR/MUTATOR METHODS--- |
123 |
|
|
124 |
|
//---ATTRIBUTES--- |
125 |
|
|
126 |
+ |
/** |
127 |
+ |
* This holds a reference to the |
128 |
+ |
* system logger that is being used. |
129 |
+ |
*/ |
130 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
131 |
+ |
|
132 |
+ |
/** |
133 |
+ |
* A reference to the reference manager in use |
134 |
+ |
*/ |
135 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
136 |
+ |
|
137 |
|
//---STATIC ATTRIBUTES--- |
138 |
|
|
139 |
< |
} |
139 |
> |
/** |
140 |
> |
* The friendly name for this component, used by |
141 |
> |
* all related classes. |
142 |
> |
* This is set from the configuration. |
143 |
> |
*/ |
144 |
> |
public static String NAME; |
145 |
> |
|
146 |
> |
} |