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.11
Committed: Wed Nov 29 19:26:00 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.10: +3 -2 lines
Log Message:
Made changes to fit into the new package structure. Also made all classes, namely
the UDPReader and FilterThread, conform to the Template class specification.

File Contents

# Content
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.10 2000/11/27 21:46:25 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.10 $";
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 FilterServant filterServant = new FilterServant(logger, parentFilter, ourName, new Integer(TCPport).toString() , new Integer(UDPport).toString());
112
113 // register ourselves
114
115 // and advertise it to the naming context
116 objRef = poa.servant_to_reference(filterServant);
117 ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef);
118
119 // **** END COMMENT
120
121 // END SETUP
122
123
124 /**************************************************************
125 Here would be an ideal place to start another thread to do
126 the listening part of the Filter. Ideally it should just be
127 created and then run(). It may be necessary to pass some of
128 the following parameters into the thread by the constructor.
129
130 Logger logger
131 - a reference to a Logger object
132 FilterManager filterManager
133 - a reference to the system filter manager
134 ConfigurationManager configManager
135 - a reference to the system configuration manager
136 Configuration myConfig
137 - a reference to the configuration object for this
138 filter instance
139 String ourName
140 - our "identifier" name
141
142 **************************************************************/
143
144 logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener");
145 UDPReader udpReader = new UDPReader(UDPport, parentFilter, logger);
146 udpReader.start();
147 logger.write(toString, Logger.SYSINIT, "Filter UDP listener started");
148
149 logger.write(toString, Logger.SYSINIT, "starting Filter TCP listener");
150 TCPReader tcpReader = new TCPReader(logger, configManager, TCPport, parentFilter);
151 tcpReader.start();
152 logger.write(toString, Logger.SYSINIT, "Filter TCP listener started");
153
154 // TEST
155 //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>");
156
157 // start the POA off
158 poa.the_POAManager().activate();
159
160 logger.write(toString, Logger.SYSINIT, "started");
161
162 // now we are running, we just need to serve
163 // so we ask the orb to block for us until it has finished
164 orb.run();
165
166 } catch (Exception e) {
167 System.err.println("FILTER ERROR: " + e);
168 e.printStackTrace(System.out);
169 }
170 }
171
172 /**
173 * A simple method to print the usage of this class.
174 * It never returns, but instead exits to the system
175 * with a value 1, to indicate the system did not start
176 * properly.
177 */
178 public static void usage() {
179 System.out.println("USAGE: java FilterMain <name>");
180 System.out.println("WHERE <name>:");
181 System.out.println(" The unique identifier for the Filter in the system.");
182 System.exit(1);
183 }
184
185 //---CONSTRUCTORS---
186
187 //---PUBLIC METHODS---
188
189 //---PRIVATE METHODS---
190
191 //---ACCESSOR/MUTATOR METHODS---
192
193 //---ATTRIBUTES---
194
195 //---STATIC ATTRIBUTES---
196
197 }