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.29 by tdb, Wed Mar 14 01:34:34 2001 UTC

# Line 1 | Line 1
1 +
2   //---PACKAGE DECLARATION---
3   package uk.ac.ukc.iscream.rootfilter;
4  
5   //---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.*;
6   import uk.ac.ukc.iscream.util.*;
7 + import uk.ac.ukc.iscream.core.*;
8 + import uk.ac.ukc.iscream.componentmanager.*;
9 + import uk.ac.ukc.iscream.clientinterface.*;
10  
11   /**
12 < * A RootFilter Startup Class
12 > * The root filter is what all filters talk to
13 > * Hosts cannot talk to this implementation of a filter.
14 > * It provides hooks to all data interfaces for the system
15 > * namely the client interface and the db interface.
16 > * This is an i-scream component that starts the
17 > * RootFilter services.
18   *
19   * @author  $Author$
20   * @version $Id$
21   */
22 < class RootFilterMain {
22 > public class RootFilter implements Component {
23  
24   //---FINAL ATTRIBUTES---
25  
# Line 23 | Line 27 | class RootFilterMain {
27       * The current CVS revision of this class
28       */
29      public static final String REVISION = "$Revision$";
30 <    
30 >
31   //---STATIC METHODS---
32  
33 <    public static void main(String[] args) {
34 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
35 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
33 > //---CONSTRUCTORS---
34 >
35 > //---PUBLIC METHODS---
36 >
37 >    /**
38 >     * This starts the Root Filter for the system
39 >     */
40 >    public void start() throws ComponentStartException {
41 >        // get references to key objects
42 >        _refman = ReferenceManager.getInstance();
43 >        _logger = ReferenceManager.getInstance().getLogger();
44          
45 <        // get our name from the command line
46 <        String ourName = "";
47 <        if (args.length == 1) {
48 <            ourName = args[0];
45 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
46 >        
47 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
48 >        String configName = "RootFilter";
49 >        
50 >        // set the name of the root filter
51 >        try {
52 >            NAME = cp.getProperty(configName, "RootFilter.name");
53 >        } catch (PropertyNotFoundException e) {
54 >            NAME = null;
55 >            _logger.write(toString(), Logger.WARNING, "RootFilter name not set: "+e);
56          }
57 <        else {
58 <            usage();
57 >        
58 >        // try and get the names of the ciReal and ciDB
59 >        String realInterface, dbInterface;
60 >        try {
61 >            realInterface = cp.getProperty(configName, "RootFilter.realtimeInterfaceName");
62 >            dbInterface = cp.getProperty(configName, "RootFilter.dbInterfaceName");
63 >        } catch (PropertyNotFoundException e) {
64 >            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
65 >            realInterface = null;
66 >            dbInterface = null;
67          }
68          
69 <        // can't have a real toString() :)
70 <        String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
69 >        ClientInterface ciReal = null, ciDB = null;
70 >        // get reference to the client interfaces - the real time one
71 >        if (realInterface != null) {
72 >            ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
73 >        }
74 >        // get reference to the client interfaces - and the db one
75 >        if (dbInterface != null) {
76 >            ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
77 >        }
78 >
79 >        // setup a queue
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);
82 >        // startup a monitor on this queue
83 >        try {
84 >            // try to get the interval, if this fails, we won't start up the monitor
85 >            int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval"));
86 >            String queueName = NAME + " RootFilter";
87 >            queue.startMonitor(queueMonitorInterval*1000, queueName);
88 >        } catch (PropertyNotFoundException e) {
89 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
90 >        }
91 >        
92 >        if (realInterface == null) {        
93 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
94 >            CIWrapper c = new CIWrapper(ciDB, queue);
95 >            c.start();
96 >        } else if (dbInterface == null) {
97 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
98 >            CIWrapper c = new CIWrapper(ciReal, queue);
99 >            c.start();
100 >        } else {
101 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
102 >            CIWrapper c = new CIWrapper(ciReal, queue);
103 >            c.start();
104 >            c = new CIWrapper(ciDB, queue);
105 >            c.start();
106 >        }
107                  
108 <            // get a ref to the ConfigurationManager, Logger & the FilterManager
109 <            
110 <            objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager"));
111 <            ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef);
112 <            
113 <            objRef = ncRef.resolve(ncRef.to_name("iscream.Logger"));
114 <            Logger logger = LoggerHelper.narrow(objRef);
115 <            
116 <            //objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager"));
117 <            //FilterManager filterManager = FilterManagerHelper.narrow(objRef);
118 <            
119 <            logger.write(toString, Logger.SYSINIT, "coming up");
120 <            
121 <            
122 <            // **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG
123 <            // **** Please ignore this block of code, it's just "copy/paste" :)
124 <            
125 <            // get the config
126 <            Configuration myConfig = configManager.getConfiguration(ourName);
127 <                      
128 <            logger.write(toString, Logger.SYSINIT, "configured");
129 <            
130 <            // **** END COMMENT
131 <            
132 <            // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
133 <            
134 <            // **** END COMMENT
135 <            
136 <            logger.write(toString, Logger.SYSINIT, "starting RootFilter");
137 <            
138 <            /**************************************************************
139 <              Here would be an ideal place to start another thread to do
140 <              the listening part of the Filter. Ideally it should just be
141 <              created and then run(). It may be necessary to pass some of
142 <              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);
108 >        // RootFilterServant start (for inbound child filter data)
109 >        _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
110 >        RootFilterServant filterServant = new RootFilterServant(queue);
111 >        // bind to the naming service as a filter
112 >        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
113 >        
114 >        _logger.write(toString(), Logger.SYSINIT, "started");
115 >        
116 >    }
117 >    
118 >    /**
119 >     * Does a dependency check. Used mainly at startup to
120 >     * see if the required dependencies (components) are up
121 >     * and running.
122 >     *
123 >     * @return a boolean value, true if the depdencies are satisfied
124 >     */
125 >    public boolean depCheck() {
126 >        try {
127 >            org.omg.CORBA.Object obj;
128 >            // first check the ConfigurationManager is alive
129 >            obj = _refman.getCORBARef("iscream.ConfigurationManager");
130 >            // then get some info on the CLI and DBI
131 >            ConfigurationProxy cp = ConfigurationProxy.getInstance();
132 >            String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName");
133 >            String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName");
134 >            // finally check the CLI and DBI are alive
135 >            obj = _refman.getCORBARef("iscream.ClientInterface." + cli);
136 >            obj = _refman.getCORBARef("iscream.ClientInterface." + dbi);
137 >        } catch(ComponentCORBAException e) {
138 >            _logger.write(toString(), Logger.WARNING, "Dependency Failure: "+e);
139 >            return false;
140 >        } catch(PropertyNotFoundException e) {
141 >            _logger.write(toString(), Logger.WARNING, "Unable to obtain configuration: "+e);
142 >            return false;
143          }
144 +        // dependency check suceeded
145 +        return true;
146      }
147 <
148 <    /**
149 <     * A simple method to print the usage of this class.
150 <     * It never returns, but instead exits to the system
151 <     * with a value 1, to indicate the system did not start
152 <     * properly.
147 >    
148 >    /**
149 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
150 >     * method to provide clean logging (every class should have this).
151 >     *
152 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
153 >     * to format the toString()
154 >     *
155 >     * @return the name of this class and its CVS revision
156       */
157 <    public static void usage() {
158 <        System.out.println("USAGE: java RootFilter <name>");
159 <        System.out.println("WHERE <name>:");
160 <        System.out.println("      The unique identifier for the RootFilter in the system.");
161 <        System.exit(1);
157 >    public String toString() {
158 >        return FormatName.getName(
159 >            NAME,
160 >            getClass().getName(),
161 >            REVISION);
162      }
163  
148 //---CONSTRUCTORS---
149
150 //---PUBLIC METHODS---
151
164   //---PRIVATE METHODS---
165  
166   //---ACCESSOR/MUTATOR METHODS---
167  
168   //---ATTRIBUTES---
169  
170 +    /**
171 +     * This holds a reference to the
172 +     * system logger that is being used.
173 +     */
174 +    private Logger _logger;
175 +
176 +    /**
177 +     * A reference to the reference manager in use
178 +     */
179 +    private ReferenceManager _refman;
180 +
181   //---STATIC ATTRIBUTES---
182 +
183 +    /**
184 +     * The friendly name for this component, used by
185 +     * all related classes.
186 +     * This is set from the configuration.
187 +     */
188 +    public static String NAME;
189  
190 < }            
190 > }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines