1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.filter; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.core.*; |
6 |
import uk.ac.ukc.iscream.filter.*; |
7 |
import org.omg.CORBA.*; |
8 |
import org.omg.CosNaming.*; |
9 |
import org.omg.PortableServer.*; |
10 |
|
11 |
/** |
12 |
* A Filter Startup Class |
13 |
* |
14 |
* @author $Author: tdb1 $ |
15 |
* @version $Id: FilterMain.java,v 1.11 2000/11/29 19:26:00 tdb1 Exp $ |
16 |
*/ |
17 |
class FilterMain { |
18 |
|
19 |
//---FINAL ATTRIBUTES--- |
20 |
|
21 |
/** |
22 |
* The current CVS revision of this class |
23 |
*/ |
24 |
public static final String REVISION = "$Revision: 1.11 $"; |
25 |
|
26 |
//---STATIC METHODS--- |
27 |
|
28 |
public static void main(String[] args) { |
29 |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
30 |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
31 |
|
32 |
// get our name from the command line |
33 |
String ourName = ""; |
34 |
if (args.length == 1) { |
35 |
ourName = args[0]; |
36 |
} |
37 |
else { |
38 |
usage(); |
39 |
} |
40 |
|
41 |
// can't have a real toString() :) |
42 |
String toString = "Filter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
43 |
|
44 |
try { |
45 |
ORB orb = ORB.init(args, null); |
46 |
|
47 |
// something to hold objects |
48 |
org.omg.CORBA.Object objRef = null; |
49 |
|
50 |
// get the Root POA |
51 |
objRef = orb.resolve_initial_references("RootPOA"); |
52 |
POA poa = POAHelper.narrow(objRef); |
53 |
|
54 |
// get a hook to the name service |
55 |
objRef = orb.resolve_initial_references("NameService"); |
56 |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
57 |
|
58 |
// get a ref to the ConfigurationManager, Logger & the FilterManager |
59 |
|
60 |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
61 |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
62 |
|
63 |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
64 |
Logger logger = LoggerHelper.narrow(objRef); |
65 |
|
66 |
logger.write(toString, Logger.SYSINIT, "coming up"); |
67 |
|
68 |
|
69 |
// **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG |
70 |
// **** Please ignore this block of code, it's just "copy/paste" :) |
71 |
|
72 |
// get the config |
73 |
Configuration myConfig = configManager.getConfiguration(ourName); |
74 |
|
75 |
// read some config here |
76 |
int UDPport = 0; |
77 |
int TCPport = 0; |
78 |
String parentFilterName = null; |
79 |
|
80 |
// did we? |
81 |
if (myConfig == null) { |
82 |
System.out.println("Failed: is it there?, can you read it?"); |
83 |
System.exit(1); |
84 |
} else { |
85 |
|
86 |
// get the property |
87 |
try { |
88 |
//QUERY HERE.... ??? |
89 |
UDPport = new Integer(myConfig.getProperty("Filter.UDPlistenPort")).intValue(); |
90 |
TCPport = new Integer(myConfig.getProperty("Filter.TCPlistenPort")).intValue(); |
91 |
parentFilterName = myConfig.getProperty("Filter.parentFilter"); |
92 |
} catch (org.omg.CORBA.MARSHAL e) { |
93 |
System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back"); |
94 |
//System.exit(1); |
95 |
} |
96 |
} |
97 |
|
98 |
logger.write(toString, Logger.SYSINIT, "configured"); |
99 |
|
100 |
// **** END COMMENT |
101 |
|
102 |
// **** INITIAL FILTER MANAGER COMMUNICATIONS HERE |
103 |
|
104 |
// get a root (CHANGE to use FilterManager) |
105 |
objRef = ncRef.resolve(ncRef.to_name("iscream.Filter." + parentFilterName)); |
106 |
Filter parentFilter = FilterHelper.narrow(objRef); |
107 |
|
108 |
// SETUP our Servant |
109 |
|
110 |
// create the FilterServant |
111 |
logger.write(toString, Logger.DEBUG, "firing servant with parent - " + parentFilterName); |
112 |
FilterServant filterServant = new FilterServant(logger, parentFilter, ourName, new Integer(TCPport).toString() , new Integer(UDPport).toString()); |
113 |
|
114 |
// register ourselves |
115 |
|
116 |
// and advertise it to the naming context |
117 |
objRef = poa.servant_to_reference(filterServant); |
118 |
ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef); |
119 |
|
120 |
// **** END COMMENT |
121 |
|
122 |
// END SETUP |
123 |
|
124 |
|
125 |
/************************************************************** |
126 |
Here would be an ideal place to start another thread to do |
127 |
the listening part of the Filter. Ideally it should just be |
128 |
created and then run(). It may be necessary to pass some of |
129 |
the following parameters into the thread by the constructor. |
130 |
|
131 |
Logger logger |
132 |
- a reference to a Logger object |
133 |
FilterManager filterManager |
134 |
- a reference to the system filter manager |
135 |
ConfigurationManager configManager |
136 |
- a reference to the system configuration manager |
137 |
Configuration myConfig |
138 |
- a reference to the configuration object for this |
139 |
filter instance |
140 |
String ourName |
141 |
- our "identifier" name |
142 |
|
143 |
**************************************************************/ |
144 |
|
145 |
logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener"); |
146 |
UDPReader udpReader = new UDPReader(UDPport, parentFilter, logger); |
147 |
udpReader.start(); |
148 |
logger.write(toString, Logger.SYSINIT, "Filter UDP listener started"); |
149 |
|
150 |
logger.write(toString, Logger.SYSINIT, "starting Filter TCP listener"); |
151 |
TCPReader tcpReader = new TCPReader(logger, configManager, TCPport, parentFilter); |
152 |
tcpReader.start(); |
153 |
logger.write(toString, Logger.SYSINIT, "Filter TCP listener started"); |
154 |
|
155 |
// TEST |
156 |
//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>"); |
157 |
|
158 |
// start the POA off |
159 |
poa.the_POAManager().activate(); |
160 |
|
161 |
logger.write(toString, Logger.SYSINIT, "started"); |
162 |
|
163 |
// now we are running, we just need to serve |
164 |
// so we ask the orb to block for us until it has finished |
165 |
orb.run(); |
166 |
|
167 |
} catch (Exception e) { |
168 |
System.err.println("FILTER ERROR: " + e); |
169 |
e.printStackTrace(System.out); |
170 |
} |
171 |
} |
172 |
|
173 |
/** |
174 |
* A simple method to print the usage of this class. |
175 |
* It never returns, but instead exits to the system |
176 |
* with a value 1, to indicate the system did not start |
177 |
* properly. |
178 |
*/ |
179 |
public static void usage() { |
180 |
System.out.println("USAGE: java FilterMain <name>"); |
181 |
System.out.println("WHERE <name>:"); |
182 |
System.out.println(" The unique identifier for the Filter in the system."); |
183 |
System.exit(1); |
184 |
} |
185 |
|
186 |
//---CONSTRUCTORS--- |
187 |
|
188 |
//---PUBLIC METHODS--- |
189 |
|
190 |
//---PRIVATE METHODS--- |
191 |
|
192 |
//---ACCESSOR/MUTATOR METHODS--- |
193 |
|
194 |
//---ATTRIBUTES--- |
195 |
|
196 |
//---STATIC ATTRIBUTES--- |
197 |
|
198 |
} |