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.24 by tdb, Mon Feb 12 02:22:19 2001 UTC vs.
Revision 1.39 by tdb, Sat May 18 18:16:02 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20 +
21   //---PACKAGE DECLARATION---
22 < package uk.ac.ukc.iscream.rootfilter;
22 > package uk.org.iscream.cms.server.rootfilter;
23  
24   //---IMPORTS---
25 < import uk.ac.ukc.iscream.util.*;
26 < import uk.ac.ukc.iscream.core.*;
27 < import uk.ac.ukc.iscream.componentmanager.*;
28 < import uk.ac.ukc.iscream.clientinterface.*;
25 > import uk.org.iscream.cms.server.util.*;
26 > import uk.org.iscream.cms.server.core.*;
27 > import uk.org.iscream.cms.server.componentmanager.*;
28 > import uk.org.iscream.cms.server.clientinterface.*;
29  
30   /**
31   * The root filter is what all filters talk to
# Line 37 | Line 57 | public class RootFilter implements Component {
57       * This starts the Root Filter for the system
58       */
59      public void start() throws ComponentStartException {
60 <
60 >        // get references to key objects
61 >        _logger = _refman.getLogger();
62 >        
63          _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;
64          
65 <        Configuration config = _refman.getCM().getConfiguration("RootFilter");
66 <        if (config == null) {
67 <            throw new ComponentStartException("Unable to obtain configuration for component");
65 >        ConfigurationProxy cp = ConfigurationProxy.getInstance();
66 >        String configName = "RootFilter";
67 >        
68 >        // set the name of the root filter
69 >        try {
70 >            NAME = cp.getProperty(configName, "RootFilter.name");
71 >        } catch (PropertyNotFoundException e) {
72 >            NAME = null;
73 >            _logger.write(toString(), Logger.WARNING, "RootFilter name not set: "+e);
74          }
75 <        else {
76 <            try {
77 <                // get the configuration properties we need
78 <                ourName = config.getProperty("RootFilter.name");
79 <                realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
80 <                dbInterface = config.getProperty("RootFilter.dbInterfaceName");
81 <            } catch (org.omg.CORBA.MARSHAL e) {
82 <                throw new ComponentStartException("Unable to obtain requried configuration property for component");
83 <            }
75 >        
76 >        // try and get the names of the ciReal and ciDB
77 >        String realInterface, dbInterface;
78 >        // first realtime
79 >        try {
80 >            realInterface = cp.getProperty(configName, "RootFilter.realtimeInterfaceName");
81 >        } catch (PropertyNotFoundException e) {
82 >            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
83 >            realInterface = null;
84          }
85 +        // next dbi
86 +        try {
87 +            dbInterface = cp.getProperty(configName, "RootFilter.dbInterfaceName");
88 +        } catch (PropertyNotFoundException e) {
89 +            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
90 +            dbInterface = null;
91 +        }
92          
63        // now we have the name of the Root Filter we set it
64        NAME = ourName;
65        
66        _logger.write(toString(), Logger.SYSINIT, "configured");
67        
93          ClientInterface ciReal = null, ciDB = null;
94          // get reference to the client interfaces - the real time one
95          if (realInterface != null) {
# Line 75 | Line 100 | public class RootFilter implements Component {
100              ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
101          }
102          
103 <        Queue queue = new Queue();
104 <        // startup a monitor on this queue, every minute
105 <        queue.startMonitor(60*1000, NAME);
103 >        // setup a queue
104 >        Queue queue;
105 >        // see if this Queue needs a size limit
106 >        try {
107 >            int queueSizeLimit = Integer.parseInt(cp.getProperty(configName, "Queue.SizeLimit"));
108 >            String queueRemoveAlgorithm = cp.getProperty(configName, "Queue.RemoveAlgorithm");
109 >            int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms);
110 >            if(algorithm != -1) {
111 >                _logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm);
112 >                // we have valid values, so lets start it.
113 >                queue = new Queue(queueSizeLimit, algorithm);
114 >            }
115 >            else {
116 >                _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
117 >                // just don't activate a limit
118 >                queue = new Queue();
119 >            }
120 >            
121 >        } catch (PropertyNotFoundException e) {
122 >            _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
123 >            // just don't activate a limit
124 >            queue = new Queue();
125 >        } catch (NumberFormatException e) {
126 >            _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
127 >            // just don't activate a limit
128 >            queue = new Queue();
129 >        }
130          
131 <        if (realInterface == null) {        
131 >        // startup a monitor on this queue
132 >        try {
133 >            // try to get the interval, if this fails, we won't start up the monitor
134 >            int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval"));
135 >            String queueName = NAME + " RootFilter";
136 >            queue.startMonitor(queueMonitorInterval*1000, queueName);
137 >        } catch (PropertyNotFoundException e) {
138 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
139 >        }
140 >        
141 >        if (realInterface != null && dbInterface != null) {
142 >            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
143 >            CIWrapper c = new CIWrapper(ciReal, queue);
144 >            c.start();
145 >            c = new CIWrapper(ciDB, queue);
146 >            c.start();
147 >        } else if (realInterface == null) {        
148              _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
149              CIWrapper c = new CIWrapper(ciDB, queue);
150              c.start();
# Line 88 | Line 153 | public class RootFilter implements Component {
153              CIWrapper c = new CIWrapper(ciReal, queue);
154              c.start();
155          } else {
156 <            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
92 <            CIWrapper c = new CIWrapper(ciReal, queue);
93 <            c.start();
94 <            c = new CIWrapper(ciDB, queue);
95 <            c.start();
156 >            _logger.write(toString(), Logger.WARNING, "not hooked to any client interfaces, this is probably not intentional!");
157          }
158                  
159          // RootFilterServant start (for inbound child filter data)
# Line 106 | Line 167 | public class RootFilter implements Component {
167      }
168      
169      /**
170 +     * Does a dependency check. Used mainly at startup to
171 +     * see if the required dependencies (components) are up
172 +     * and running.
173 +     *
174 +     * @return a boolean value, true if the depdencies are satisfied
175 +     */
176 +    public boolean depCheck() {
177 +        org.omg.CORBA.Object obj;
178 +        
179 +        // first we need to check the Configuration system is available
180 +        try {
181 +            // first check the ConfigurationManager is alive
182 +            obj = _refman.getCORBARef("iscream.ConfigurationManager");
183 +        } catch(ComponentCORBAException e) {
184 +            System.err.println(toString() + ": Dependency Failure: "+e);
185 +            return false;
186 +        }
187 +        
188 +        // next we need to check which client interfaces *should*
189 +        // be active, and check them. Note they do not have to
190 +        // be enabled, and we should check this.
191 +        // -- each check only forces a dependency if it's configured
192 +        ConfigurationProxy cp = ConfigurationProxy.getInstance();
193 +        // first check the client interface
194 +        try {
195 +            String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName");
196 +            obj = _refman.getCORBARef("iscream.ClientInterface." + cli);
197 +        } catch(ComponentCORBAException e) {
198 +            System.err.println(toString() + ": Dependency Failure: "+e);
199 +            return false;
200 +        } catch(PropertyNotFoundException e) {
201 +            System.err.println(toString() + ": Client interface not configured and thus not enabled.");
202 +        }
203 +        // second check the database interface
204 +        try {
205 +            String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName");
206 +            obj = _refman.getCORBARef("iscream.ClientInterface." + dbi);
207 +        } catch(ComponentCORBAException e) {
208 +            System.err.println(toString() + ": Dependency Failure: "+e);
209 +            return false;
210 +        } catch(PropertyNotFoundException e) {
211 +            System.err.println(toString() + ": Database interface not configured and thus not enabled.");
212 +        }
213 +        
214 +        // dependency check suceeded
215 +        return true;
216 +    }
217 +    
218 +    /**
219       * Overrides the {@link java.lang.Object#toString() Object.toString()}
220       * method to provide clean logging (every class should have this).
221       *
222 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
222 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
223       * to format the toString()
224       *
225       * @return the name of this class and its CVS revision
# Line 131 | Line 241 | public class RootFilter implements Component {
241       * This holds a reference to the
242       * system logger that is being used.
243       */
244 <    private Logger _logger = ReferenceManager.getInstance().getLogger();
244 >    private Logger _logger;
245  
246      /**
247       * A reference to the reference manager in use

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines