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.33 by tdb, Fri Mar 16 15:16:01 2001 UTC

# Line 1 | Line 1
1 +
2   //---PACKAGE DECLARATION---
3 < package uk.ac.ukc.iscream.rootfilter;
3 > package uk.org.iscream.rootfilter;
4  
5   //---IMPORTS---
6 < import uk.ac.ukc.iscream.core.*;
7 < import uk.ac.ukc.iscream.filter.*;
8 < import org.omg.CORBA.*;
9 < import org.omg.CosNaming.*;
9 < import org.omg.PortableServer.*;
10 < import uk.ac.ukc.iscream.util.*;
6 > import uk.org.iscream.util.*;
7 > import uk.org.iscream.core.*;
8 > import uk.org.iscream.componentmanager.*;
9 > import uk.org.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 >        _logger = _refman.getLogger();
43          
44 <        // get our name from the command line
45 <        String ourName = "";
46 <        if (args.length == 1) {
47 <            ourName = args[0];
44 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
45 >        
46 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
47 >        String configName = "RootFilter";
48 >        
49 >        // set the name of the root filter
50 >        try {
51 >            NAME = cp.getProperty(configName, "RootFilter.name");
52 >        } catch (PropertyNotFoundException e) {
53 >            NAME = null;
54 >            _logger.write(toString(), Logger.WARNING, "RootFilter name not set: "+e);
55          }
56 <        else {
57 <            usage();
56 >        
57 >        // try and get the names of the ciReal and ciDB
58 >        String realInterface, dbInterface;
59 >        try {
60 >            realInterface = cp.getProperty(configName, "RootFilter.realtimeInterfaceName");
61 >            dbInterface = cp.getProperty(configName, "RootFilter.dbInterfaceName");
62 >        } catch (PropertyNotFoundException e) {
63 >            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
64 >            realInterface = null;
65 >            dbInterface = null;
66          }
67          
68 <        // can't have a real toString() :)
69 <        String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
68 >        ClientInterface ciReal = null, ciDB = null;
69 >        // get reference to the client interfaces - the real time one
70 >        if (realInterface != null) {
71 >            ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
72 >        }
73 >        // get reference to the client interfaces - and the db one
74 >        if (dbInterface != null) {
75 >            ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
76 >        }
77          
78 <        try {        
79 <            ORB orb = ORB.init(args, null);
78 >        // setup a queue
79 >        Queue queue;
80 >        // see if this Queue needs a size limit
81 >        try {
82 >            int queueSizeLimit = Integer.parseInt(cp.getProperty(configName, "Queue.SizeLimit"));
83 >            String queueRemoveAlgorithm = cp.getProperty(configName, "Queue.RemoveAlgorithm");
84 >            int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms);
85 >            if(algorithm != -1) {
86 >                queue = new Queue(queueSizeLimit, algorithm);
87 >            }
88 >            else {
89 >                _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
90 >                // just don't activate a limit
91 >                queue = new Queue();
92 >            }
93              
94 <            // something to hold objects
95 <            org.omg.CORBA.Object objRef = null;    
96 <            
97 <            // get the Root POA
98 <            objRef = orb.resolve_initial_references("RootPOA");
99 <            POA poa = POAHelper.narrow(objRef);
100 <            
101 <            // get a hook to the name service
102 <            objRef = orb.resolve_initial_references("NameService");
103 <            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
94 >        } catch (PropertyNotFoundException e) {
95 >            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
96 >            // just don't activate a limit
97 >            queue = new Queue();
98 >        } catch (NumberFormatException e) {
99 >            _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
100 >            // just don't activate a limit
101 >            queue = new Queue();
102 >        }
103 >        
104 >        // startup a monitor on this queue
105 >        try {
106 >            // try to get the interval, if this fails, we won't start up the monitor
107 >            int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval"));
108 >            String queueName = NAME + " RootFilter";
109 >            queue.startMonitor(queueMonitorInterval*1000, queueName);
110 >        } catch (PropertyNotFoundException e) {
111 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
112 >        }
113 >        
114 >        if (realInterface == null) {        
115 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
116 >            CIWrapper c = new CIWrapper(ciDB, queue);
117 >            c.start();
118 >        } else if (dbInterface == null) {
119 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
120 >            CIWrapper c = new CIWrapper(ciReal, queue);
121 >            c.start();
122 >        } else {
123 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
124 >            CIWrapper c = new CIWrapper(ciReal, queue);
125 >            c.start();
126 >            c = new CIWrapper(ciDB, queue);
127 >            c.start();
128 >        }
129                  
130 <            // get a ref to the ConfigurationManager, Logger & the FilterManager
131 <            
132 <            objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager"));
133 <            ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef);
134 <            
135 <            objRef = ncRef.resolve(ncRef.to_name("iscream.Logger"));
136 <            Logger logger = LoggerHelper.narrow(objRef);
137 <            
138 <            //objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager"));
139 <            //FilterManager filterManager = FilterManagerHelper.narrow(objRef);
140 <            
141 <            logger.write(toString, Logger.SYSINIT, "coming up");
142 <            
143 <            
144 <            // **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG
145 <            // **** Please ignore this block of code, it's just "copy/paste" :)
146 <            
147 <            // get the config
148 <            Configuration myConfig = configManager.getConfiguration(ourName);
149 <                      
150 <            logger.write(toString, Logger.SYSINIT, "configured");
151 <            
152 <            // **** END COMMENT
153 <            
154 <            // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
155 <            
156 <            // **** END COMMENT
157 <            
158 <            logger.write(toString, Logger.SYSINIT, "starting RootFilter");
159 <            
160 <            /**************************************************************
161 <              Here would be an ideal place to start another thread to do
162 <              the listening part of the Filter. Ideally it should just be
163 <              created and then run(). It may be necessary to pass some of
164 <              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);
130 >        // RootFilterServant start (for inbound child filter data)
131 >        _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
132 >        RootFilterServant filterServant = new RootFilterServant(queue);
133 >        // bind to the naming service as a filter
134 >        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
135 >        
136 >        _logger.write(toString(), Logger.SYSINIT, "started");
137 >        
138 >    }
139 >    
140 >    /**
141 >     * Does a dependency check. Used mainly at startup to
142 >     * see if the required dependencies (components) are up
143 >     * and running.
144 >     *
145 >     * @return a boolean value, true if the depdencies are satisfied
146 >     */
147 >    public boolean depCheck() {
148 >        try {
149 >            org.omg.CORBA.Object obj;
150 >            // first check the ConfigurationManager is alive
151 >            obj = _refman.getCORBARef("iscream.ConfigurationManager");
152 >            // then get some info on the CLI and DBI
153 >            ConfigurationProxy cp = ConfigurationProxy.getInstance();
154 >            String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName");
155 >            String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName");
156 >            // finally check the CLI and DBI are alive
157 >            obj = _refman.getCORBARef("iscream.ClientInterface." + cli);
158 >            obj = _refman.getCORBARef("iscream.ClientInterface." + dbi);
159 >        } catch(ComponentCORBAException e) {
160 >            System.err.println(toString() + ": Dependency Failure: "+e);
161 >            return false;
162 >        } catch(PropertyNotFoundException e) {
163 >            System.err.println(toString() + ": Unable to obtain configuration: "+e);
164 >            return false;
165          }
166 +        // dependency check suceeded
167 +        return true;
168      }
169 <
170 <    /**
171 <     * A simple method to print the usage of this class.
172 <     * It never returns, but instead exits to the system
173 <     * with a value 1, to indicate the system did not start
174 <     * properly.
169 >    
170 >    /**
171 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
172 >     * method to provide clean logging (every class should have this).
173 >     *
174 >     * This uses the uk.org.iscream.util.NameFormat class
175 >     * to format the toString()
176 >     *
177 >     * @return the name of this class and its CVS revision
178       */
179 <    public static void usage() {
180 <        System.out.println("USAGE: java RootFilter <name>");
181 <        System.out.println("WHERE <name>:");
182 <        System.out.println("      The unique identifier for the RootFilter in the system.");
183 <        System.exit(1);
179 >    public String toString() {
180 >        return FormatName.getName(
181 >            NAME,
182 >            getClass().getName(),
183 >            REVISION);
184      }
185  
148 //---CONSTRUCTORS---
149
150 //---PUBLIC METHODS---
151
186   //---PRIVATE METHODS---
187  
188   //---ACCESSOR/MUTATOR METHODS---
189  
190   //---ATTRIBUTES---
191  
192 +    /**
193 +     * This holds a reference to the
194 +     * system logger that is being used.
195 +     */
196 +    private Logger _logger;
197 +
198 +    /**
199 +     * A reference to the reference manager in use
200 +     */
201 +    private ReferenceManager _refman = ReferenceManager.getInstance();
202 +
203   //---STATIC ATTRIBUTES---
204 +
205 +    /**
206 +     * The friendly name for this component, used by
207 +     * all related classes.
208 +     * This is set from the configuration.
209 +     */
210 +    public static String NAME;
211  
212 < }            
212 > }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines