ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/rootfilter/RootFilter.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/rootfilter/RootFilter.java (file contents):
Revision 1.3 by tdb, Wed Nov 29 19:33:35 2000 UTC vs.
Revision 1.15 by tdb, Tue Jan 2 03:19:37 2001 UTC

# Line 2 | Line 2
2   package uk.ac.ukc.iscream.rootfilter;
3  
4   //---IMPORTS---
5 + import uk.ac.ukc.iscream.util.*;
6   import uk.ac.ukc.iscream.core.*;
7 < import uk.ac.ukc.iscream.filter.*;
7 < import org.omg.CORBA.*;
8 < import org.omg.CosNaming.*;
9 < import org.omg.PortableServer.*;
7 > import uk.ac.ukc.iscream.clientinterface.*;
8  
9   /**
10 < * A RootFilter Startup Class
10 > * The root filter is what all filters talk to
11 > * Hosts cannot talk to this implementation of a filter.
12 > * It provides hooks to all data interfaces for the system
13 > * namely the client interface and the db interface.
14 > * This is an i-scream component that starts the
15 > * RootFilter services.
16   *
17   * @author  $Author$
18   * @version $Id$
19   */
20 < class RootFilterMain {
20 > public class RootFilter implements uk.ac.ukc.iscream.util.Component {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 22 | Line 25 | class RootFilterMain {
25       * The current CVS revision of this class
26       */
27      public static final String REVISION = "$Revision$";
28 <    
28 >
29   //---STATIC METHODS---
30  
31 <    public static void main(String[] args) {
32 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
33 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
31 > //---CONSTRUCTORS---
32 >
33 > //---PUBLIC METHODS---
34 >
35 >    /**
36 >     * This starts the Root Filter for the system
37 >     */
38 >    public void start() throws ComponentStartException {
39 >
40 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
41 >            
42 >        // configuration variables we require
43 >        String ourName = null;
44 >        String realInterface = null;
45 >        String dbInterface = null;
46          
47 <        // get our name from the command line
48 <        String ourName = "";
49 <        if (args.length == 1) {
50 <            ourName = args[0];
47 >        Configuration config = _refman.getCM().getConfiguration("RootFilter");
48 >        if (config == null) {
49 >            System.err.println("CRITICAL:Unable to obtain configuration" +
50 >                               "\n         Advise you check the i-scream log for more information.");
51 >            _logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration");
52 >            System.exit(1);
53 >        } else {
54 >            try {
55 >                ourName = config.getProperty("RootFilter.name");
56 >                realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
57 >                dbInterface = config.getProperty("RootFilter.dbInterfaceName");
58 >            } catch (org.omg.CORBA.MARSHAL e) {
59 >                System.err.println ("CRITICAL:Unable to obtain required configuration property" +
60 >                                    "\n         Advise you check the i-scream log for more information.");
61 >                _logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present");
62 >                System.exit(1);
63 >            }
64          }
65 <        else {
66 <            usage();
65 >        // now we have the name of the Root Filter we set it
66 >        NAME = ourName;
67 >        
68 >        _logger.write(toString(), Logger.SYSINIT, "configured");
69 >        
70 >        ClientInterface ciReal = null, ciDB = null;
71 >        // get reference to the client interfaces - the real time one
72 >        if (realInterface != null) {
73 >            ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
74          }
75 +        // get reference to the client interfaces - and the db one
76 +        if (dbInterface != null) {
77 +            ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
78 +        }
79          
80 <        // can't have a real toString() :)
42 <        String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
80 >        Queue queue = new Queue();
81          
82 <        try {        
83 <            ORB orb = ORB.init(args, null);
84 <            
85 <            // something to hold objects
86 <            org.omg.CORBA.Object objRef = null;    
87 <            
88 <            // get the Root POA
89 <            objRef = orb.resolve_initial_references("RootPOA");
90 <            POA poa = POAHelper.narrow(objRef);
91 <            
92 <            // get a hook to the name service
93 <            objRef = orb.resolve_initial_references("NameService");
94 <            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
95 <                
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"));
67 <            //FilterManager filterManager = FilterManagerHelper.narrow(objRef);
68 <            
69 <            logger.write(toString, Logger.SYSINIT, "coming up");
70 <            
71 <            
72 <            // **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG
73 <            // **** Please ignore this block of code, it's just "copy/paste" :)
74 <            
75 <            // get the config
76 <            Configuration myConfig = configManager.getConfiguration(ourName);
77 <                      
78 <            logger.write(toString, Logger.SYSINIT, "configured");
79 <            
80 <            // **** END COMMENT
81 <            
82 <            // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
83 <            
84 <            // **** END COMMENT
85 <            
86 <            logger.write(toString, Logger.SYSINIT, "starting RootFilter");
87 <            
88 <            /**************************************************************
89 <              Here would be an ideal place to start another thread to do
90 <              the listening part of the Filter. Ideally it should just be
91 <              created and then run(). It may be necessary to pass some of
92 <              the following parameters into the thread by the constructor.
93 <              
94 <                  Logger logger
95 <                      - a reference to a Logger object
96 <                  FilterManager filterManager
97 <                      - a reference to the system filter manager
98 <                  ConfigurationManager configManager
99 <                      - a reference to the system configuration manager
100 <                  Configuration myConfig
101 <                      - a reference to the configuration object for this
102 <                        filter instance
103 <                  String ourName
104 <                      - our "identifier" name
105 <            
106 <            **************************************************************/
107 <            
108 <            // NOTE:
109 <            //   We will not need to bind to the ORB when the FilterManager
110 <            //   is running :)
111 <            
112 <            // create the RootFilterServant
113 <            RootFilterServant rfServant = new RootFilterServant(logger, ourName);
114 <            
115 <            // and advertise it to the naming context
116 <            objRef = poa.servant_to_reference(rfServant);
117 <            ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef);
118 <            
119 <            // start the POA off
120 <            poa.the_POAManager().activate();
121 <                        
122 <            logger.write(toString, Logger.SYSINIT, "started");
123 <            
124 <            // now we are running, we just need to serve
125 <            // so we ask the orb to block for us until it has finished
126 <            orb.run();
127 <            
128 <        } catch (Exception e) {
129 <            System.err.println("FILTER ERROR: " + e);
130 <            e.printStackTrace(System.out);
82 >        if (realInterface == null) {        
83 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
84 >            CIWrapper c = new CIWrapper(ciDB, queue);
85 >            c.start();
86 >        } else if (dbInterface == null) {
87 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
88 >            CIWrapper c = new CIWrapper(ciReal, queue);
89 >            c.start();
90 >        } else {
91 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
92 >            CIWrapper c = new CIWrapper(ciReal, queue);
93 >            c.start();
94 >            c = new CIWrapper(ciDB, queue);
95 >            c.start();
96          }
97 +                
98 +        // RootFilterServant start (for inbound child filter data)
99 +        _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
100 +        RootFilterServant filterServant = new RootFilterServant(queue);
101 +        // bind to the naming service as a filter
102 +        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
103 +        
104 +        _logger.write(toString(), Logger.SYSINIT, "started");
105      }
106 <
107 <    /**
108 <     * A simple method to print the usage of this class.
109 <     * It never returns, but instead exits to the system
110 <     * with a value 1, to indicate the system did not start
111 <     * properly.
106 >    
107 >    /**
108 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
109 >     * method to provide clean logging (every class should have this).
110 >     *
111 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
112 >     * to format the toString()
113 >     *
114 >     * @return the name of this class and its CVS revision
115       */
116 <    public static void usage() {
117 <        System.out.println("USAGE: java RootFilter <name>");
118 <        System.out.println("WHERE <name>:");
119 <        System.out.println("      The unique identifier for the RootFilter in the system.");
120 <        System.exit(1);
116 >    public String toString() {
117 >        return FormatName.getName(
118 >            NAME,
119 >            getClass().getName(),
120 >            REVISION);
121      }
122  
147 //---CONSTRUCTORS---
148
149 //---PUBLIC METHODS---
150
123   //---PRIVATE METHODS---
124  
125   //---ACCESSOR/MUTATOR METHODS---
126  
127   //---ATTRIBUTES---
128  
129 +    /**
130 +     * This holds a reference to the
131 +     * system logger that is being used.
132 +     */
133 +    private Logger _logger = ReferenceManager.getInstance().getLogger();
134 +
135 +    /**
136 +     * A reference to the reference manager in use
137 +     */
138 +    private ReferenceManager _refman = ReferenceManager.getInstance();
139 +
140   //---STATIC ATTRIBUTES---
141 +
142 +    /**
143 +     * The friendly name for this component, used by
144 +     * all related classes.
145 +     * This is set from the configuration.
146 +     */
147 +    public static String NAME;
148  
149 < }            
149 > }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines