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.28 by tdb, Tue Mar 13 16:37:31 2001 UTC

# Line 1 | Line 1
1 +
2   //---PACKAGE DECLARATION---
3   package uk.ac.ukc.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.componentmanager.*;
9   import uk.ac.ukc.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 >        _refman = ReferenceManager.getInstance();
43 >        _logger = ReferenceManager.getInstance().getLogger();
44          
45 <        Configuration config = refman.getCM().getConfiguration("RootFilter");
46 <        if (config == null) {
47 <            throw new RuntimeException ("CRITICAL:Unable to obtain configuration" +
48 <                                        "         Advise you check the i-scream log for more information.");
49 <        } else {
50 <            try {
51 <                ourName = config.getProperty("RootFilter.name");
52 <                realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
53 <                dbInterface = config.getProperty("RootFilter.dbInterfaceName");
54 <            } catch (org.omg.CORBA.MARSHAL e) {
55 <                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 <            }
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 <        // now we have the name of the Root Filter we set it
58 <        refman.setName(ourName);
59 <        toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
60 <        refman.getLogger().write(toString, Logger.SYSINIT, "configured");
61 <                
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 >        ClientInterface ciReal = null, ciDB = null;
70          // get reference to the client interfaces - the real time one
71 <        ClientInterface ciReal = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + realInterface));
72 <        // - the db one ... but it's not done yet
73 <        //ClientInterface ciDB = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + dbInterface));
74 <        // so for the time being we null it.
75 <        ClientInterface ciDB = null;
76 <        refman.getLogger().write(toString, Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
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 <        ClientInterface[] clientInterfaces = {ciReal, ciDB};
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          // RootFilterServant start (for inbound child filter data)
109 <        refman.getLogger().write(toString, Logger.DEBUG, "starting Root Filter");
110 <        RootFilterServant filterServant = new RootFilterServant(clientInterfaces);
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." + refman.getName());
112 >        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
113          
114 <        // start the POA off
115 <        // 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();
114 >        _logger.write(toString(), Logger.SYSINIT, "started");
115 >        
116      }
117 <
118 <    /**
119 <     * A simple method to print the usage of this class.
120 <     * It never returns, but instead exits to the system
121 <     * with a value 1, to indicate the system did not start
122 <     * properly.
117 >    
118 >    /**
119 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
120 >     * method to provide clean logging (every class should have this).
121 >     *
122 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
123 >     * to format the toString()
124 >     *
125 >     * @return the name of this class and its CVS revision
126       */
127 <    public static void usage() {
128 <        System.out.println("USAGE: java FilterMain <name>");
129 <        System.out.println("WHERE <name>:");
130 <        System.out.println("      The unique identifier for the Filter in the system.");
131 <        System.exit(1);
127 >    public String toString() {
128 >        return FormatName.getName(
129 >            NAME,
130 >            getClass().getName(),
131 >            REVISION);
132      }
133  
103 //---CONSTRUCTORS---
104
105 //---PUBLIC METHODS---
106
134   //---PRIVATE METHODS---
135  
136   //---ACCESSOR/MUTATOR METHODS---
137  
138   //---ATTRIBUTES---
139  
140 +    /**
141 +     * This holds a reference to the
142 +     * system logger that is being used.
143 +     */
144 +    private Logger _logger;
145 +
146 +    /**
147 +     * A reference to the reference manager in use
148 +     */
149 +    private ReferenceManager _refman;
150 +
151   //---STATIC ATTRIBUTES---
152 +
153 +    /**
154 +     * The friendly name for this component, used by
155 +     * all related classes.
156 +     * This is set from the configuration.
157 +     */
158 +    public static String NAME;
159  
160   }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines