1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.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.*; |
6 |
– |
import org.omg.CORBA.*; |
7 |
– |
import org.omg.CosNaming.*; |
8 |
– |
import org.omg.PortableServer.*; |
8 |
|
|
9 |
|
/** |
10 |
|
* A Filter Startup Class |
24 |
|
//---STATIC METHODS--- |
25 |
|
|
26 |
|
public static void main(String[] args) { |
27 |
+ |
// *************************************** |
28 |
+ |
// VERY TEMPORARY - will find a better way |
29 |
|
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
30 |
|
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
31 |
< |
|
31 |
> |
// *************************************** |
32 |
> |
|
33 |
|
// get our name from the command line |
34 |
|
String ourName = ""; |
35 |
|
if (args.length == 1) { |
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 |
< |
try { |
44 |
< |
ORB orb = ORB.init(args, null); |
47 |
> |
refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); |
48 |
|
|
49 |
< |
// something to hold objects |
50 |
< |
org.omg.CORBA.Object objRef = null; |
51 |
< |
|
52 |
< |
// get the Root POA |
50 |
< |
objRef = orb.resolve_initial_references("RootPOA"); |
51 |
< |
POA poa = POAHelper.narrow(objRef); |
52 |
< |
|
53 |
< |
// get a hook to the name service |
54 |
< |
objRef = orb.resolve_initial_references("NameService"); |
55 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
56 |
< |
|
57 |
< |
// get a ref to the ConfigurationManager, Logger & the FilterManager |
58 |
< |
|
59 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
60 |
< |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
61 |
< |
|
62 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
63 |
< |
Logger logger = LoggerHelper.narrow(objRef); |
64 |
< |
|
65 |
< |
logger.write(toString, Logger.SYSINIT, "coming up"); |
66 |
< |
|
67 |
< |
|
68 |
< |
// **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG |
69 |
< |
// **** Please ignore this block of code, it's just "copy/paste" :) |
70 |
< |
|
71 |
< |
// get the config |
72 |
< |
Configuration myConfig = configManager.getConfiguration(ourName); |
73 |
< |
|
74 |
< |
// read some config here |
75 |
< |
int UDPport = 0; |
76 |
< |
int TCPport = 0; |
77 |
< |
String parentFilterName = null; |
78 |
< |
|
79 |
< |
// did we? |
80 |
< |
if (myConfig == null) { |
81 |
< |
System.out.println("Failed: is it there?, can you read it?"); |
82 |
< |
System.exit(1); |
83 |
< |
} else { |
84 |
< |
|
85 |
< |
// get the property |
86 |
< |
try { |
87 |
< |
//QUERY HERE.... ??? |
88 |
< |
UDPport = new Integer(myConfig.getProperty("Filter.UDPlistenPort")).intValue(); |
89 |
< |
TCPport = new Integer(myConfig.getProperty("Filter.TCPlistenPort")).intValue(); |
90 |
< |
parentFilterName = myConfig.getProperty("Filter.parentFilter"); |
91 |
< |
} catch (org.omg.CORBA.MARSHAL e) { |
92 |
< |
System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back"); |
93 |
< |
//System.exit(1); |
94 |
< |
} |
95 |
< |
} |
96 |
< |
|
97 |
< |
logger.write(toString, Logger.SYSINIT, "configured"); |
98 |
< |
|
99 |
< |
// **** END COMMENT |
100 |
< |
|
101 |
< |
// **** INITIAL FILTER MANAGER COMMUNICATIONS HERE |
102 |
< |
|
103 |
< |
// get a root (CHANGE to use FilterManager) |
104 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.Filter." + parentFilterName)); |
105 |
< |
Filter parentFilter = FilterHelper.narrow(objRef); |
49 |
> |
// configuration variables we require |
50 |
> |
int UDPListenPort = 0; |
51 |
> |
int TCPListenPort = 0; |
52 |
> |
String parentFilterName = null; |
53 |
|
|
54 |
< |
// SETUP our Servant |
55 |
< |
|
56 |
< |
// create the FilterServant |
57 |
< |
FilterServant filterServant = new FilterServant(logger, parentFilter, ourName, new Integer(TCPport).toString() , new Integer(UDPport).toString()); |
54 |
> |
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 |
< |
// register ourselves |
68 |
> |
} |
69 |
> |
} |
70 |
> |
refman.getLogger().write(toString, Logger.SYSINIT, "configured"); |
71 |
> |
// get parent |
72 |
> |
Filter parentFilter = FilterHelper.narrow(refman.getCORBARef("iscream.Filter." + parentFilterName)); |
73 |
> |
|
74 |
> |
|
75 |
> |
|
76 |
> |
// FilterServant start (for inbound child filter data) |
77 |
> |
refman.getLogger().write(toString, Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName); |
78 |
> |
FilterServant filterServant = new FilterServant(parentFilter, TCPListenPort, UDPListenPort); |
79 |
> |
refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName()); |
80 |
|
|
81 |
< |
// and advertise it to the naming context |
82 |
< |
objRef = poa.servant_to_reference(filterServant); |
83 |
< |
ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef); |
81 |
> |
// UDL Reader start (for inbound host data) |
82 |
> |
refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter UDP listener"); |
83 |
> |
UDPReader udpReader = new UDPReader(UDPListenPort, parentFilter); |
84 |
> |
udpReader.start(); |
85 |
|
|
86 |
< |
// **** END COMMENT |
87 |
< |
|
88 |
< |
// END SETUP |
89 |
< |
|
90 |
< |
|
91 |
< |
/************************************************************** |
92 |
< |
Here would be an ideal place to start another thread to do |
93 |
< |
the listening part of the Filter. Ideally it should just be |
94 |
< |
created and then run(). It may be necessary to pass some of |
95 |
< |
the following parameters into the thread by the constructor. |
96 |
< |
|
129 |
< |
Logger logger |
130 |
< |
- a reference to a Logger object |
131 |
< |
FilterManager filterManager |
132 |
< |
- a reference to the system filter manager |
133 |
< |
ConfigurationManager configManager |
134 |
< |
- a reference to the system configuration manager |
135 |
< |
Configuration myConfig |
136 |
< |
- a reference to the configuration object for this |
137 |
< |
filter instance |
138 |
< |
String ourName |
139 |
< |
- our "identifier" name |
140 |
< |
|
141 |
< |
**************************************************************/ |
142 |
< |
|
143 |
< |
logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener"); |
144 |
< |
UDPReader udpReader = new UDPReader(UDPport, parentFilter, logger); |
145 |
< |
udpReader.start(); |
146 |
< |
logger.write(toString, Logger.SYSINIT, "Filter UDP listener started"); |
147 |
< |
|
148 |
< |
logger.write(toString, Logger.SYSINIT, "starting Filter TCP listener"); |
149 |
< |
TCPReader tcpReader = new TCPReader(logger, configManager, TCPport, parentFilter); |
150 |
< |
tcpReader.start(); |
151 |
< |
logger.write(toString, Logger.SYSINIT, "Filter TCP listener started"); |
152 |
< |
|
153 |
< |
// TEST |
154 |
< |
parentFilter.receiveXML("<?xml version=\"1.0\" encoding=\"ISO8859-1\"?><packet><test>This is just a debugging test, we ("+ourName+") are live on UDPport: "+UDPport+"</test></packet>"); |
155 |
< |
|
156 |
< |
// start the POA off |
157 |
< |
poa.the_POAManager().activate(); |
158 |
< |
|
159 |
< |
logger.write(toString, Logger.SYSINIT, "started"); |
160 |
< |
|
161 |
< |
// now we are running, we just need to serve |
162 |
< |
// so we ask the orb to block for us until it has finished |
163 |
< |
orb.run(); |
164 |
< |
|
165 |
< |
} catch (Exception e) { |
166 |
< |
System.err.println("FILTER ERROR: " + e); |
167 |
< |
e.printStackTrace(System.out); |
168 |
< |
} |
86 |
> |
// TCP Reader start (for heartbeats) |
87 |
> |
refman.getLogger().write(toString, Logger.SYSINIT, "starting Filter TCP listener"); |
88 |
> |
TCPReader tcpReader = new TCPReader(TCPListenPort, parentFilter); |
89 |
> |
tcpReader.start(); |
90 |
> |
|
91 |
> |
// 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(); |
97 |
|
} |
98 |
|
|
99 |
|
/** |