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.8 by ajm, Mon Dec 4 18:12:13 2000 UTC vs.
Revision 1.32 by tdb, Wed Mar 14 23:25:29 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.util.*;
7 < import uk.ac.ukc.iscream.core.*;
8 < import uk.ac.ukc.iscream.clientinterface.*;
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 Filter 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 20 | 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) {
27 <        // ***************************************
28 <        // VERY TEMPORARY - will find a better way
29 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
30 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
31 <        // ***************************************
33 > //---CONSTRUCTORS---
34  
35 <        ReferenceManager refman = ReferenceManager.init(null, null);
34 <        
35 <        // can't have a real toString() :)
36 <        String toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
35 > //---PUBLIC METHODS---
36  
37 <        refman.getLogger().write(toString, Logger.SYSINIT, "coming up");
38 <            
39 <        // configuration variables we require
40 <        String ourName = null;
41 <        String realInterface = null;
42 <        String dbInterface = null;
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 <        Configuration config = refman.getCM().getConfiguration("RootFilter");
45 <        if (config == null) {
46 <            throw new RuntimeException ("CRITICAL:Unable to obtain configuration" +
47 <                                        "         Advise you check the i-scream log for more information.");
48 <        } else {
49 <            try {
50 <                ourName = config.getProperty("RootFilter.name");
51 <                realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
52 <                dbInterface = config.getProperty("RootFilter.dbInterfaceName");
53 <            } catch (org.omg.CORBA.MARSHAL e) {
54 <                refman.getLogger().write(toString, Logger.FATAL, "required config property not present");
56 <                throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" +
57 <                                            "         Advise you check the i-scream log for more information.");
58 <
59 <            }
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 <        // now we have the name of the Root Filter we set it
57 <        refman.setName(ourName);
58 <        toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
59 <        refman.getLogger().write(toString, Logger.SYSINIT, "configured");
60 <                
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 >        ClientInterface ciReal = null, ciDB = null;
69          // get reference to the client interfaces - the real time one
70 <        ClientInterface ciReal = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + realInterface));
71 <        // - the db one ... but it's not done yet
72 <        //ClientInterface ciDB = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + dbInterface));
73 <        // so for the time being we null it.
74 <        ClientInterface ciDB = null;
75 <        refman.getLogger().write(toString, Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
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 >        // setup a queue
79 >        Queue queue = new Queue();
80          
81 <        ClientInterface[] clientInterfaces = {ciReal, ciDB};
81 >        // startup a monitor on this queue
82 >        try {
83 >            // try to get the interval, if this fails, we won't start up the monitor
84 >            int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval"));
85 >            String queueName = NAME + " RootFilter";
86 >            queue.startMonitor(queueMonitorInterval*1000, queueName);
87 >        } catch (PropertyNotFoundException e) {
88 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
89 >        }
90          
91 +        if (realInterface == null) {        
92 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
93 +            CIWrapper c = new CIWrapper(ciDB, queue);
94 +            c.start();
95 +        } else if (dbInterface == null) {
96 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
97 +            CIWrapper c = new CIWrapper(ciReal, queue);
98 +            c.start();
99 +        } else {
100 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
101 +            CIWrapper c = new CIWrapper(ciReal, queue);
102 +            c.start();
103 +            c = new CIWrapper(ciDB, queue);
104 +            c.start();
105 +        }
106 +                
107          // RootFilterServant start (for inbound child filter data)
108 <        refman.getLogger().write(toString, Logger.DEBUG, "starting Root Filter");
109 <        RootFilterServant filterServant = new RootFilterServant(clientInterfaces);
108 >        _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
109 >        RootFilterServant filterServant = new RootFilterServant(queue);
110          // bind to the naming service as a filter
111 <        refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName());
111 >        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
112          
113 <        // start the POA off
114 <        // now we are running, we just need to serve
84 <        // so we ask the orb to block for us until it has finished
85 <        refman.activatePOA();
86 <        refman.getLogger().write(toString, Logger.SYSINIT, "started");
87 <        refman.getORB().run();
113 >        _logger.write(toString(), Logger.SYSINIT, "started");
114 >        
115      }
116 <
117 <    /**
118 <     * A simple method to print the usage of this class.
119 <     * It never returns, but instead exits to the system
120 <     * with a value 1, to indicate the system did not start
121 <     * properly.
116 >    
117 >    /**
118 >     * Does a dependency check. Used mainly at startup to
119 >     * see if the required dependencies (components) are up
120 >     * and running.
121 >     *
122 >     * @return a boolean value, true if the depdencies are satisfied
123       */
124 <    public static void usage() {
125 <        System.out.println("USAGE: java FilterMain <name>");
126 <        System.out.println("WHERE <name>:");
127 <        System.out.println("      The unique identifier for the Filter in the system.");
128 <        System.exit(1);
124 >    public boolean depCheck() {
125 >        try {
126 >            org.omg.CORBA.Object obj;
127 >            // first check the ConfigurationManager is alive
128 >            obj = _refman.getCORBARef("iscream.ConfigurationManager");
129 >            // then get some info on the CLI and DBI
130 >            ConfigurationProxy cp = ConfigurationProxy.getInstance();
131 >            String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName");
132 >            String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName");
133 >            // finally check the CLI and DBI are alive
134 >            obj = _refman.getCORBARef("iscream.ClientInterface." + cli);
135 >            obj = _refman.getCORBARef("iscream.ClientInterface." + dbi);
136 >        } catch(ComponentCORBAException e) {
137 >            System.err.println(toString() + ": Dependency Failure: "+e);
138 >            return false;
139 >        } catch(PropertyNotFoundException e) {
140 >            System.err.println(toString() + ": Unable to obtain configuration: "+e);
141 >            return false;
142 >        }
143 >        // dependency check suceeded
144 >        return true;
145      }
146 +    
147 +    /**
148 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
149 +     * method to provide clean logging (every class should have this).
150 +     *
151 +     * This uses the uk.org.iscream.util.NameFormat class
152 +     * to format the toString()
153 +     *
154 +     * @return the name of this class and its CVS revision
155 +     */
156 +    public String toString() {
157 +        return FormatName.getName(
158 +            NAME,
159 +            getClass().getName(),
160 +            REVISION);
161 +    }
162  
103 //---CONSTRUCTORS---
104
105 //---PUBLIC METHODS---
106
163   //---PRIVATE METHODS---
164  
165   //---ACCESSOR/MUTATOR METHODS---
166  
167   //---ATTRIBUTES---
168  
169 +    /**
170 +     * This holds a reference to the
171 +     * system logger that is being used.
172 +     */
173 +    private Logger _logger;
174 +
175 +    /**
176 +     * A reference to the reference manager in use
177 +     */
178 +    private ReferenceManager _refman = ReferenceManager.getInstance();
179 +
180   //---STATIC ATTRIBUTES---
181 +
182 +    /**
183 +     * The friendly name for this component, used by
184 +     * all related classes.
185 +     * This is set from the configuration.
186 +     */
187 +    public static String NAME;
188  
189   }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines