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
Revision: 1.35
Committed: Fri Mar 23 04:57:09 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.34: +28 -9 lines
Log Message:
Now only enforces a dependency on either the Client Interface or the Database
Interface if it is configured. This ensures that the startup order is still
correct (which it wouldn't if the checks were removed), but also doesn't enforce
the checks when one of the interfaces is disabled.

File Contents

# User Rev Content
1 ajm 1.27
2 tdb 1.1 //---PACKAGE DECLARATION---
3 tdb 1.32 package uk.org.iscream.rootfilter;
4 tdb 1.1
5     //---IMPORTS---
6 tdb 1.32 import uk.org.iscream.util.*;
7     import uk.org.iscream.core.*;
8     import uk.org.iscream.componentmanager.*;
9     import uk.org.iscream.clientinterface.*;
10 tdb 1.1
11     /**
12 ajm 1.10 * 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 tdb 1.1 *
19 tdb 1.29 * @author $Author: tdb1 $
20 tdb 1.35 * @version $Id: RootFilter.java,v 1.34 2001/03/16 15:22:13 tdb1 Exp $
21 tdb 1.1 */
22 tdb 1.17 public class RootFilter implements Component {
23 tdb 1.1
24     //---FINAL ATTRIBUTES---
25    
26     /**
27     * The current CVS revision of this class
28     */
29 tdb 1.35 public static final String REVISION = "$Revision: 1.34 $";
30 ajm 1.10
31 tdb 1.1 //---STATIC METHODS---
32    
33 ajm 1.10 //---CONSTRUCTORS---
34    
35     //---PUBLIC METHODS---
36 ajm 1.5
37 ajm 1.10 /**
38     * This starts the Root Filter for the system
39     */
40     public void start() throws ComponentStartException {
41 ajm 1.26 // get references to key objects
42 tdb 1.30 _logger = _refman.getLogger();
43 ajm 1.26
44 ajm 1.10 _logger.write(toString(), Logger.SYSINIT, "coming up");
45 tdb 1.28
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 tdb 1.23 }
56 tdb 1.28
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 tdb 1.1 }
67 tdb 1.23
68 ajm 1.13 ClientInterface ciReal = null, ciDB = null;
69 ajm 1.8 // get reference to the client interfaces - the real time one
70 ajm 1.11 if (realInterface != null) {
71 ajm 1.13 ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface));
72 ajm 1.11 }
73 ajm 1.10 // get reference to the client interfaces - and the db one
74 ajm 1.11 if (dbInterface != null) {
75 ajm 1.13 ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface));
76 ajm 1.11 }
77 tdb 1.33
78 tdb 1.28 // setup a queue
79 tdb 1.33 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 tdb 1.34 _logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm);
87     // we have valid values, so lets start it.
88 tdb 1.33 queue = new Queue(queueSizeLimit, algorithm);
89     }
90     else {
91     _logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm);
92     // just don't activate a limit
93     queue = new Queue();
94     }
95    
96     } catch (PropertyNotFoundException e) {
97     _logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e);
98     // just don't activate a limit
99     queue = new Queue();
100     } catch (NumberFormatException e) {
101     _logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e);
102     // just don't activate a limit
103     queue = new Queue();
104     }
105 tdb 1.15
106 tdb 1.28 // startup a monitor on this queue
107     try {
108     // try to get the interval, if this fails, we won't start up the monitor
109     int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval"));
110     String queueName = NAME + " RootFilter";
111     queue.startMonitor(queueMonitorInterval*1000, queueName);
112     } catch (PropertyNotFoundException e) {
113     _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
114     }
115 tdb 1.15
116 ajm 1.11 if (realInterface == null) {
117     _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface);
118 tdb 1.15 CIWrapper c = new CIWrapper(ciDB, queue);
119     c.start();
120 ajm 1.11 } else if (dbInterface == null) {
121     _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface);
122 tdb 1.15 CIWrapper c = new CIWrapper(ciReal, queue);
123     c.start();
124 ajm 1.11 } else {
125     _logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface);
126 tdb 1.15 CIWrapper c = new CIWrapper(ciReal, queue);
127     c.start();
128     c = new CIWrapper(ciDB, queue);
129     c.start();
130 ajm 1.11 }
131 tdb 1.15
132 ajm 1.8 // RootFilterServant start (for inbound child filter data)
133 ajm 1.10 _logger.write(toString(), Logger.DEBUG, "starting Root Filter");
134 tdb 1.15 RootFilterServant filterServant = new RootFilterServant(queue);
135 ajm 1.8 // bind to the naming service as a filter
136 ajm 1.14 _refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME);
137 tdb 1.1
138 ajm 1.10 _logger.write(toString(), Logger.SYSINIT, "started");
139 tdb 1.18
140 tdb 1.29 }
141    
142     /**
143     * Does a dependency check. Used mainly at startup to
144     * see if the required dependencies (components) are up
145     * and running.
146     *
147     * @return a boolean value, true if the depdencies are satisfied
148     */
149     public boolean depCheck() {
150 tdb 1.35 org.omg.CORBA.Object obj;
151    
152     // first we need to check the Configuration system is available
153 tdb 1.29 try {
154     // first check the ConfigurationManager is alive
155     obj = _refman.getCORBARef("iscream.ConfigurationManager");
156 tdb 1.35 } catch(ComponentCORBAException e) {
157     System.err.println(toString() + ": Dependency Failure: "+e);
158     return false;
159     }
160    
161     // next we need to check which client interfaces *should*
162     // be active, and check them. Note they do not have to
163     // be enabled, and we should check this.
164     // -- each check only forces a dependency if it's configured
165     ConfigurationProxy cp = ConfigurationProxy.getInstance();
166     // first check the client interface
167     try {
168 tdb 1.29 String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName");
169 tdb 1.35 obj = _refman.getCORBARef("iscream.ClientInterface." + cli);
170     } catch(ComponentCORBAException e) {
171     System.err.println(toString() + ": Dependency Failure: "+e);
172     return false;
173     } catch(PropertyNotFoundException e) {
174     System.err.println(toString() + ": Client interface not configured and thus not enabled.");
175     }
176     // second check the database interface
177     try {
178 tdb 1.29 String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName");
179     obj = _refman.getCORBARef("iscream.ClientInterface." + dbi);
180     } catch(ComponentCORBAException e) {
181 tdb 1.31 System.err.println(toString() + ": Dependency Failure: "+e);
182 tdb 1.29 return false;
183     } catch(PropertyNotFoundException e) {
184 tdb 1.35 System.err.println(toString() + ": Database interface not configured and thus not enabled.");
185 tdb 1.29 }
186 tdb 1.35
187 tdb 1.29 // dependency check suceeded
188     return true;
189 tdb 1.1 }
190 ajm 1.10
191     /**
192     * Overrides the {@link java.lang.Object#toString() Object.toString()}
193     * method to provide clean logging (every class should have this).
194     *
195 tdb 1.32 * This uses the uk.org.iscream.util.NameFormat class
196 ajm 1.10 * to format the toString()
197     *
198     * @return the name of this class and its CVS revision
199     */
200     public String toString() {
201     return FormatName.getName(
202 ajm 1.14 NAME,
203 ajm 1.10 getClass().getName(),
204     REVISION);
205 tdb 1.1 }
206    
207     //---PRIVATE METHODS---
208    
209     //---ACCESSOR/MUTATOR METHODS---
210    
211     //---ATTRIBUTES---
212 ajm 1.10
213     /**
214     * This holds a reference to the
215     * system logger that is being used.
216     */
217 ajm 1.26 private Logger _logger;
218 ajm 1.10
219     /**
220     * A reference to the reference manager in use
221     */
222 tdb 1.30 private ReferenceManager _refman = ReferenceManager.getInstance();
223 ajm 1.10
224 tdb 1.1 //---STATIC ATTRIBUTES---
225 ajm 1.10
226     /**
227     * The friendly name for this component, used by
228     * all related classes.
229     * This is set from the configuration.
230     */
231     public static String NAME;
232 tdb 1.1
233 ajm 1.5 }