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.26 by ajm, Fri Feb 23 17:08:50 2001 UTC

# Line 4 | Line 4 | package uk.ac.ukc.iscream.rootfilter;
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.util.*;
6   import uk.ac.ukc.iscream.core.*;
7 + import uk.ac.ukc.iscream.componentmanager.*;
8   import uk.ac.ukc.iscream.clientinterface.*;
9  
10   /**
11 < * A Filter Startup Class
11 > * The root filter is what all filters talk to
12 > * Hosts cannot talk to this implementation of a filter.
13 > * It provides hooks to all data interfaces for the system
14 > * namely the client interface and the db interface.
15 > * This is an i-scream component that starts the
16 > * RootFilter services.
17   *
18   * @author  $Author$
19   * @version $Id$
20   */
21 < class RootFilterMain {
21 > public class RootFilter implements Component {
22  
23   //---FINAL ATTRIBUTES---
24  
# Line 20 | Line 26 | class RootFilterMain {
26       * The current CVS revision of this class
27       */
28      public static final String REVISION = "$Revision$";
29 <    
29 >
30   //---STATIC METHODS---
31  
32 <    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 <        // ***************************************
32 > //---CONSTRUCTORS---
33  
34 <        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) + ")";
34 > //---PUBLIC METHODS---
35  
36 <        refman.getLogger().write(toString, Logger.SYSINIT, "coming up");
36 >    /**
37 >     * This starts the Root Filter for the system
38 >     */
39 >    public void start() throws ComponentStartException {
40 >        // get references to key objects
41 >        _refman = ReferenceManager.getInstance();
42 >        _logger = ReferenceManager.getInstance().getLogger();
43 >        
44 >        _logger.write(toString(), Logger.SYSINIT, "coming up");
45              
46          // configuration variables we require
47          String ourName = null;
48          String realInterface = null;
49          String dbInterface = null;
50 +        int queueMonitorInterval = 0;
51          
52 <        Configuration config = refman.getCM().getConfiguration("RootFilter");
52 >        Configuration config = _refman.getCM().getConfiguration("RootFilter");
53          if (config == null) {
54 <            throw new RuntimeException ("CRITICAL:Unable to obtain configuration" +
55 <                                        "         Advise you check the i-scream log for more information.");
56 <        } else {
54 >            throw new ComponentStartException("Unable to obtain configuration for component");
55 >        }
56 >        else {
57              try {
58 +                // get the configuration properties we need
59                  ourName = config.getProperty("RootFilter.name");
60                  realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
61                  dbInterface = config.getProperty("RootFilter.dbInterfaceName");
62 +                queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval"));
63              } catch (org.omg.CORBA.MARSHAL e) {
64 <                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 <
64 >                throw new ComponentStartException("Unable to obtain requried configuration property for component");
65              }
66          }
67 +        
68          // now we have the name of the Root Filter we set it
69 <        refman.setName(ourName);
70 <        toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
71 <        refman.getLogger().write(toString, Logger.SYSINIT, "configured");
72 <                
69 >        NAME = ourName;
70 >        
71 >        _logger.write(toString(), Logger.SYSINIT, "configured");
72 >        
73 >        ClientInterface ciReal = null, ciDB = null;
74          // get reference to the client interfaces - the real time one
75 <        ClientInterface ciReal = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + realInterface));
76 <        // - the db one ... but it's not done yet
77 <        //ClientInterface ciDB = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + dbInterface));
78 <        // so for the time being we null it.
79 <        ClientInterface ciDB = null;
80 <        refman.getLogger().write(toString, Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
75 >        if (realInterface != null) {
76 >            ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
77 >        }
78 >        // get reference to the client interfaces - and the db one
79 >        if (dbInterface != null) {
80 >            ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
81 >        }
82          
83 <        ClientInterface[] clientInterfaces = {ciReal, ciDB};
83 >        Queue queue = new Queue();
84 >        // startup a monitor on this queue, every minute
85 >        String queueName = NAME + " RootFilter";
86 >        queue.startMonitor(queueMonitorInterval*1000, queueName);
87          
88 +        if (realInterface == null) {        
89 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
90 +            CIWrapper c = new CIWrapper(ciDB, queue);
91 +            c.start();
92 +        } else if (dbInterface == null) {
93 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
94 +            CIWrapper c = new CIWrapper(ciReal, queue);
95 +            c.start();
96 +        } else {
97 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
98 +            CIWrapper c = new CIWrapper(ciReal, queue);
99 +            c.start();
100 +            c = new CIWrapper(ciDB, queue);
101 +            c.start();
102 +        }
103 +                
104          // RootFilterServant start (for inbound child filter data)
105 <        refman.getLogger().write(toString, Logger.DEBUG, "starting Root Filter");
106 <        RootFilterServant filterServant = new RootFilterServant(clientInterfaces);
105 >        _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
106 >        RootFilterServant filterServant = new RootFilterServant(queue);
107          // bind to the naming service as a filter
108 <        refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName());
108 >        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
109          
110 <        // start the POA off
111 <        // 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();
110 >        _logger.write(toString(), Logger.SYSINIT, "started");
111 >        
112      }
113 <
114 <    /**
115 <     * A simple method to print the usage of this class.
116 <     * It never returns, but instead exits to the system
117 <     * with a value 1, to indicate the system did not start
118 <     * properly.
113 >    
114 >    /**
115 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
116 >     * method to provide clean logging (every class should have this).
117 >     *
118 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
119 >     * to format the toString()
120 >     *
121 >     * @return the name of this class and its CVS revision
122       */
123 <    public static void usage() {
124 <        System.out.println("USAGE: java FilterMain <name>");
125 <        System.out.println("WHERE <name>:");
126 <        System.out.println("      The unique identifier for the Filter in the system.");
127 <        System.exit(1);
123 >    public String toString() {
124 >        return FormatName.getName(
125 >            NAME,
126 >            getClass().getName(),
127 >            REVISION);
128      }
129  
103 //---CONSTRUCTORS---
104
105 //---PUBLIC METHODS---
106
130   //---PRIVATE METHODS---
131  
132   //---ACCESSOR/MUTATOR METHODS---
133  
134   //---ATTRIBUTES---
135  
136 +    /**
137 +     * This holds a reference to the
138 +     * system logger that is being used.
139 +     */
140 +    private Logger _logger;
141 +
142 +    /**
143 +     * A reference to the reference manager in use
144 +     */
145 +    private ReferenceManager _refman;
146 +
147   //---STATIC ATTRIBUTES---
148 +
149 +    /**
150 +     * The friendly name for this component, used by
151 +     * all related classes.
152 +     * This is set from the configuration.
153 +     */
154 +    public static String NAME;
155  
156   }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines