7 |
|
import uk.ac.ukc.iscream.clientinterface.*; |
8 |
|
|
9 |
|
/** |
10 |
< |
* A Filter 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) { |
27 |
< |
// *************************************** |
28 |
< |
// VERY TEMPORARY - will find a better way |
29 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
30 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
31 |
< |
// *************************************** |
31 |
> |
//---CONSTRUCTORS--- |
32 |
|
|
33 |
< |
ReferenceManager refman = ReferenceManager.init(null, null); |
34 |
< |
|
35 |
< |
// can't have a real toString() :) |
36 |
< |
String toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
33 |
> |
//---PUBLIC METHODS--- |
34 |
|
|
35 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); |
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 |
< |
Configuration config = refman.getCM().getConfiguration("RootFilter"); |
47 |
> |
Configuration config = _refman.getCM().getConfiguration("RootFilter"); |
48 |
|
if (config == null) { |
49 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain configuration" + |
50 |
< |
" Advise you check the i-scream log for more information."); |
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 |
< |
refman.getLogger().write(toString, Logger.FATAL, "required config property not present"); |
60 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" + |
61 |
< |
" Advise you check the i-scream log for more information."); |
62 |
< |
|
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 |
|
// now we have the name of the Root Filter we set it |
66 |
< |
refman.setName(ourName); |
63 |
< |
toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
64 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "configured"); |
65 |
< |
|
66 |
< |
// get reference to the client interfaces - the real time one |
67 |
< |
ClientInterface ciReal = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
68 |
< |
// - the db one ... but it's not done yet |
69 |
< |
//ClientInterface ciDB = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
70 |
< |
// so for the time being we null it. |
71 |
< |
ClientInterface ciDB = null; |
72 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
66 |
> |
NAME = ourName; |
67 |
|
|
68 |
< |
ClientInterface[] clientInterfaces = {ciReal, ciDB}; |
68 |
> |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
69 |
|
|
70 |
+ |
ClientInterface ciReal = null, ciDB = null; |
71 |
+ |
// get reference to the client interfaces - the real time one |
72 |
+ |
if (realInterface != null) { |
73 |
+ |
ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
74 |
+ |
} |
75 |
+ |
// get reference to the client interfaces - and the db one |
76 |
+ |
if (dbInterface != null) { |
77 |
+ |
ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
78 |
+ |
} |
79 |
+ |
|
80 |
+ |
ClientInterface[] clientInterfaces; |
81 |
+ |
if (realInterface == null) { |
82 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface); |
83 |
+ |
clientInterfaces = new ClientInterface[] {ciDB}; |
84 |
+ |
} else if (dbInterface == null) { |
85 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface); |
86 |
+ |
clientInterfaces = new ClientInterface[] {ciReal}; |
87 |
+ |
} else { |
88 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
89 |
+ |
clientInterfaces = new ClientInterface[] {ciReal, ciDB}; |
90 |
+ |
} |
91 |
+ |
|
92 |
|
// RootFilterServant start (for inbound child filter data) |
93 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "starting Root Filter"); |
93 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
94 |
|
RootFilterServant filterServant = new RootFilterServant(clientInterfaces); |
95 |
|
// bind to the naming service as a filter |
96 |
< |
refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName()); |
96 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter." + _name); |
97 |
|
|
98 |
< |
// start the POA off |
83 |
< |
// now we are running, we just need to serve |
84 |
< |
// so we ask the orb to block for us until it has finished |
85 |
< |
refman.activatePOA(); |
86 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "started"); |
87 |
< |
refman.getORB().run(); |
98 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
99 |
|
} |
100 |
< |
|
101 |
< |
/** |
102 |
< |
* A simple method to print the usage of this class. |
103 |
< |
* It never returns, but instead exits to the system |
104 |
< |
* with a value 1, to indicate the system did not start |
105 |
< |
* properly. |
100 |
> |
|
101 |
> |
/** |
102 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
103 |
> |
* method to provide clean logging (every class should have this). |
104 |
> |
* |
105 |
> |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
106 |
> |
* to format the toString() |
107 |
> |
* |
108 |
> |
* @return the name of this class and its CVS revision |
109 |
|
*/ |
110 |
< |
public static void usage() { |
111 |
< |
System.out.println("USAGE: java FilterMain <name>"); |
112 |
< |
System.out.println("WHERE <name>:"); |
113 |
< |
System.out.println(" The unique identifier for the Filter in the system."); |
114 |
< |
System.exit(1); |
110 |
> |
public String toString() { |
111 |
> |
return FormatName.getName( |
112 |
> |
_name, |
113 |
> |
getClass().getName(), |
114 |
> |
REVISION); |
115 |
|
} |
116 |
|
|
103 |
– |
//---CONSTRUCTORS--- |
104 |
– |
|
105 |
– |
//---PUBLIC METHODS--- |
106 |
– |
|
117 |
|
//---PRIVATE METHODS--- |
118 |
|
|
119 |
|
//---ACCESSOR/MUTATOR METHODS--- |
120 |
|
|
121 |
|
//---ATTRIBUTES--- |
122 |
|
|
123 |
+ |
/** |
124 |
+ |
* This is the friendly identifier of the |
125 |
+ |
* component this class is running in. |
126 |
+ |
* eg, a Filter may be called "filter1", |
127 |
+ |
* If this class does not have an owning |
128 |
+ |
* component, a name from the configuration |
129 |
+ |
* can be placed here. This name could also |
130 |
+ |
* be changed to null for utility classes. |
131 |
+ |
*/ |
132 |
+ |
private String _name = RootFilter.NAME; |
133 |
+ |
|
134 |
+ |
/** |
135 |
+ |
* This holds a reference to the |
136 |
+ |
* system logger that is being used. |
137 |
+ |
*/ |
138 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
139 |
+ |
|
140 |
+ |
/** |
141 |
+ |
* A reference to the reference manager in use |
142 |
+ |
*/ |
143 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
144 |
+ |
|
145 |
|
//---STATIC ATTRIBUTES--- |
146 |
+ |
|
147 |
+ |
/** |
148 |
+ |
* The friendly name for this component, used by |
149 |
+ |
* all related classes. |
150 |
+ |
* This is set from the configuration. |
151 |
+ |
*/ |
152 |
+ |
public static String NAME; |
153 |
|
|
154 |
|
} |