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