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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/FilterMain.java (file contents):
Revision 1.3 by tdb, Tue Nov 21 23:14:00 2000 UTC vs.
Revision 1.18 by tdb, Fri Jan 12 00:45:25 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.filter;
3  
4   //---IMPORTS---
5 + import uk.ac.ukc.iscream.util.*;
6   import uk.ac.ukc.iscream.core.*;
7   import uk.ac.ukc.iscream.filter.*;
6 import org.omg.CORBA.*;
7 import org.omg.CosNaming.*;
8 import org.omg.PortableServer.*;
8  
9   /**
10   * A Filter Startup Class
11 + * A filter is an iscream component.
12   *
13   * @author  $Author$
14   * @version $Id$
15   */
16 < class FilterMain {
16 > public class FilterMain implements uk.ac.ukc.iscream.util.Component {
17  
18   //---FINAL ATTRIBUTES---
19  
# Line 24 | Line 24 | class FilterMain {
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);
27 > //---CONSTRUCTORS---
28 >    
29 >    /**
30 >     * Constructs a Filter with the name given
31 >     *
32 >     * @param givenName the name
33 >     */
34 >    public FilterMain(String givenName) {
35 >        NAME = givenName;
36 >    }
37 >
38 > //---PUBLIC METHODS---
39 >
40 >    /**
41 >     * Starts the Filter component
42 >     */
43 >    public void start() throws ComponentStartException {
44 >              
45 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
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 <            //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 <            int port = 0;
79 <  
80 <            // did we?
81 <            if (myConfig == null) {
82 <                System.out.println("Failed: is it there?, can you read it?");
47 >        // configuration variables we require
48 >        int UDPListenPort = 0;
49 >        int TCPListenPort = 0;
50 >        String parentFilterName = null;
51 >
52 >        Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME);
53 >        if (config == null) {
54 >            System.err.println("CRITICAL:Unable to obtain configuration" +
55 >                               "\n         Advise you check the i-scream log for more information.");
56 >            _logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration");
57 >            System.exit(1);
58 >        } else {
59 >            try {
60 >                UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort"));
61 >                TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort"));
62 >                parentFilterName = config.getProperty("Filter.parentFilter");
63 >            } catch (org.omg.CORBA.MARSHAL e) {
64 >                System.err.println ("CRITICAL:Unable to obtain required configuration property" +
65 >                                    "\n         Advise you check the i-scream log for more information.");
66 >                _logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present");
67                  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                    //System.exit(1);
93                }
68              }
95            
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            
131            logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener");
132            //UDPReader udpReader = new UDPReader(port, logger);
133            //udpReader.start();
134            logger.write(toString, Logger.SYSINIT, "Filter UDP listener started");
135            
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            root.receiveXML("This is just a debugging test, we ("+ourName+") are live on port: "+port);
148            
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);
69          }
70 +        _logger.write(toString(), Logger.SYSINIT, "configured");
71 +        
72 +        // get parent
73 +        Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName));
74 +        
75 +        // setup a queue
76 +        Queue queue = new Queue();
77 +        
78 +        // Start a filter thread
79 +        _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
80 +        FilterThread filterThread = new FilterThread(queue, parentFilter);
81 +        filterThread.start();
82 +        
83 +        // FilterServant start (for inbound child filter data)
84 +        _logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName);
85 +        FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
86 +        _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
87 +
88 +        // UDL Reader start (for inbound host data)
89 +        _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
90 +        UDPReader udpReader = new UDPReader(UDPListenPort, queue);
91 +        udpReader.start();
92 +
93 +        // TCP Reader start (for heartbeats)
94 +        _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
95 +        TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
96 +        tcpReader.start();
97 +        
98 +        _logger.write(toString(), Logger.SYSINIT, "started");
99      }
100  
101 <    /**
102 <     * A simple method to print the usage of this class.
103 <     * It never returns, but instead exits to the system
104 <     * with a value 1, to indicate the system did not start
105 <     * properly.
101 >    /**
102 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
103 >     * method to provide clean logging (every class should have this).
104 >     *
105 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
106 >     * to format the toString()
107 >     *
108 >     * @return the name of this class and its CVS revision
109       */
110 <    public static void usage() {
111 <        System.out.println("USAGE: java Filter <name>");
112 <        System.out.println("WHERE <name>:");
113 <        System.out.println("      The unique identifier for the Filter in the system.");
114 <        System.exit(1);
110 >    public String toString() {
111 >        return FormatName.getName(
112 >            NAME,
113 >            getClass().getName(),
114 >            REVISION);
115      }
116  
177 //---CONSTRUCTORS---
178
179 //---PUBLIC METHODS---
180
117   //---PRIVATE METHODS---
118  
119   //---ACCESSOR/MUTATOR METHODS---
120  
121   //---ATTRIBUTES---
122  
123 +    /**
124 +     * This holds a reference to the
125 +     * system logger that is being used.
126 +     */
127 +    private Logger _logger = ReferenceManager.getInstance().getLogger();
128 +
129 +    /**
130 +     * A reference to the reference manager in use
131 +     */
132 +    private ReferenceManager _refman = ReferenceManager.getInstance();
133 +
134   //---STATIC ATTRIBUTES---
135 +
136 +    /**
137 +     * The friendly name for this component, used by
138 +     * all related classes.
139 +     * This is set from the configuration.
140 +     */
141 +    public static String NAME;
142  
143 < }            
143 > }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines