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.4 by tdb, Thu Nov 30 02:42:56 2000 UTC vs.
Revision 1.11 by ajm, Tue Dec 12 20:44:03 2000 UTC

# Line 2 | Line 2
2   package uk.ac.ukc.iscream.rootfilter;
3  
4   //---IMPORTS---
5 import uk.ac.ukc.iscream.core.*;
6 import uk.ac.ukc.iscream.filter.*;
7 import org.omg.CORBA.*;
8 import org.omg.CosNaming.*;
9 import org.omg.PortableServer.*;
5   import uk.ac.ukc.iscream.util.*;
6 + import uk.ac.ukc.iscream.core.*;
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 23 | 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();
40 <        }
65 >        // now we have the name of the Root Filter we set it
66 >        NAME = ourName;
67          
68 <        // can't have a real toString() :)
43 <        String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
44 <        
45 <        try {        
46 <            ORB orb = ORB.init(args, null);
47 <            
48 <            // something to hold objects
49 <            org.omg.CORBA.Object objRef = null;    
50 <            
51 <            // get the Root POA
52 <            objRef = orb.resolve_initial_references("RootPOA");
53 <            POA poa = POAHelper.narrow(objRef);
54 <            
55 <            // get a hook to the name service
56 <            objRef = orb.resolve_initial_references("NameService");
57 <            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
68 >        _logger.write(toString(), Logger.SYSINIT, "configured");
69                  
70 <            // get a ref to the ConfigurationManager, Logger & the FilterManager
71 <            
72 <            objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager"));
62 <            ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef);
63 <            
64 <            objRef = ncRef.resolve(ncRef.to_name("iscream.Logger"));
65 <            Logger logger = LoggerHelper.narrow(objRef);
66 <            
67 <            //objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager"));
68 <            //FilterManager filterManager = FilterManagerHelper.narrow(objRef);
69 <            
70 <            logger.write(toString, Logger.SYSINIT, "coming up");
71 <            
72 <            
73 <            // **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG
74 <            // **** Please ignore this block of code, it's just "copy/paste" :)
75 <            
76 <            // get the config
77 <            Configuration myConfig = configManager.getConfiguration(ourName);
78 <                      
79 <            logger.write(toString, Logger.SYSINIT, "configured");
80 <            
81 <            // **** END COMMENT
82 <            
83 <            // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
84 <            
85 <            // **** END COMMENT
86 <            
87 <            logger.write(toString, Logger.SYSINIT, "starting RootFilter");
88 <            
89 <            /**************************************************************
90 <              Here would be an ideal place to start another thread to do
91 <              the listening part of the Filter. Ideally it should just be
92 <              created and then run(). It may be necessary to pass some of
93 <              the following parameters into the thread by the constructor.
94 <              
95 <                  Logger logger
96 <                      - a reference to a Logger object
97 <                  FilterManager filterManager
98 <                      - a reference to the system filter manager
99 <                  ConfigurationManager configManager
100 <                      - a reference to the system configuration manager
101 <                  Configuration myConfig
102 <                      - a reference to the configuration object for this
103 <                        filter instance
104 <                  String ourName
105 <                      - our "identifier" name
106 <            
107 <            **************************************************************/
108 <            
109 <            // NOTE:
110 <            //   We will not need to bind to the ORB when the FilterManager
111 <            //   is running :)
112 <            
113 <            // create the RootFilterServant
114 <            RootFilterServant rfServant = new RootFilterServant(logger, ourName);
115 <            
116 <            // and advertise it to the naming context
117 <            objRef = poa.servant_to_reference(rfServant);
118 <            ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef);
119 <            
120 <            // start the POA off
121 <            poa.the_POAManager().activate();
122 <                        
123 <            logger.write(toString, Logger.SYSINIT, "started");
124 <            
125 <            // now we are running, we just need to serve
126 <            // so we ask the orb to block for us until it has finished
127 <            orb.run();
128 <            
129 <        } catch (Exception e) {
130 <            System.err.println("FILTER ERROR: " + e);
131 <            e.printStackTrace(System.out);
70 >        // get reference to the client interfaces - the real time one
71 >        if (realInterface != null) {
72 >            ClientInterface ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
73          }
74 <    }
74 >        // get reference to the client interfaces - and the db one
75 >        if (dbInterface != null) {
76 >            ClientInterface ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
77 >        }
78  
79 <    /**
80 <     * A simple method to print the usage of this class.
81 <     * It never returns, but instead exits to the system
82 <     * with a value 1, to indicate the system did not start
83 <     * properly.
79 >        ClientInterface[] clientInterfaces;
80 >        if (realInterface == null) {        
81 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
82 >            clientInterfaces = {ciReal, ciDB};
83 >        } else if (dbInterface == null) {
84 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
85 >            clientInterfaces = {ciReal};
86 >        } else {
87 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
88 >            clientInterfaces = {ciReal, ciDB};
89 >        }
90 >        
91 >        // RootFilterServant start (for inbound child filter data)
92 >        _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
93 >        RootFilterServant filterServant = new RootFilterServant(clientInterfaces);
94 >        // bind to the naming service as a filter
95 >        _refman.bindToOrb(filterServant, "iscream.Filter." + _name);
96 >        
97 >        _logger.write(toString(), Logger.SYSINIT, "started");
98 >    }
99 >    
100 >    /**
101 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
102 >     * method to provide clean logging (every class should have this).
103 >     *
104 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
105 >     * to format the toString()
106 >     *
107 >     * @return the name of this class and its CVS revision
108       */
109 <    public static void usage() {
110 <        System.out.println("USAGE: java RootFilter <name>");
111 <        System.out.println("WHERE <name>:");
112 <        System.out.println("      The unique identifier for the RootFilter in the system.");
113 <        System.exit(1);
109 >    public String toString() {
110 >        return FormatName.getName(
111 >            _name,
112 >            getClass().getName(),
113 >            REVISION);
114      }
115  
148 //---CONSTRUCTORS---
149
150 //---PUBLIC METHODS---
151
116   //---PRIVATE METHODS---
117  
118   //---ACCESSOR/MUTATOR METHODS---
119  
120   //---ATTRIBUTES---
121  
122 +    /**
123 +     * This is the friendly identifier of the
124 +     * component this class is running in.
125 +     * eg, a Filter may be called "filter1",
126 +     * If this class does not have an owning
127 +     * component,  a name from the configuration
128 +     * can be placed here.  This name could also
129 +     * be changed to null for utility classes.
130 +     */
131 +    private String _name = RootFilter.NAME;
132 +
133 +    /**
134 +     * This holds a reference to the
135 +     * system logger that is being used.
136 +     */
137 +    private Logger _logger = ReferenceManager.getInstance().getLogger();
138 +
139 +    /**
140 +     * A reference to the reference manager in use
141 +     */
142 +    private ReferenceManager _refman = ReferenceManager.getInstance();
143 +
144   //---STATIC ATTRIBUTES---
145 +
146 +    /**
147 +     * The friendly name for this component, used by
148 +     * all related classes.
149 +     * This is set from the configuration.
150 +     */
151 +    public static String NAME;
152  
153 < }            
153 > }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines