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.12 by ajm, Wed Nov 29 21:27:39 2000 UTC vs.
Revision 1.19 by tdb, Thu Jan 18 23:17:58 2001 UTC

# Line 2 | Line 2
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.componentmanager.*;
8   import uk.ac.ukc.iscream.filter.*;
7 import org.omg.CORBA.*;
8 import org.omg.CosNaming.*;
9 import org.omg.PortableServer.*;
9  
10   /**
11   * A Filter Startup Class
12 + * A filter is an iscream component.
13   *
14   * @author  $Author$
15   * @version $Id$
16   */
17 < class FilterMain {
17 > public class FilterMain implements Component {
18  
19   //---FINAL ATTRIBUTES---
20  
# Line 25 | Line 25 | class FilterMain {
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);
28 > //---CONSTRUCTORS---
29 >    
30 >    /**
31 >     * Constructs a Filter with the name given
32 >     *
33 >     * @param givenName the name
34 >     */
35 >    public FilterMain(String givenName) {
36 >        NAME = givenName;
37 >    }
38  
39 <            // SETUP our Servant
109 <            
110 <            // create the FilterServant
111 <            logger.write(toString, Logger.DEBUG, "firing servant with parent - " + parentFilterName);
112 <            FilterServant filterServant = new FilterServant(logger, parentFilter, ourName, new Integer(TCPport).toString() , new Integer(UDPport).toString());
39 > //---PUBLIC METHODS---
40  
41 <            // register ourselves
42 <
43 <            // and advertise it to the naming context
44 <            objRef = poa.servant_to_reference(filterServant);
45 <            ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef);
46 <
120 <            // **** END COMMENT
41 >    /**
42 >     * Starts the Filter component
43 >     */
44 >    public void start() throws ComponentStartException {
45 >              
46 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
47              
48 <            // END SETUP
49 <            
48 >        // configuration variables we require
49 >        int UDPListenPort = 0;
50 >        int TCPListenPort = 0;
51 >        String parentFilterName = null;
52  
53 <            /**************************************************************
54 <              Here would be an ideal place to start another thread to do
55 <              the listening part of the Filter. Ideally it should just be
56 <              created and then run(). It may be necessary to pass some of
57 <              the following parameters into the thread by the constructor.
58 <              
59 <                  Logger logger
60 <                      - a reference to a Logger object
61 <                  FilterManager filterManager
62 <                      - a reference to the system filter manager
63 <                  ConfigurationManager configManager
64 <                      - a reference to the system configuration manager
65 <                  Configuration myConfig
66 <                      - a reference to the configuration object for this
67 <                        filter instance
68 <                  String ourName
69 <                      - our "identifier" name
70 <            
71 <            **************************************************************/
72 <                                    
73 <            logger.write(toString, Logger.SYSINIT, "starting Filter UDP listener");
74 <            UDPReader udpReader = new UDPReader(UDPport, parentFilter, logger);
75 <            udpReader.start();
76 <            logger.write(toString, Logger.SYSINIT, "Filter UDP listener started");
53 >        Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME);
54 >        if (config == null) {
55 >            System.err.println("CRITICAL:Unable to obtain configuration" +
56 >                               "\n         Advise you check the i-scream log for more information.");
57 >            _logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration");
58 >            System.exit(1);
59 >        } else {
60 >            try {
61 >                UDPListenPort = Integer.parseInt(config.getProperty("Filter.UDPListenPort"));
62 >                TCPListenPort = Integer.parseInt(config.getProperty("Filter.TCPListenPort"));
63 >                parentFilterName = config.getProperty("Filter.parentFilter");
64 >            } catch (org.omg.CORBA.MARSHAL e) {
65 >                System.err.println ("CRITICAL:Unable to obtain required configuration property" +
66 >                                    "\n         Advise you check the i-scream log for more information.");
67 >                _logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present");
68 >                System.exit(1);
69 >            }
70 >        }
71 >        _logger.write(toString(), Logger.SYSINIT, "configured");
72 >        
73 >        // get parent
74 >        Filter parentFilter = FilterHelper.narrow(_refman.getCORBARef("iscream.Filter." + parentFilterName));
75 >        
76 >        // setup a queue
77 >        Queue queue = new Queue();
78 >        
79 >        // Start a filter thread
80 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter Thread / Queue consumer");
81 >        FilterThread filterThread = new FilterThread(queue, parentFilter);
82 >        filterThread.start();
83 >        
84 >        // FilterServant start (for inbound child filter data)
85 >        _logger.write(toString(), Logger.DEBUG, "starting Filter Child -> Parent link for upstream parent - " + parentFilterName);
86 >        FilterServant filterServant = new FilterServant(TCPListenPort, UDPListenPort, queue);
87 >        _refman.bindToOrb(filterServant, "iscream.Filter." + FilterMain.NAME);
88  
89 <            logger.write(toString, Logger.SYSINIT, "starting Filter TCP listener");
90 <            TCPReader tcpReader = new TCPReader(logger, configManager, TCPport, parentFilter);
91 <            tcpReader.start();
92 <            logger.write(toString, Logger.SYSINIT, "Filter TCP listener started");
89 >        // UDL Reader start (for inbound host data)
90 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter UDP listener");
91 >        UDPReader udpReader = new UDPReader(UDPListenPort, queue);
92 >        udpReader.start();
93  
94 <            // TEST
95 <            //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>");
96 <            
97 <            // start the POA off
98 <            poa.the_POAManager().activate();
99 <                        
161 <            logger.write(toString, Logger.SYSINIT, "started");
162 <            
163 <            // now we are running, we just need to serve
164 <            // so we ask the orb to block for us until it has finished
165 <            orb.run();
166 <            
167 <        } catch (Exception e) {
168 <            System.err.println("FILTER ERROR: " + e);
169 <            e.printStackTrace(System.out);
170 <        }
94 >        // TCP Reader start (for heartbeats)
95 >        _logger.write(toString(), Logger.SYSINIT, "starting Filter TCP listener");
96 >        TCPReader tcpReader = new TCPReader(TCPListenPort, queue);
97 >        tcpReader.start();
98 >        
99 >        _logger.write(toString(), Logger.SYSINIT, "started");
100      }
101  
102 <    /**
103 <     * A simple method to print the usage of this class.
104 <     * It never returns, but instead exits to the system
105 <     * with a value 1, to indicate the system did not start
106 <     * properly.
102 >    /**
103 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
104 >     * method to provide clean logging (every class should have this).
105 >     *
106 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
107 >     * to format the toString()
108 >     *
109 >     * @return the name of this class and its CVS revision
110       */
111 <    public static void usage() {
112 <        System.out.println("USAGE: java FilterMain <name>");
113 <        System.out.println("WHERE <name>:");
114 <        System.out.println("      The unique identifier for the Filter in the system.");
115 <        System.exit(1);
111 >    public String toString() {
112 >        return FormatName.getName(
113 >            NAME,
114 >            getClass().getName(),
115 >            REVISION);
116      }
117  
186 //---CONSTRUCTORS---
187
188 //---PUBLIC METHODS---
189
118   //---PRIVATE METHODS---
119  
120   //---ACCESSOR/MUTATOR METHODS---
121  
122   //---ATTRIBUTES---
123  
124 +    /**
125 +     * This holds a reference to the
126 +     * system logger that is being used.
127 +     */
128 +    private Logger _logger = ReferenceManager.getInstance().getLogger();
129 +
130 +    /**
131 +     * A reference to the reference manager in use
132 +     */
133 +    private ReferenceManager _refman = ReferenceManager.getInstance();
134 +
135   //---STATIC ATTRIBUTES---
136 +
137 +    /**
138 +     * The friendly name for this component, used by
139 +     * all related classes.
140 +     * This is set from the configuration.
141 +     */
142 +    public static String NAME;
143  
144   }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines