ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterMain.java
Revision: 1.9
Committed: Mon Nov 27 10:23:19 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.8: +4 -4 lines
Log Message:
Missed a few references to port.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4 import uk.ac.ukc.iscream.core.*;
5 import uk.ac.ukc.iscream.filter.*;
6 import org.omg.CORBA.*;
7 import org.omg.CosNaming.*;
8 import org.omg.PortableServer.*;
9
10 /**
11 * A Filter Startup Class
12 *
13 * @author $Author: tdb1 $
14 * @version $Id: FilterMain.java,v 1.8 2000/11/27 00:41:01 tdb1 Exp $
15 */
16 class FilterMain {
17
18 //---FINAL ATTRIBUTES---
19
20 /**
21 * The current CVS revision of this class
22 */
23 public static final String REVISION = "$Revision: 1.8 $";
24
25 //---STATIC METHODS---
26
27 public static void main(String[] args) {
28 System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
29 System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
30
31 // get our name from the command line
32 String ourName = "";
33 if (args.length == 1) {
34 ourName = args[0];
35 }
36 else {
37 usage();
38 }
39
40 // can't have a real toString() :)
41 String toString = "Filter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
42
43 try {
44 ORB orb = ORB.init(args, null);
45
46 // something to hold objects
47 org.omg.CORBA.Object objRef = null;
48
49 // 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);
106
107 // SETUP our Servant
108
109 // create the FilterServant
110 FilterServant filterServant = new FilterServant(logger, parentFilter, ourName, new Integer(TCPport).toString() , new Integer(UDPport).toString());
111
112 // register ourselves
113
114 // and advertise it to the naming context
115 objRef = poa.servant_to_reference(filterServant);
116 ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef);
117
118 // **** END COMMENT
119
120 // END SETUP
121
122
123 /**************************************************************
124 Here would be an ideal place to start another thread to do
125 the listening part of the Filter. Ideally it should just be
126 created and then run(). It may be necessary to pass some of
127 the following parameters into the thread by the constructor.
128
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 }
169 }
170
171 /**
172 * A simple method to print the usage of this class.
173 * It never returns, but instead exits to the system
174 * with a value 1, to indicate the system did not start
175 * properly.
176 */
177 public static void usage() {
178 System.out.println("USAGE: java FilterMain <name>");
179 System.out.println("WHERE <name>:");
180 System.out.println(" The unique identifier for the Filter in the system.");
181 System.exit(1);
182 }
183
184 //---CONSTRUCTORS---
185
186 //---PUBLIC METHODS---
187
188 //---PRIVATE METHODS---
189
190 //---ACCESSOR/MUTATOR METHODS---
191
192 //---ATTRIBUTES---
193
194 //---STATIC ATTRIBUTES---
195
196 }