1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.iscream.rootfilter; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
+ |
import uk.ac.ukc.iscream.util.*; |
6 |
|
import uk.ac.ukc.iscream.core.*; |
7 |
< |
import uk.ac.ukc.iscream.filter.*; |
6 |
< |
import org.omg.CORBA.*; |
7 |
< |
import org.omg.CosNaming.*; |
8 |
< |
import org.omg.PortableServer.*; |
7 |
> |
import uk.ac.ukc.iscream.clientinterface.*; |
8 |
|
|
9 |
|
/** |
10 |
< |
* A RootFilter Startup Class |
10 |
> |
* The root filter is what all filters talk to |
11 |
> |
* Hosts cannot talk to this implementation of a filter. |
12 |
> |
* It provides hooks to all data interfaces for the system |
13 |
> |
* namely the client interface and the db interface. |
14 |
> |
* This is an i-scream component that starts the |
15 |
> |
* RootFilter services. |
16 |
|
* |
17 |
|
* @author $Author$ |
18 |
|
* @version $Id$ |
19 |
|
*/ |
20 |
< |
class RootFilterMain { |
20 |
> |
public class RootFilter implements uk.ac.ukc.iscream.util.Component { |
21 |
|
|
22 |
|
//---FINAL ATTRIBUTES--- |
23 |
|
|
25 |
|
* The current CVS revision of this class |
26 |
|
*/ |
27 |
|
public static final String REVISION = "$Revision$"; |
28 |
< |
|
28 |
> |
|
29 |
|
//---STATIC METHODS--- |
30 |
|
|
31 |
< |
public static void main(String[] args) { |
32 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
33 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
31 |
> |
//---CONSTRUCTORS--- |
32 |
> |
|
33 |
> |
//---PUBLIC METHODS--- |
34 |
> |
|
35 |
> |
/** |
36 |
> |
* This starts the Root Filter for the system |
37 |
> |
*/ |
38 |
> |
public void start() throws ComponentStartException { |
39 |
> |
|
40 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
41 |
> |
|
42 |
> |
// configuration variables we require |
43 |
> |
String ourName = null; |
44 |
> |
String realInterface = null; |
45 |
> |
String dbInterface = null; |
46 |
|
|
47 |
< |
// get our name from the command line |
48 |
< |
String ourName = ""; |
49 |
< |
if (args.length == 1) { |
50 |
< |
ourName = args[0]; |
47 |
> |
Configuration config = _refman.getCM().getConfiguration("RootFilter"); |
48 |
> |
if (config == null) { |
49 |
> |
System.err.println("CRITICAL:Unable to obtain configuration" + |
50 |
> |
"\n Advise you check the i-scream log for more information."); |
51 |
> |
_logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration"); |
52 |
> |
System.exit(1); |
53 |
> |
} else { |
54 |
> |
try { |
55 |
> |
ourName = config.getProperty("RootFilter.name"); |
56 |
> |
realInterface = config.getProperty("RootFilter.realtimeInterfaceName"); |
57 |
> |
dbInterface = config.getProperty("RootFilter.dbInterfaceName"); |
58 |
> |
} catch (org.omg.CORBA.MARSHAL e) { |
59 |
> |
System.err.println ("CRITICAL:Unable to obtain required configuration property" + |
60 |
> |
"\n Advise you check the i-scream log for more information."); |
61 |
> |
_logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present"); |
62 |
> |
System.exit(1); |
63 |
> |
} |
64 |
|
} |
65 |
< |
else { |
66 |
< |
usage(); |
38 |
< |
} |
65 |
> |
// now we have the name of the Root Filter we set it |
66 |
> |
NAME = ourName; |
67 |
|
|
68 |
< |
// can't have a real toString() :) |
41 |
< |
String toString = "RootFilter{" + ourName + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
42 |
< |
|
43 |
< |
try { |
44 |
< |
ORB orb = ORB.init(args, null); |
45 |
< |
|
46 |
< |
// something to hold objects |
47 |
< |
org.omg.CORBA.Object objRef = null; |
48 |
< |
|
49 |
< |
// get the Root POA |
50 |
< |
objRef = orb.resolve_initial_references("RootPOA"); |
51 |
< |
POA poa = POAHelper.narrow(objRef); |
52 |
< |
|
53 |
< |
// get a hook to the name service |
54 |
< |
objRef = orb.resolve_initial_references("NameService"); |
55 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
68 |
> |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
69 |
|
|
70 |
< |
// get a ref to the ConfigurationManager, Logger & the FilterManager |
71 |
< |
|
72 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
73 |
< |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
74 |
< |
|
75 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
76 |
< |
Logger logger = LoggerHelper.narrow(objRef); |
77 |
< |
|
78 |
< |
//objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager")); |
79 |
< |
//FilterManager filterManager = FilterManagerHelper.narrow(objRef); |
80 |
< |
|
81 |
< |
logger.write(toString, Logger.SYSINIT, "coming up"); |
82 |
< |
|
83 |
< |
|
84 |
< |
// **** THIS SECTION WILL NEED CHANGING TO GET RELEVANT CONFIG |
72 |
< |
// **** Please ignore this block of code, it's just "copy/paste" :) |
73 |
< |
|
74 |
< |
// get the config |
75 |
< |
Configuration myConfig = configManager.getConfiguration(ourName); |
76 |
< |
|
77 |
< |
logger.write(toString, Logger.SYSINIT, "configured"); |
78 |
< |
|
79 |
< |
// **** END COMMENT |
80 |
< |
|
81 |
< |
// **** INITIAL FILTER MANAGER COMMUNICATIONS HERE |
82 |
< |
|
83 |
< |
// **** 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); |
130 |
< |
} |
70 |
> |
// get reference to the client interfaces - the real time one |
71 |
> |
ClientInterface ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
72 |
> |
// get reference to the client interfaces - and the db one |
73 |
> |
ClientInterface ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
74 |
> |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
75 |
> |
|
76 |
> |
ClientInterface[] clientInterfaces = {ciReal, ciDB}; |
77 |
> |
|
78 |
> |
// RootFilterServant start (for inbound child filter data) |
79 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
80 |
> |
RootFilterServant filterServant = new RootFilterServant(clientInterfaces); |
81 |
> |
// bind to the naming service as a filter |
82 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter." + _name); |
83 |
> |
|
84 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
85 |
|
} |
86 |
< |
|
87 |
< |
/** |
88 |
< |
* A simple method to print the usage of this class. |
89 |
< |
* It never returns, but instead exits to the system |
90 |
< |
* with a value 1, to indicate the system did not start |
91 |
< |
* properly. |
86 |
> |
|
87 |
> |
/** |
88 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
89 |
> |
* method to provide clean logging (every class should have this). |
90 |
> |
* |
91 |
> |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
92 |
> |
* to format the toString() |
93 |
> |
* |
94 |
> |
* @return the name of this class and its CVS revision |
95 |
|
*/ |
96 |
< |
public static void usage() { |
97 |
< |
System.out.println("USAGE: java RootFilter <name>"); |
98 |
< |
System.out.println("WHERE <name>:"); |
99 |
< |
System.out.println(" The unique identifier for the RootFilter in the system."); |
100 |
< |
System.exit(1); |
96 |
> |
public String toString() { |
97 |
> |
return FormatName.getName( |
98 |
> |
_name, |
99 |
> |
getClass().getName(), |
100 |
> |
REVISION); |
101 |
|
} |
102 |
|
|
146 |
– |
//---CONSTRUCTORS--- |
147 |
– |
|
148 |
– |
//---PUBLIC METHODS--- |
149 |
– |
|
103 |
|
//---PRIVATE METHODS--- |
104 |
|
|
105 |
|
//---ACCESSOR/MUTATOR METHODS--- |
106 |
|
|
107 |
|
//---ATTRIBUTES--- |
108 |
|
|
109 |
+ |
/** |
110 |
+ |
* This is the friendly identifier of the |
111 |
+ |
* component this class is running in. |
112 |
+ |
* eg, a Filter may be called "filter1", |
113 |
+ |
* If this class does not have an owning |
114 |
+ |
* component, a name from the configuration |
115 |
+ |
* can be placed here. This name could also |
116 |
+ |
* be changed to null for utility classes. |
117 |
+ |
*/ |
118 |
+ |
private String _name = RootFilter.NAME; |
119 |
+ |
|
120 |
+ |
/** |
121 |
+ |
* This holds a reference to the |
122 |
+ |
* system logger that is being used. |
123 |
+ |
*/ |
124 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
125 |
+ |
|
126 |
+ |
/** |
127 |
+ |
* A reference to the reference manager in use |
128 |
+ |
*/ |
129 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
130 |
+ |
|
131 |
|
//---STATIC ATTRIBUTES--- |
132 |
+ |
|
133 |
+ |
/** |
134 |
+ |
* The friendly name for this component, used by |
135 |
+ |
* all related classes. |
136 |
+ |
* This is set from the configuration. |
137 |
+ |
*/ |
138 |
+ |
public static String NAME; |
139 |
|
|
140 |
< |
} |
140 |
> |
} |