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.10 by ajm, Tue Dec 12 19:54:55 2000 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.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 17 | Line 38 | import uk.ac.ukc.iscream.clientinterface.*;
38   * @author  $Author$
39   * @version $Id$
40   */
41 < public class RootFilter implements uk.ac.ukc.iscream.util.Component {
41 > public class RootFilter implements Component {
42  
43   //---FINAL ATTRIBUTES---
44  
# Line 36 | Line 57 | public class RootFilter implements uk.ac.ukc.iscream.u
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");
41            
42        // configuration variables we require
43        String ourName = null;
44        String realInterface = null;
45        String dbInterface = null;
64          
65 <        Configuration config = _refman.getCM().getConfiguration("RootFilter");
66 <        if (config == null) {
67 <            System.err.println("CRITICAL:Unable to obtain configuration" +
68 <                               "\n         Advise you check the i-scream log for more information.");
69 <            _logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration");
70 <            System.exit(1);
71 <        } else {
72 <            try {
73 <                ourName = config.getProperty("RootFilter.name");
56 <                realInterface = config.getProperty("RootFilter.realtimeInterfaceName");
57 <                dbInterface = config.getProperty("RootFilter.dbInterfaceName");
58 <            } catch (org.omg.CORBA.MARSHAL e) {
59 <                System.err.println ("CRITICAL:Unable to obtain required configuration property" +
60 <                                    "\n         Advise you check the i-scream log for more information.");
61 <                _logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present");
62 <                System.exit(1);
63 <            }
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          }
65        // now we have the name of the Root Filter we set it
66        NAME = ourName;
75          
76 <        _logger.write(toString(), Logger.SYSINIT, "configured");
77 <                
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 >        
93 >        ClientInterface ciReal = null, ciDB = null;
94          // get reference to the client interfaces - the real time one
95 <        ClientInterface ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
95 >        if (realInterface != null) {
96 >            ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
97 >        }
98          // get reference to the client interfaces - and the db one
99 <        ClientInterface ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
100 <        _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
99 >        if (dbInterface != null) {
100 >            ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
101 >        }
102          
103 <        ClientInterface[] clientInterfaces = {ciReal, ciDB};
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 +        // 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();
151 +        } else if (dbInterface == null) {
152 +            _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
153 +            CIWrapper c = new CIWrapper(ciReal, queue);
154 +            c.start();
155 +        } else {
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)
160          _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
161 <        RootFilterServant filterServant = new RootFilterServant(clientInterfaces);
161 >        RootFilterServant filterServant = new RootFilterServant(queue);
162          // bind to the naming service as a filter
163 <        _refman.bindToOrb(filterServant, "iscream.Filter." + _name);
163 >        _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
164          
165          _logger.write(toString(), Logger.SYSINIT, "started");
166 +        
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
226       */
227      public String toString() {
228          return FormatName.getName(
229 <            _name,
229 >            NAME,
230              getClass().getName(),
231              REVISION);
232      }
# Line 107 | Line 238 | public class RootFilter implements uk.ac.ukc.iscream.u
238   //---ATTRIBUTES---
239  
240      /**
110     * This is the friendly identifier of the
111     * component this class is running in.
112     * eg, a Filter may be called "filter1",
113     * If this class does not have an owning
114     * component,  a name from the configuration
115     * can be placed here.  This name could also
116     * be changed to null for utility classes.
117     */
118    private String _name = RootFilter.NAME;
119
120    /**
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