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.27 by ajm, Mon Feb 26 02:15:11 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 >        // configuration variables we require
48 >        String ourName = null;
49 >        String realInterface = null;
50 >        String dbInterface = null;
51 >        int queueMonitorInterval = 0;
52 >        
53 >        Configuration config = _refman.getCM().getConfiguration("RootFilter");
54 >        if (config == null) {
55 >            throw new ComponentStartException("Unable to obtain configuration for component");
56          }
57          else {
58 <            usage();
58 >            try {
59 >                // get the configuration properties we need
60 >                ourName = config.getProperty("RootFilter.name");
61 >            
62 >                queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval"));
63 >            } catch (org.omg.CORBA.MARSHAL e) {
64 >                throw new ComponentStartException("Unable to obtain requried configuration property for component");
65 >            }
66 >            try {
67 >                // get the optional configuration properties
68 >                realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
69 >                dbInterface = config.getProperty("RootFilter.dbInterfaceName");
70 >            } catch (org.omg.CORBA.MARSHAL e) {
71 >                // we can ignore that fact
72 >            }
73          }
74          
75 <        // can't have a real toString() :)
76 <        String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
75 >        // now we have the name of the Root Filter we set it
76 >        NAME = ourName;
77          
78 <        try {        
79 <            ORB orb = ORB.init(args, null);
80 <            
81 <            // something to hold objects
82 <            org.omg.CORBA.Object objRef = null;    
83 <            
51 <            // get the Root POA
52 <            objRef = orb.resolve_initial_references("RootPOA");
53 <            POA poa = POAHelper.narrow(objRef);
54 <            
55 <            // get a hook to the name service
56 <            objRef = orb.resolve_initial_references("NameService");
57 <            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
58 <                
59 <            // get a ref to the ConfigurationManager, Logger & the FilterManager
60 <            
61 <            objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager"));
62 <            ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef);
63 <            
64 <            objRef = ncRef.resolve(ncRef.to_name("iscream.Logger"));
65 <            Logger logger = LoggerHelper.narrow(objRef);
66 <            
67 <            //objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager"));
68 <            //FilterManager filterManager = FilterManagerHelper.narrow(objRef);
69 <            
70 <            logger.write(toString, Logger.SYSINIT, "coming up");
71 <            
72 <            
73 <            // **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG
74 <            // **** Please ignore this block of code, it's just "copy/paste" :)
75 <            
76 <            // get the config
77 <            Configuration myConfig = configManager.getConfiguration(ourName);
78 <                      
79 <            logger.write(toString, Logger.SYSINIT, "configured");
80 <            
81 <            // **** END COMMENT
82 <            
83 <            // **** INITIAL FILTER MANAGER COMMUNICATIONS HERE
84 <            
85 <            // **** END COMMENT
86 <            
87 <            logger.write(toString, Logger.SYSINIT, "starting RootFilter");
88 <            
89 <            /**************************************************************
90 <              Here would be an ideal place to start another thread to do
91 <              the listening part of the Filter. Ideally it should just be
92 <              created and then run(). It may be necessary to pass some of
93 <              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);
78 >        _logger.write(toString(), Logger.SYSINIT, "configured");
79 >        
80 >        ClientInterface ciReal = null, ciDB = null;
81 >        // get reference to the client interfaces - the real time one
82 >        if (realInterface != null) {
83 >            ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
84          }
85 +        // get reference to the client interfaces - and the db one
86 +        if (dbInterface != null) {
87 +            ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
88 +        }
89 +        
90 +        Queue queue = new Queue();
91 +        // startup a monitor on this queue, every minute
92 +        String queueName = NAME + " RootFilter";
93 +        queue.startMonitor(queueMonitorInterval*1000, queueName);
94 +        
95 +        if (realInterface == null) {        
96 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
97 +            CIWrapper c = new CIWrapper(ciDB, queue);
98 +            c.start();
99 +        } else if (dbInterface == null) {
100 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
101 +            CIWrapper c = new CIWrapper(ciReal, queue);
102 +            c.start();
103 +        } else {
104 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
105 +            CIWrapper c = new CIWrapper(ciReal, queue);
106 +            c.start();
107 +            c = new CIWrapper(ciDB, queue);
108 +            c.start();
109 +        }
110 +                
111 +        // RootFilterServant start (for inbound child filter data)
112 +        _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
113 +        RootFilterServant filterServant = new RootFilterServant(queue);
114 +        // bind to the naming service as a filter
115 +        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
116 +        
117 +        _logger.write(toString(), Logger.SYSINIT, "started");
118 +        
119      }
120 <
121 <    /**
122 <     * A simple method to print the usage of this class.
123 <     * It never returns, but instead exits to the system
124 <     * with a value 1, to indicate the system did not start
125 <     * properly.
120 >    
121 >    /**
122 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
123 >     * method to provide clean logging (every class should have this).
124 >     *
125 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
126 >     * to format the toString()
127 >     *
128 >     * @return the name of this class and its CVS revision
129       */
130 <    public static void usage() {
131 <        System.out.println("USAGE: java RootFilter <name>");
132 <        System.out.println("WHERE <name>:");
133 <        System.out.println("      The unique identifier for the RootFilter in the system.");
134 <        System.exit(1);
130 >    public String toString() {
131 >        return FormatName.getName(
132 >            NAME,
133 >            getClass().getName(),
134 >            REVISION);
135      }
136  
148 //---CONSTRUCTORS---
149
150 //---PUBLIC METHODS---
151
137   //---PRIVATE METHODS---
138  
139   //---ACCESSOR/MUTATOR METHODS---
140  
141   //---ATTRIBUTES---
142  
143 +    /**
144 +     * This holds a reference to the
145 +     * system logger that is being used.
146 +     */
147 +    private Logger _logger;
148 +
149 +    /**
150 +     * A reference to the reference manager in use
151 +     */
152 +    private ReferenceManager _refman;
153 +
154   //---STATIC ATTRIBUTES---
155 +
156 +    /**
157 +     * The friendly name for this component, used by
158 +     * all related classes.
159 +     * This is set from the configuration.
160 +     */
161 +    public static String NAME;
162  
163 < }            
163 > }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines