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.7
Committed: Thu Nov 23 09:41:09 2000 UTC (23 years, 6 months ago) by pjm2
Branch: MAIN
Changes since 1.6: +3 -3 lines
Log Message:
Corrected the message contained within the usage() function.

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.6 * @author $Author: tdb1 $
14 pjm2 1.7 * @version $Id: FilterMain.java,v 1.6 2000/11/23 01:44:05 tdb1 Exp $
15 tdb 1.1 */
16     class FilterMain {
17    
18     //---FINAL ATTRIBUTES---
19    
20     /**
21     * The current CVS revision of this class
22     */
23 pjm2 1.7 public static final String REVISION = "$Revision: 1.6 $";
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     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 tdb 1.2 int port = 0;
76 tdb 1.6 String parentFilterName = null;
77 tdb 1.2
78     // did we?
79     if (myConfig == null) {
80     System.out.println("Failed: is it there?, can you read it?");
81     System.exit(1);
82     } else {
83    
84     // get the property
85     try {
86     //QUERY HERE.... ???
87     port = new Integer(myConfig.getProperty("Filter.listenPort")).intValue();
88 tdb 1.6 parentFilterName = myConfig.getProperty("Filter.parentFilter");
89 tdb 1.2 } catch (org.omg.CORBA.MARSHAL e) {
90     System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back");
91 tdb 1.3 //System.exit(1);
92 tdb 1.2 }
93     }
94 tdb 1.1
95     logger.write(toString, Logger.SYSINIT, "configured");
96    
97     // **** END COMMENT
98    
99 tdb 1.5 // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
100    
101     // get a root (CHANGE to use FilterManager)
102 tdb 1.6 objRef = ncRef.resolve(ncRef.to_name("iscream.Filter." + parentFilterName));
103     Filter parentFilter = FilterHelper.narrow(objRef);
104 tdb 1.5
105 tdb 1.1 // SETUP our Servant
106    
107     // create the FilterServant
108 tdb 1.6 FilterServant filterServant = new FilterServant(logger, parentFilter, ourName, new Integer(port).toString() , new Integer(port).toString());
109    
110     // register ourselves
111    
112 tdb 1.1 // and advertise it to the naming context
113     objRef = poa.servant_to_reference(filterServant);
114     ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef);
115 tdb 1.6
116     // **** END COMMENT
117 tdb 1.1
118     // END SETUP
119    
120 tdb 1.5
121 tdb 1.1 /**************************************************************
122     Here would be an ideal place to start another thread to do
123     the listening part of the Filter. Ideally it should just be
124     created and then run(). It may be necessary to pass some of
125     the following parameters into the thread by the constructor.
126    
127     Logger logger
128     - a reference to a Logger object
129     FilterManager filterManager
130     - a reference to the system filter manager
131     ConfigurationManager configManager
132     - a reference to the system configuration manager
133     Configuration myConfig
134     - a reference to the configuration object for this
135     filter instance
136     String ourName
137     - our "identifier" name
138    
139     **************************************************************/
140 tdb 1.5
141 tdb 1.2 logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener");
142 tdb 1.6 UDPReader udpReader = new UDPReader(port, parentFilter, logger);
143 pjm2 1.4 udpReader.start();
144 tdb 1.2 logger.write(toString, Logger.SYSINIT, "Filter UDP listener started");
145 tdb 1.5
146 tdb 1.1 // TEST
147 tdb 1.6 parentFilter.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>");
148 tdb 1.1
149     // start the POA off
150     poa.the_POAManager().activate();
151    
152     logger.write(toString, Logger.SYSINIT, "started");
153    
154     // now we are running, we just need to serve
155     // so we ask the orb to block for us until it has finished
156     orb.run();
157    
158     } catch (Exception e) {
159     System.err.println("FILTER ERROR: " + e);
160     e.printStackTrace(System.out);
161     }
162     }
163    
164     /**
165     * A simple method to print the usage of this class.
166     * It never returns, but instead exits to the system
167     * with a value 1, to indicate the system did not start
168     * properly.
169     */
170     public static void usage() {
171 pjm2 1.7 System.out.println("USAGE: java FilterMain <name>");
172 tdb 1.1 System.out.println("WHERE <name>:");
173     System.out.println(" The unique identifier for the Filter in the system.");
174     System.exit(1);
175     }
176    
177     //---CONSTRUCTORS---
178    
179     //---PUBLIC METHODS---
180    
181     //---PRIVATE METHODS---
182    
183     //---ACCESSOR/MUTATOR METHODS---
184    
185     //---ATTRIBUTES---
186    
187     //---STATIC ATTRIBUTES---
188    
189 pjm2 1.4 }