1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
4 |
+ |
* Copyright (C) 2000-2002 i-scream |
5 |
+ |
* |
6 |
+ |
* This program is free software; you can redistribute it and/or |
7 |
+ |
* modify it under the terms of the GNU General Public License |
8 |
+ |
* as published by the Free Software Foundation; either version 2 |
9 |
+ |
* of the License, or (at your option) any later version. |
10 |
+ |
* |
11 |
+ |
* This program is distributed in the hope that it will be useful, |
12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
+ |
* GNU General Public License for more details. |
15 |
+ |
* |
16 |
+ |
* You should have received a copy of the GNU General Public License |
17 |
+ |
* along with this program; if not, write to the Free Software |
18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
+ |
*/ |
20 |
+ |
|
21 |
+ |
|
22 |
|
//---PACKAGE DECLARATION--- |
23 |
< |
package uk.ac.ukc.iscream.rootfilter; |
23 |
> |
package uk.org.iscream.cms.server.rootfilter; |
24 |
|
|
25 |
|
//---IMPORTS--- |
26 |
< |
import uk.ac.ukc.iscream.util.*; |
27 |
< |
import uk.ac.ukc.iscream.core.*; |
26 |
> |
import uk.org.iscream.cms.util.*; |
27 |
> |
import uk.org.iscream.cms.server.core.*; |
28 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
29 |
> |
import uk.org.iscream.cms.server.clientinterface.*; |
30 |
|
|
31 |
|
/** |
32 |
< |
* A Filter Startup Class |
32 |
> |
* The root filter is what all filters talk to |
33 |
> |
* Hosts cannot talk to this implementation of a filter. |
34 |
> |
* It provides hooks to all data interfaces for the system |
35 |
> |
* namely the client interface and the db interface. |
36 |
> |
* This is an i-scream component that starts the |
37 |
> |
* RootFilter services. |
38 |
|
* |
39 |
|
* @author $Author$ |
40 |
|
* @version $Id$ |
41 |
|
*/ |
42 |
< |
class FilterMain { |
42 |
> |
public class RootFilter implements Component { |
43 |
|
|
44 |
|
//---FINAL ATTRIBUTES--- |
45 |
|
|
47 |
|
* The current CVS revision of this class |
48 |
|
*/ |
49 |
|
public static final String REVISION = "$Revision$"; |
50 |
< |
|
50 |
> |
|
51 |
|
//---STATIC METHODS--- |
52 |
|
|
53 |
< |
public static void main(String[] args) { |
26 |
< |
// *************************************** |
27 |
< |
// VERY TEMPORARY - will find a better way |
28 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
29 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
30 |
< |
// *************************************** |
53 |
> |
//---CONSTRUCTORS--- |
54 |
|
|
55 |
< |
ReferenceManager refman = ReferenceManager.init(null, null); |
33 |
< |
|
34 |
< |
// can't have a real toString() :) |
35 |
< |
String toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
55 |
> |
//---PUBLIC METHODS--- |
56 |
|
|
57 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); |
57 |
> |
/** |
58 |
> |
* This starts the Root Filter for the system |
59 |
> |
*/ |
60 |
> |
public void start() throws ComponentStartException { |
61 |
> |
// get references to key objects |
62 |
> |
_logger = _refman.getLogger(); |
63 |
> |
|
64 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
65 |
> |
|
66 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
67 |
> |
String configName = "RootFilter"; |
68 |
> |
|
69 |
> |
// set the name of the root filter |
70 |
> |
try { |
71 |
> |
NAME = cp.getProperty(configName, "RootFilter.name"); |
72 |
> |
} catch (PropertyNotFoundException e) { |
73 |
> |
NAME = null; |
74 |
> |
_logger.write(toString(), Logger.WARNING, "RootFilter name not set: "+e); |
75 |
> |
} |
76 |
> |
|
77 |
> |
// try and get the names of the ciReal and ciDB |
78 |
> |
String realInterface, dbInterface; |
79 |
> |
// first realtime |
80 |
> |
try { |
81 |
> |
realInterface = cp.getProperty(configName, "RootFilter.realtimeInterfaceName"); |
82 |
> |
} catch (PropertyNotFoundException e) { |
83 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
84 |
> |
realInterface = null; |
85 |
> |
} |
86 |
> |
// next dbi |
87 |
> |
try { |
88 |
> |
dbInterface = cp.getProperty(configName, "RootFilter.dbInterfaceName"); |
89 |
> |
} catch (PropertyNotFoundException e) { |
90 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
91 |
> |
dbInterface = null; |
92 |
> |
} |
93 |
> |
|
94 |
> |
ClientInterface ciReal = null, ciDB = null; |
95 |
> |
// get reference to the client interfaces - the real time one |
96 |
> |
if (realInterface != null) { |
97 |
> |
ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface\\." + realInterface)); |
98 |
> |
} |
99 |
> |
// get reference to the client interfaces - and the db one |
100 |
> |
if (dbInterface != null) { |
101 |
> |
ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface\\." + dbInterface)); |
102 |
> |
} |
103 |
> |
|
104 |
> |
// setup a queue |
105 |
> |
Queue queue; |
106 |
> |
// see if this Queue needs a size limit |
107 |
> |
try { |
108 |
> |
int queueSizeLimit = Integer.parseInt(cp.getProperty(configName, "Queue.SizeLimit")); |
109 |
> |
String queueRemoveAlgorithm = cp.getProperty(configName, "Queue.RemoveAlgorithm"); |
110 |
> |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
111 |
> |
if(algorithm != -1) { |
112 |
> |
_logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
113 |
> |
// we have valid values, so lets start it. |
114 |
> |
queue = new Queue(queueSizeLimit, algorithm); |
115 |
> |
} |
116 |
> |
else { |
117 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
118 |
> |
// just don't activate a limit |
119 |
> |
queue = new Queue(); |
120 |
> |
} |
121 |
|
|
122 |
< |
// configuration variables we require |
123 |
< |
String ourName = null; |
122 |
> |
} catch (PropertyNotFoundException e) { |
123 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
124 |
> |
// just don't activate a limit |
125 |
> |
queue = new Queue(); |
126 |
> |
} catch (NumberFormatException e) { |
127 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
128 |
> |
// just don't activate a limit |
129 |
> |
queue = new Queue(); |
130 |
> |
} |
131 |
|
|
132 |
< |
Configuration config = refman.getCM().getConfiguration("RootFilter"); |
133 |
< |
if (config == null) { |
134 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain configuration" + |
135 |
< |
" Advise you check the i-scream log for more information."); |
132 |
> |
// startup a monitor on this queue |
133 |
> |
try { |
134 |
> |
// try to get the interval, if this fails, we won't start up the monitor |
135 |
> |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval")); |
136 |
> |
String queueName = NAME + " RootFilter"; |
137 |
> |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
138 |
> |
} catch (PropertyNotFoundException e) { |
139 |
> |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
140 |
> |
} |
141 |
> |
|
142 |
> |
if (realInterface != null && dbInterface != null) { |
143 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
144 |
> |
CIWrapper c = new CIWrapper(ciReal, queue); |
145 |
> |
c.start(); |
146 |
> |
c = new CIWrapper(ciDB, queue); |
147 |
> |
c.start(); |
148 |
> |
} else if (realInterface == null) { |
149 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface); |
150 |
> |
CIWrapper c = new CIWrapper(ciDB, queue); |
151 |
> |
c.start(); |
152 |
> |
} else if (dbInterface == null) { |
153 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface); |
154 |
> |
CIWrapper c = new CIWrapper(ciReal, queue); |
155 |
> |
c.start(); |
156 |
|
} else { |
157 |
< |
try { |
48 |
< |
ourName = config.getProperty("Filter.rootFilter"); |
49 |
< |
} catch (org.omg.CORBA.MARSHAL e) { |
50 |
< |
refman.getLogger().write(toString, Logger.FATAL, "required config property not present"); |
51 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" + |
52 |
< |
" Advise you check the i-scream log for more information."); |
53 |
< |
|
54 |
< |
} |
157 |
> |
_logger.write(toString(), Logger.WARNING, "not hooked to any client interfaces, this is probably not intentional!"); |
158 |
|
} |
159 |
< |
// now we have the name of the Root Filter we set it |
160 |
< |
refman.setName(ourName); |
161 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "configured"); |
159 |
> |
|
160 |
> |
// RootFilterServant start (for inbound child filter data) |
161 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
162 |
> |
RootFilterServant filterServant = new RootFilterServant(queue); |
163 |
> |
// bind to the naming service as a filter |
164 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter\\." + RootFilter.NAME); |
165 |
|
|
166 |
< |
// FilterServant start (for inbound child filter data) |
61 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "starting Root Filter"); |
62 |
< |
RootFilterServant filterServant = new RootFilterServant(); |
63 |
< |
refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName()); |
166 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
167 |
|
|
65 |
– |
// start the POA off |
66 |
– |
// now we are running, we just need to serve |
67 |
– |
// so we ask the orb to block for us until it has finished |
68 |
– |
refman.activatePOA(); |
69 |
– |
refman.getLogger().write(toString, Logger.SYSINIT, "started"); |
70 |
– |
refman.getORB().run(); |
168 |
|
} |
169 |
< |
|
170 |
< |
/** |
171 |
< |
* A simple method to print the usage of this class. |
172 |
< |
* It never returns, but instead exits to the system |
173 |
< |
* with a value 1, to indicate the system did not start |
174 |
< |
* properly. |
169 |
> |
|
170 |
> |
/** |
171 |
> |
* Does a dependency check. Used mainly at startup to |
172 |
> |
* see if the required dependencies (components) are up |
173 |
> |
* and running. |
174 |
> |
* |
175 |
> |
* @return a boolean value, true if the depdencies are satisfied |
176 |
|
*/ |
177 |
< |
public static void usage() { |
178 |
< |
System.out.println("USAGE: java FilterMain <name>"); |
179 |
< |
System.out.println("WHERE <name>:"); |
180 |
< |
System.out.println(" The unique identifier for the Filter in the system."); |
181 |
< |
System.exit(1); |
177 |
> |
public boolean depCheck() { |
178 |
> |
org.omg.CORBA.Object obj; |
179 |
> |
|
180 |
> |
// first we need to check the Configuration system is available |
181 |
> |
try { |
182 |
> |
// first check the ConfigurationManager is alive |
183 |
> |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
184 |
> |
} catch(ComponentCORBAException e) { |
185 |
> |
System.err.println(toString() + ": Dependency Failure: "+e); |
186 |
> |
return false; |
187 |
> |
} |
188 |
> |
|
189 |
> |
// next we need to check which client interfaces *should* |
190 |
> |
// be active, and check them. Note they do not have to |
191 |
> |
// be enabled, and we should check this. |
192 |
> |
// -- each check only forces a dependency if it's configured |
193 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
194 |
> |
// first check the client interface |
195 |
> |
try { |
196 |
> |
String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName"); |
197 |
> |
obj = _refman.getCORBARef("iscream.ClientInterface\\." + cli); |
198 |
> |
} catch(ComponentCORBAException e) { |
199 |
> |
System.err.println(toString() + ": Dependency Failure: "+e); |
200 |
> |
return false; |
201 |
> |
} catch(PropertyNotFoundException e) { |
202 |
> |
System.err.println(toString() + ": Client interface not configured and thus not enabled."); |
203 |
> |
} |
204 |
> |
// second check the database interface |
205 |
> |
try { |
206 |
> |
String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName"); |
207 |
> |
obj = _refman.getCORBARef("iscream.ClientInterface\\." + dbi); |
208 |
> |
} catch(ComponentCORBAException e) { |
209 |
> |
System.err.println(toString() + ": Dependency Failure: "+e); |
210 |
> |
return false; |
211 |
> |
} catch(PropertyNotFoundException e) { |
212 |
> |
System.err.println(toString() + ": Database interface not configured and thus not enabled."); |
213 |
> |
} |
214 |
> |
|
215 |
> |
// dependency check suceeded |
216 |
> |
return true; |
217 |
|
} |
218 |
+ |
|
219 |
+ |
/** |
220 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
221 |
+ |
* method to provide clean logging (every class should have this). |
222 |
+ |
* |
223 |
+ |
* This uses the uk.org.iscream.cms.util.NameFormat class |
224 |
+ |
* to format the toString() |
225 |
+ |
* |
226 |
+ |
* @return the name of this class and its CVS revision |
227 |
+ |
*/ |
228 |
+ |
public String toString() { |
229 |
+ |
return FormatName.getName( |
230 |
+ |
NAME, |
231 |
+ |
getClass().getName(), |
232 |
+ |
REVISION); |
233 |
+ |
} |
234 |
|
|
86 |
– |
//---CONSTRUCTORS--- |
87 |
– |
|
88 |
– |
//---PUBLIC METHODS--- |
89 |
– |
|
235 |
|
//---PRIVATE METHODS--- |
236 |
|
|
237 |
|
//---ACCESSOR/MUTATOR METHODS--- |
238 |
|
|
239 |
|
//---ATTRIBUTES--- |
240 |
|
|
241 |
+ |
/** |
242 |
+ |
* This holds a reference to the |
243 |
+ |
* system logger that is being used. |
244 |
+ |
*/ |
245 |
+ |
private Logger _logger; |
246 |
+ |
|
247 |
+ |
/** |
248 |
+ |
* A reference to the reference manager in use |
249 |
+ |
*/ |
250 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
251 |
+ |
|
252 |
|
//---STATIC ATTRIBUTES--- |
253 |
+ |
|
254 |
+ |
/** |
255 |
+ |
* The friendly name for this component, used by |
256 |
+ |
* all related classes. |
257 |
+ |
* This is set from the configuration. |
258 |
+ |
*/ |
259 |
+ |
public static String NAME; |
260 |
|
|
261 |
|
} |