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.5
Committed: Wed Nov 22 09:36:38 2000 UTC (23 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.4: +21 -20 lines
Log Message:
Had to jiggle a few bits around. It's going to take a bit of sorting to get this
arranged correctly, but we need the FilterManager finished first.

File Contents

# User Rev Content
1 tdb 1.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 tdb 1.5 * @author $Author: pjm2 $
14     * @version $Id: FilterMain.java,v 1.4 2000/11/22 08:47:36 pjm2 Exp $
15 tdb 1.1 */
16     class FilterMain {
17    
18     //---FINAL ATTRIBUTES---
19    
20     /**
21     * The current CVS revision of this class
22     */
23 tdb 1.5 public static final String REVISION = "$Revision: 1.4 $";
24 tdb 1.1
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 tdb 1.5 objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager"));
66     FilterManager filterManager = FilterManagerHelper.narrow(objRef);
67 tdb 1.1
68     logger.write(toString, Logger.SYSINIT, "coming up");
69    
70    
71     // **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG
72     // **** Please ignore this block of code, it's just "copy/paste" :)
73    
74     // get the config
75     Configuration myConfig = configManager.getConfiguration(ourName);
76    
77     // read some config here
78 tdb 1.2 int port = 0;
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     port = new Integer(myConfig.getProperty("Filter.listenPort")).intValue();
90     } catch (org.omg.CORBA.MARSHAL e) {
91     System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back");
92 tdb 1.3 //System.exit(1);
93 tdb 1.2 }
94     }
95 tdb 1.1
96     logger.write(toString, Logger.SYSINIT, "configured");
97    
98     // **** END COMMENT
99    
100 tdb 1.5 // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
101    
102     // get a root (CHANGE to use FilterManager)
103     objRef = ncRef.resolve(ncRef.to_name("iscream.Filter.root1"));
104     Filter root = FilterHelper.narrow(objRef);
105    
106     // register ourselves
107    
108     // **** END COMMENT
109    
110 tdb 1.1 // SETUP our Servant
111    
112     // create the FilterServant
113 tdb 1.5 FilterServant filterServant = new FilterServant(logger, root, ourName);
114 tdb 1.1
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 SETUP
120    
121 tdb 1.5
122 tdb 1.1 /**************************************************************
123     Here would be an ideal place to start another thread to do
124     the listening part of the Filter. Ideally it should just be
125     created and then run(). It may be necessary to pass some of
126     the following parameters into the thread by the constructor.
127    
128     Logger logger
129     - a reference to a Logger object
130     FilterManager filterManager
131     - a reference to the system filter manager
132     ConfigurationManager configManager
133     - a reference to the system configuration manager
134     Configuration myConfig
135     - a reference to the configuration object for this
136     filter instance
137     String ourName
138     - our "identifier" name
139    
140     **************************************************************/
141 tdb 1.5
142 tdb 1.2 logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener");
143 tdb 1.5 UDPReader udpReader = new UDPReader(port, root, logger);
144 pjm2 1.4 udpReader.start();
145 tdb 1.2 logger.write(toString, Logger.SYSINIT, "Filter UDP listener started");
146 tdb 1.5
147 tdb 1.1 // TEST
148 tdb 1.5 root.receiveXML("<?xml version=\"1.0\" encoding=\"ISO8859-1\"?><packet><test>This is just a debugging test, we ("+ourName+") are live on port: "+port+"</test></packet>");
149 tdb 1.1
150     // start the POA off
151     poa.the_POAManager().activate();
152    
153     logger.write(toString, Logger.SYSINIT, "started");
154    
155     // now we are running, we just need to serve
156     // so we ask the orb to block for us until it has finished
157     orb.run();
158    
159     } catch (Exception e) {
160     System.err.println("FILTER ERROR: " + e);
161     e.printStackTrace(System.out);
162     }
163     }
164    
165     /**
166     * A simple method to print the usage of this class.
167     * It never returns, but instead exits to the system
168     * with a value 1, to indicate the system did not start
169     * properly.
170     */
171     public static void usage() {
172     System.out.println("USAGE: java Filter <name>");
173     System.out.println("WHERE <name>:");
174     System.out.println(" The unique identifier for the Filter in the system.");
175     System.exit(1);
176     }
177    
178     //---CONSTRUCTORS---
179    
180     //---PUBLIC METHODS---
181    
182     //---PRIVATE METHODS---
183    
184     //---ACCESSOR/MUTATOR METHODS---
185    
186     //---ATTRIBUTES---
187    
188     //---STATIC ATTRIBUTES---
189    
190 pjm2 1.4 }