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.4
Committed: Wed Nov 22 08:47:36 2000 UTC (23 years, 6 months ago) by pjm2
Branch: MAIN
Changes since 1.3: +5 -5 lines
Log Message:
Incorporated the UDPReader thread.

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     * @author $Author: tdb1 $
14 pjm2 1.4 * @version $Id: FilterMain.java,v 1.3 2000/11/21 23:14:00 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.4 public static final String REVISION = "$Revision: 1.3 $";
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     //objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager"));
66     //FilterManager filterManager = FilterManagerHelper.narrow(objRef);
67    
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     // SETUP our Servant
101    
102     // create the FilterServant
103     FilterServant filterServant = new FilterServant(logger, ourName);
104    
105     // and advertise it to the naming context
106     objRef = poa.servant_to_reference(filterServant);
107     ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef);
108    
109     // END SETUP
110    
111     /**************************************************************
112     Here would be an ideal place to start another thread to do
113     the listening part of the Filter. Ideally it should just be
114     created and then run(). It may be necessary to pass some of
115     the following parameters into the thread by the constructor.
116    
117     Logger logger
118     - a reference to a Logger object
119     FilterManager filterManager
120     - a reference to the system filter manager
121     ConfigurationManager configManager
122     - a reference to the system configuration manager
123     Configuration myConfig
124     - a reference to the configuration object for this
125     filter instance
126     String ourName
127     - our "identifier" name
128    
129     **************************************************************/
130 tdb 1.2
131     logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener");
132 pjm2 1.4 UDPReader udpReader = new UDPReader(port, logger);
133     udpReader.start();
134 tdb 1.2 logger.write(toString, Logger.SYSINIT, "Filter UDP listener started");
135 tdb 1.1
136     // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
137    
138     // get a root (CHANGE to use FilterManager)
139     objRef = ncRef.resolve(ncRef.to_name("iscream.Filter.root1"));
140     Filter root = FilterHelper.narrow(objRef);
141    
142     // register ourselves
143    
144     // **** END COMMENT
145    
146     // TEST
147 tdb 1.3 root.receiveXML("This is just a debugging test, we ("+ourName+") are live on port: "+port);
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     System.out.println("USAGE: java Filter <name>");
172     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 }