1 |
+ |
|
2 |
|
//---PACKAGE DECLARATION--- |
3 |
+ |
package uk.org.iscream.cms.server.rootfilter; |
4 |
|
|
5 |
|
//---IMPORTS--- |
6 |
< |
import uk.ac.ukc.iscream.core.*; |
7 |
< |
import uk.ac.ukc.iscream.filter.*; |
8 |
< |
import org.omg.CORBA.*; |
9 |
< |
import org.omg.CosNaming.*; |
8 |
< |
import org.omg.PortableServer.*; |
6 |
> |
import uk.org.iscream.cms.server.util.*; |
7 |
> |
import uk.org.iscream.cms.server.core.*; |
8 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
9 |
> |
import uk.org.iscream.cms.server.clientinterface.*; |
10 |
|
|
11 |
|
/** |
12 |
< |
* A RootFilter Startup Class |
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$ |
20 |
|
* @version $Id$ |
21 |
|
*/ |
22 |
< |
class RootFilterMain { |
22 |
> |
public class RootFilter implements Component { |
23 |
|
|
24 |
|
//---FINAL ATTRIBUTES--- |
25 |
|
|
27 |
|
* The current CVS revision of this class |
28 |
|
*/ |
29 |
|
public static final String REVISION = "$Revision$"; |
30 |
< |
|
30 |
> |
|
31 |
|
//---STATIC METHODS--- |
32 |
|
|
33 |
< |
public static void main(String[] args) { |
34 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
35 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
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 |
< |
// get our name from the command line |
45 |
< |
String ourName = ""; |
46 |
< |
if (args.length == 1) { |
47 |
< |
ourName = args[0]; |
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 |
< |
else { |
57 |
< |
usage(); |
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 |
< |
// can't have a real toString() :) |
75 |
< |
String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
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 |
< |
try { |
85 |
< |
ORB orb = ORB.init(args, null); |
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 |
< |
// something to hold objects |
103 |
< |
org.omg.CORBA.Object objRef = null; |
104 |
< |
|
105 |
< |
// get the Root POA |
106 |
< |
objRef = orb.resolve_initial_references("RootPOA"); |
107 |
< |
POA poa = POAHelper.narrow(objRef); |
108 |
< |
|
109 |
< |
// get a hook to the name service |
110 |
< |
objRef = orb.resolve_initial_references("NameService"); |
111 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
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 && dbInterface != null) { |
123 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
124 |
> |
CIWrapper c = new CIWrapper(ciReal, queue); |
125 |
> |
c.start(); |
126 |
> |
c = new CIWrapper(ciDB, queue); |
127 |
> |
c.start(); |
128 |
> |
} else if (realInterface == null) { |
129 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface); |
130 |
> |
CIWrapper c = new CIWrapper(ciDB, queue); |
131 |
> |
c.start(); |
132 |
> |
} else if (dbInterface == null) { |
133 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface); |
134 |
> |
CIWrapper c = new CIWrapper(ciReal, queue); |
135 |
> |
c.start(); |
136 |
> |
} else { |
137 |
> |
_logger.write(toString(), Logger.WARNING, "not hooked to any client interfaces, this is probably not intentional!"); |
138 |
> |
} |
139 |
|
|
140 |
< |
// get a ref to the ConfigurationManager, Logger & the FilterManager |
141 |
< |
|
142 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
143 |
< |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
144 |
< |
|
145 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
146 |
< |
Logger logger = LoggerHelper.narrow(objRef); |
147 |
< |
|
148 |
< |
//objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager")); |
149 |
< |
//FilterManager filterManager = FilterManagerHelper.narrow(objRef); |
150 |
< |
|
151 |
< |
logger.write(toString, Logger.SYSINIT, "coming up"); |
152 |
< |
|
153 |
< |
|
154 |
< |
// **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG |
155 |
< |
// **** Please ignore this block of code, it's just "copy/paste" :) |
156 |
< |
|
157 |
< |
// get the config |
158 |
< |
Configuration myConfig = configManager.getConfiguration(ourName); |
159 |
< |
|
160 |
< |
logger.write(toString, Logger.SYSINIT, "configured"); |
161 |
< |
|
162 |
< |
// **** END COMMENT |
163 |
< |
|
164 |
< |
// **** INITIAL FILTER MANAGER COMMUNICATIONS HERE |
165 |
< |
|
166 |
< |
// **** END COMMENT |
84 |
< |
|
85 |
< |
logger.write(toString, Logger.SYSINIT, "starting RootFilter"); |
86 |
< |
|
87 |
< |
/************************************************************** |
88 |
< |
Here would be an ideal place to start another thread to do |
89 |
< |
the listening part of the Filter. Ideally it should just be |
90 |
< |
created and then run(). It may be necessary to pass some of |
91 |
< |
the following parameters into the thread by the constructor. |
92 |
< |
|
93 |
< |
Logger logger |
94 |
< |
- a reference to a Logger object |
95 |
< |
FilterManager filterManager |
96 |
< |
- a reference to the system filter manager |
97 |
< |
ConfigurationManager configManager |
98 |
< |
- a reference to the system configuration manager |
99 |
< |
Configuration myConfig |
100 |
< |
- a reference to the configuration object for this |
101 |
< |
filter instance |
102 |
< |
String ourName |
103 |
< |
- our "identifier" name |
104 |
< |
|
105 |
< |
**************************************************************/ |
106 |
< |
|
107 |
< |
// NOTE: |
108 |
< |
// We will not need to bind to the ORB when the FilterManager |
109 |
< |
// is running :) |
110 |
< |
|
111 |
< |
// create the RootFilterServant |
112 |
< |
RootFilterServant rfServant = new RootFilterServant(logger, ourName); |
113 |
< |
|
114 |
< |
// and advertise it to the naming context |
115 |
< |
objRef = poa.servant_to_reference(rfServant); |
116 |
< |
ncRef.bind(ncRef.to_name("iscream.Filter."+ourName), objRef); |
117 |
< |
|
118 |
< |
// start the POA off |
119 |
< |
poa.the_POAManager().activate(); |
120 |
< |
|
121 |
< |
logger.write(toString, Logger.SYSINIT, "started"); |
122 |
< |
|
123 |
< |
// now we are running, we just need to serve |
124 |
< |
// so we ask the orb to block for us until it has finished |
125 |
< |
orb.run(); |
126 |
< |
|
127 |
< |
} catch (Exception e) { |
128 |
< |
System.err.println("FILTER ERROR: " + e); |
129 |
< |
e.printStackTrace(System.out); |
140 |
> |
// RootFilterServant start (for inbound child filter data) |
141 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
142 |
> |
RootFilterServant filterServant = new RootFilterServant(queue); |
143 |
> |
// bind to the naming service as a filter |
144 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME); |
145 |
> |
|
146 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
147 |
> |
|
148 |
> |
} |
149 |
> |
|
150 |
> |
/** |
151 |
> |
* Does a dependency check. Used mainly at startup to |
152 |
> |
* see if the required dependencies (components) are up |
153 |
> |
* and running. |
154 |
> |
* |
155 |
> |
* @return a boolean value, true if the depdencies are satisfied |
156 |
> |
*/ |
157 |
> |
public boolean depCheck() { |
158 |
> |
org.omg.CORBA.Object obj; |
159 |
> |
|
160 |
> |
// first we need to check the Configuration system is available |
161 |
> |
try { |
162 |
> |
// first check the ConfigurationManager is alive |
163 |
> |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
164 |
> |
} catch(ComponentCORBAException e) { |
165 |
> |
System.err.println(toString() + ": Dependency Failure: "+e); |
166 |
> |
return false; |
167 |
|
} |
168 |
+ |
|
169 |
+ |
// next we need to check which client interfaces *should* |
170 |
+ |
// be active, and check them. Note they do not have to |
171 |
+ |
// be enabled, and we should check this. |
172 |
+ |
// -- each check only forces a dependency if it's configured |
173 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
174 |
+ |
// first check the client interface |
175 |
+ |
try { |
176 |
+ |
String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName"); |
177 |
+ |
obj = _refman.getCORBARef("iscream.ClientInterface." + cli); |
178 |
+ |
} catch(ComponentCORBAException e) { |
179 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
180 |
+ |
return false; |
181 |
+ |
} catch(PropertyNotFoundException e) { |
182 |
+ |
System.err.println(toString() + ": Client interface not configured and thus not enabled."); |
183 |
+ |
} |
184 |
+ |
// second check the database interface |
185 |
+ |
try { |
186 |
+ |
String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName"); |
187 |
+ |
obj = _refman.getCORBARef("iscream.ClientInterface." + dbi); |
188 |
+ |
} catch(ComponentCORBAException e) { |
189 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
190 |
+ |
return false; |
191 |
+ |
} catch(PropertyNotFoundException e) { |
192 |
+ |
System.err.println(toString() + ": Database interface not configured and thus not enabled."); |
193 |
+ |
} |
194 |
+ |
|
195 |
+ |
// dependency check suceeded |
196 |
+ |
return true; |
197 |
|
} |
198 |
< |
|
199 |
< |
/** |
200 |
< |
* A simple method to print the usage of this class. |
201 |
< |
* It never returns, but instead exits to the system |
202 |
< |
* with a value 1, to indicate the system did not start |
203 |
< |
* properly. |
198 |
> |
|
199 |
> |
/** |
200 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
201 |
> |
* method to provide clean logging (every class should have this). |
202 |
> |
* |
203 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
204 |
> |
* to format the toString() |
205 |
> |
* |
206 |
> |
* @return the name of this class and its CVS revision |
207 |
|
*/ |
208 |
< |
public static void usage() { |
209 |
< |
System.out.println("USAGE: java RootFilter <name>"); |
210 |
< |
System.out.println("WHERE <name>:"); |
211 |
< |
System.out.println(" The unique identifier for the RootFilter in the system."); |
212 |
< |
System.exit(1); |
208 |
> |
public String toString() { |
209 |
> |
return FormatName.getName( |
210 |
> |
NAME, |
211 |
> |
getClass().getName(), |
212 |
> |
REVISION); |
213 |
|
} |
214 |
|
|
146 |
– |
//---CONSTRUCTORS--- |
147 |
– |
|
148 |
– |
//---PUBLIC METHODS--- |
149 |
– |
|
215 |
|
//---PRIVATE METHODS--- |
216 |
|
|
217 |
|
//---ACCESSOR/MUTATOR METHODS--- |
218 |
|
|
219 |
|
//---ATTRIBUTES--- |
220 |
|
|
221 |
+ |
/** |
222 |
+ |
* This holds a reference to the |
223 |
+ |
* system logger that is being used. |
224 |
+ |
*/ |
225 |
+ |
private Logger _logger; |
226 |
+ |
|
227 |
+ |
/** |
228 |
+ |
* A reference to the reference manager in use |
229 |
+ |
*/ |
230 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
231 |
+ |
|
232 |
|
//---STATIC ATTRIBUTES--- |
233 |
+ |
|
234 |
+ |
/** |
235 |
+ |
* The friendly name for this component, used by |
236 |
+ |
* all related classes. |
237 |
+ |
* This is set from the configuration. |
238 |
+ |
*/ |
239 |
+ |
public static String NAME; |
240 |
|
|
241 |
< |
} |
241 |
> |
} |