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.21 by tdb, Fri Jan 19 01:20:15 2001 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.util.*;
7 < import uk.ac.ukc.iscream.core.*;
8 < import uk.ac.ukc.iscream.componentmanager.*;
9 < 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   * The root filter is what all filters talk to
# Line 37 | Line 38 | public class RootFilter implements Component {
38       * This starts the Root Filter for the system
39       */
40      public void start() throws ComponentStartException {
41 <
41 >        // get references to key objects
42 >        _logger = _refman.getLogger();
43 >        
44          _logger.write(toString(), Logger.SYSINIT, "coming up");
42            
43        // configuration variables we require
44        String ourName = null;
45        String realInterface = null;
46        String dbInterface = null;
45          
46 <        Configuration config = _refman.getCM().getConfiguration("RootFilter");
47 <        if (config == null) {
48 <            System.err.println("CRITICAL:Unable to obtain configuration" +
49 <                               "\n         Advise you check the i-scream log for more information.");
50 <            _logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration");
51 <            System.exit(1);
52 <        } else {
53 <            try {
54 <                ourName = config.getProperty("RootFilter.name");
57 <                realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
58 <                dbInterface = config.getProperty("RootFilter.dbInterfaceName");
59 <            } catch (org.omg.CORBA.MARSHAL e) {
60 <                System.err.println ("CRITICAL:Unable to obtain required configuration property" +
61 <                                    "\n         Advise you check the i-scream log for more information.");
62 <                _logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present");
63 <                System.exit(1);
64 <            }
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          }
66        // now we have the name of the Root Filter we set it
67        NAME = ourName;
56          
57 <        _logger.write(toString(), Logger.SYSINIT, "configured");
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
# Line 78 | Line 75 | public class RootFilter implements Component {
75              ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
76          }
77          
78 <        Queue queue = new Queue();
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 >        } 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);
# Line 104 | Line 135 | public class RootFilter implements Component {
135          
136          _logger.write(toString(), Logger.SYSINIT, "started");
137          
138 <        // !!!! TEMPORARY CODE !!!!
139 <        // Monitor the queue's status (queue 0 and 1 - big assumption!)
140 <        while(true) {
141 <            // wait 30 seconds
142 <            try { Thread.sleep(30000); } catch(Exception e) {}
143 <            try {
144 <                int q0 = queue.queueSize(0);
145 <                int q1 = queue.queueSize(1);
146 <                int tot = queue.elementCount();
147 <                String message = "Queue status - queue0: "+q0+" queue1: "+q1+" total: "+tot;
148 <                _logger.write(toString(), Logger.DEBUG, message);
149 <            }
150 <            catch(Exception e) {
151 <                _logger.write(toString(), Logger.ERROR, e.getMessage());
152 <            }
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       * 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.ac.ukc.iscream.util.NameFormat class
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
# Line 148 | Line 193 | public class RootFilter implements Component {
193       * This holds a reference to the
194       * system logger that is being used.
195       */
196 <    private Logger _logger = ReferenceManager.getInstance().getLogger();
196 >    private Logger _logger;
197  
198      /**
199       * A reference to the reference manager in use

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines