1 |
+ |
|
2 |
|
//---PACKAGE DECLARATION--- |
3 |
+ |
package uk.org.iscream.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.util.*; |
7 |
> |
import uk.org.iscream.core.*; |
8 |
> |
import uk.org.iscream.componentmanager.*; |
9 |
> |
import uk.org.iscream.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 |
> |
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 |
|
} |
67 |
|
|
68 |
< |
// can't have a real toString() :) |
69 |
< |
String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
68 |
> |
ClientInterface ciReal = null, ciDB = null; |
69 |
> |
// get reference to the client interfaces - the real time one |
70 |
> |
if (realInterface != null) { |
71 |
> |
ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
72 |
> |
} |
73 |
> |
// get reference to the client interfaces - and the db one |
74 |
> |
if (dbInterface != null) { |
75 |
> |
ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
76 |
> |
} |
77 |
> |
|
78 |
> |
// setup a queue |
79 |
> |
Queue queue = new Queue(); |
80 |
|
|
81 |
< |
try { |
82 |
< |
ORB orb = ORB.init(args, null); |
83 |
< |
|
84 |
< |
// something to hold objects |
85 |
< |
org.omg.CORBA.Object objRef = null; |
86 |
< |
|
87 |
< |
// get the Root POA |
88 |
< |
objRef = orb.resolve_initial_references("RootPOA"); |
89 |
< |
POA poa = POAHelper.narrow(objRef); |
90 |
< |
|
91 |
< |
// get a hook to the name service |
92 |
< |
objRef = orb.resolve_initial_references("NameService"); |
93 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
81 |
> |
// startup a monitor on this queue |
82 |
> |
try { |
83 |
> |
// try to get the interval, if this fails, we won't start up the monitor |
84 |
> |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval")); |
85 |
> |
String queueName = NAME + " RootFilter"; |
86 |
> |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
87 |
> |
} catch (PropertyNotFoundException e) { |
88 |
> |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
89 |
> |
} |
90 |
> |
|
91 |
> |
if (realInterface == null) { |
92 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface); |
93 |
> |
CIWrapper c = new CIWrapper(ciDB, queue); |
94 |
> |
c.start(); |
95 |
> |
} else if (dbInterface == null) { |
96 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface); |
97 |
> |
CIWrapper c = new CIWrapper(ciReal, queue); |
98 |
> |
c.start(); |
99 |
> |
} else { |
100 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
101 |
> |
CIWrapper c = new CIWrapper(ciReal, queue); |
102 |
> |
c.start(); |
103 |
> |
c = new CIWrapper(ciDB, queue); |
104 |
> |
c.start(); |
105 |
> |
} |
106 |
|
|
107 |
< |
// get a ref to the ConfigurationManager, Logger & the FilterManager |
108 |
< |
|
109 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
110 |
< |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
111 |
< |
|
112 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
113 |
< |
Logger logger = LoggerHelper.narrow(objRef); |
114 |
< |
|
115 |
< |
//objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager")); |
116 |
< |
//FilterManager filterManager = FilterManagerHelper.narrow(objRef); |
117 |
< |
|
118 |
< |
logger.write(toString, Logger.SYSINIT, "coming up"); |
119 |
< |
|
120 |
< |
|
121 |
< |
// **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG |
122 |
< |
// **** Please ignore this block of code, it's just "copy/paste" :) |
123 |
< |
|
124 |
< |
// get the config |
125 |
< |
Configuration myConfig = configManager.getConfiguration(ourName); |
126 |
< |
|
127 |
< |
logger.write(toString, Logger.SYSINIT, "configured"); |
128 |
< |
|
129 |
< |
// **** END COMMENT |
130 |
< |
|
131 |
< |
// **** INITIAL FILTER MANAGER COMMUNICATIONS HERE |
132 |
< |
|
133 |
< |
// **** END COMMENT |
134 |
< |
|
135 |
< |
logger.write(toString, Logger.SYSINIT, "starting RootFilter"); |
136 |
< |
|
137 |
< |
/************************************************************** |
138 |
< |
Here would be an ideal place to start another thread to do |
139 |
< |
the listening part of the Filter. Ideally it should just be |
140 |
< |
created and then run(). It may be necessary to pass some of |
141 |
< |
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); |
107 |
> |
// RootFilterServant start (for inbound child filter data) |
108 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
109 |
> |
RootFilterServant filterServant = new RootFilterServant(queue); |
110 |
> |
// bind to the naming service as a filter |
111 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME); |
112 |
> |
|
113 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
114 |
> |
|
115 |
> |
} |
116 |
> |
|
117 |
> |
/** |
118 |
> |
* Does a dependency check. Used mainly at startup to |
119 |
> |
* see if the required dependencies (components) are up |
120 |
> |
* and running. |
121 |
> |
* |
122 |
> |
* @return a boolean value, true if the depdencies are satisfied |
123 |
> |
*/ |
124 |
> |
public boolean depCheck() { |
125 |
> |
try { |
126 |
> |
org.omg.CORBA.Object obj; |
127 |
> |
// first check the ConfigurationManager is alive |
128 |
> |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
129 |
> |
// then get some info on the CLI and DBI |
130 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
131 |
> |
String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName"); |
132 |
> |
String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName"); |
133 |
> |
// finally check the CLI and DBI are alive |
134 |
> |
obj = _refman.getCORBARef("iscream.ClientInterface." + cli); |
135 |
> |
obj = _refman.getCORBARef("iscream.ClientInterface." + dbi); |
136 |
> |
} catch(ComponentCORBAException e) { |
137 |
> |
System.err.println(toString() + ": Dependency Failure: "+e); |
138 |
> |
return false; |
139 |
> |
} catch(PropertyNotFoundException e) { |
140 |
> |
System.err.println(toString() + ": Unable to obtain configuration: "+e); |
141 |
> |
return false; |
142 |
|
} |
143 |
+ |
// dependency check suceeded |
144 |
+ |
return true; |
145 |
|
} |
146 |
< |
|
147 |
< |
/** |
148 |
< |
* A simple method to print the usage of this class. |
149 |
< |
* It never returns, but instead exits to the system |
150 |
< |
* with a value 1, to indicate the system did not start |
151 |
< |
* properly. |
146 |
> |
|
147 |
> |
/** |
148 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
149 |
> |
* method to provide clean logging (every class should have this). |
150 |
> |
* |
151 |
> |
* This uses the uk.org.iscream.util.NameFormat class |
152 |
> |
* to format the toString() |
153 |
> |
* |
154 |
> |
* @return the name of this class and its CVS revision |
155 |
|
*/ |
156 |
< |
public static void usage() { |
157 |
< |
System.out.println("USAGE: java RootFilter <name>"); |
158 |
< |
System.out.println("WHERE <name>:"); |
159 |
< |
System.out.println(" The unique identifier for the RootFilter in the system."); |
160 |
< |
System.exit(1); |
156 |
> |
public String toString() { |
157 |
> |
return FormatName.getName( |
158 |
> |
NAME, |
159 |
> |
getClass().getName(), |
160 |
> |
REVISION); |
161 |
|
} |
162 |
|
|
146 |
– |
//---CONSTRUCTORS--- |
147 |
– |
|
148 |
– |
//---PUBLIC METHODS--- |
149 |
– |
|
163 |
|
//---PRIVATE METHODS--- |
164 |
|
|
165 |
|
//---ACCESSOR/MUTATOR METHODS--- |
166 |
|
|
167 |
|
//---ATTRIBUTES--- |
168 |
|
|
169 |
+ |
/** |
170 |
+ |
* This holds a reference to the |
171 |
+ |
* system logger that is being used. |
172 |
+ |
*/ |
173 |
+ |
private Logger _logger; |
174 |
+ |
|
175 |
+ |
/** |
176 |
+ |
* A reference to the reference manager in use |
177 |
+ |
*/ |
178 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
179 |
+ |
|
180 |
|
//---STATIC ATTRIBUTES--- |
181 |
+ |
|
182 |
+ |
/** |
183 |
+ |
* The friendly name for this component, used by |
184 |
+ |
* all related classes. |
185 |
+ |
* This is set from the configuration. |
186 |
+ |
*/ |
187 |
+ |
public static String NAME; |
188 |
|
|
189 |
< |
} |
189 |
> |
} |