4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.util.*; |
6 |
|
import uk.ac.ukc.iscream.core.*; |
7 |
+ |
import uk.ac.ukc.iscream.componentmanager.*; |
8 |
|
import uk.ac.ukc.iscream.clientinterface.*; |
9 |
|
|
10 |
|
/** |
11 |
< |
* A Filter Startup Class |
11 |
> |
* The root filter is what all filters talk to |
12 |
> |
* Hosts cannot talk to this implementation of a filter. |
13 |
> |
* It provides hooks to all data interfaces for the system |
14 |
> |
* namely the client interface and the db interface. |
15 |
> |
* This is an i-scream component that starts the |
16 |
> |
* RootFilter services. |
17 |
|
* |
18 |
|
* @author $Author$ |
19 |
|
* @version $Id$ |
20 |
|
*/ |
21 |
< |
class RootFilterMain { |
21 |
> |
public class RootFilter implements Component { |
22 |
|
|
23 |
|
//---FINAL ATTRIBUTES--- |
24 |
|
|
26 |
|
* The current CVS revision of this class |
27 |
|
*/ |
28 |
|
public static final String REVISION = "$Revision$"; |
29 |
< |
|
29 |
> |
|
30 |
|
//---STATIC METHODS--- |
31 |
|
|
32 |
< |
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 |
< |
// *************************************** |
32 |
> |
//---CONSTRUCTORS--- |
33 |
|
|
34 |
< |
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) + ")"; |
34 |
> |
//---PUBLIC METHODS--- |
35 |
|
|
36 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); |
36 |
> |
/** |
37 |
> |
* This starts the Root Filter for the system |
38 |
> |
*/ |
39 |
> |
public void start() throws ComponentStartException { |
40 |
> |
|
41 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
42 |
|
|
43 |
|
// configuration variables we require |
44 |
|
String ourName = null; |
45 |
|
String realInterface = null; |
46 |
|
String dbInterface = null; |
47 |
|
|
48 |
< |
Configuration config = refman.getCM().getConfiguration("RootFilter"); |
48 |
> |
Configuration config = _refman.getCM().getConfiguration("RootFilter"); |
49 |
|
if (config == null) { |
50 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain configuration" + |
51 |
< |
" Advise you check the i-scream log for more information."); |
50 |
> |
System.err.println("CRITICAL:Unable to obtain configuration" + |
51 |
> |
"\n Advise you check the i-scream log for more information."); |
52 |
> |
_logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration"); |
53 |
> |
System.exit(1); |
54 |
|
} else { |
55 |
|
try { |
56 |
|
ourName = config.getProperty("RootFilter.name"); |
57 |
|
realInterface = config.getProperty("RootFilter.realtimeInterfaceName"); |
58 |
|
dbInterface = config.getProperty("RootFilter.dbInterfaceName"); |
59 |
|
} catch (org.omg.CORBA.MARSHAL e) { |
60 |
< |
refman.getLogger().write(toString, Logger.FATAL, "required config property not present"); |
61 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" + |
62 |
< |
" Advise you check the i-scream log for more information."); |
63 |
< |
|
60 |
> |
System.err.println ("CRITICAL:Unable to obtain required configuration property" + |
61 |
> |
"\n Advise you check the i-scream log for more information."); |
62 |
> |
_logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present"); |
63 |
> |
System.exit(1); |
64 |
|
} |
65 |
|
} |
66 |
|
// now we have the name of the Root Filter we set it |
67 |
< |
refman.setName(ourName); |
68 |
< |
toString = "RootFilter{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
69 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "configured"); |
70 |
< |
|
67 |
> |
NAME = ourName; |
68 |
> |
|
69 |
> |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
70 |
> |
|
71 |
> |
ClientInterface ciReal = null, ciDB = null; |
72 |
|
// get reference to the client interfaces - the real time one |
73 |
< |
ClientInterface ciReal = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
74 |
< |
// - the db one ... but it's not done yet |
75 |
< |
//ClientInterface ciDB = ClientInterfaceHelper.narrow(refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
76 |
< |
// so for the time being we null it. |
77 |
< |
ClientInterface ciDB = null; |
78 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
73 |
> |
if (realInterface != null) { |
74 |
> |
ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
75 |
> |
} |
76 |
> |
// get reference to the client interfaces - and the db one |
77 |
> |
if (dbInterface != null) { |
78 |
> |
ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
79 |
> |
} |
80 |
|
|
81 |
< |
ClientInterface[] clientInterfaces = {ciReal, ciDB}; |
81 |
> |
Queue queue = new Queue(); |
82 |
|
|
83 |
+ |
if (realInterface == null) { |
84 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface); |
85 |
+ |
CIWrapper c = new CIWrapper(ciDB, queue); |
86 |
+ |
c.start(); |
87 |
+ |
} else if (dbInterface == null) { |
88 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface); |
89 |
+ |
CIWrapper c = new CIWrapper(ciReal, queue); |
90 |
+ |
c.start(); |
91 |
+ |
} else { |
92 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
93 |
+ |
CIWrapper c = new CIWrapper(ciReal, queue); |
94 |
+ |
c.start(); |
95 |
+ |
c = new CIWrapper(ciDB, queue); |
96 |
+ |
c.start(); |
97 |
+ |
} |
98 |
+ |
|
99 |
|
// RootFilterServant start (for inbound child filter data) |
100 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "starting Root Filter"); |
101 |
< |
RootFilterServant filterServant = new RootFilterServant(clientInterfaces); |
100 |
> |
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
101 |
> |
RootFilterServant filterServant = new RootFilterServant(queue); |
102 |
|
// bind to the naming service as a filter |
103 |
< |
refman.bindToOrb(filterServant, "iscream.Filter." + refman.getName()); |
103 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME); |
104 |
|
|
105 |
< |
// 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(); |
105 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
106 |
|
} |
107 |
< |
|
108 |
< |
/** |
109 |
< |
* A simple method to print the usage of this class. |
110 |
< |
* It never returns, but instead exits to the system |
111 |
< |
* with a value 1, to indicate the system did not start |
112 |
< |
* properly. |
107 |
> |
|
108 |
> |
/** |
109 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
110 |
> |
* method to provide clean logging (every class should have this). |
111 |
> |
* |
112 |
> |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
113 |
> |
* to format the toString() |
114 |
> |
* |
115 |
> |
* @return the name of this class and its CVS revision |
116 |
|
*/ |
117 |
< |
public static void usage() { |
118 |
< |
System.out.println("USAGE: java FilterMain <name>"); |
119 |
< |
System.out.println("WHERE <name>:"); |
120 |
< |
System.out.println(" The unique identifier for the Filter in the system."); |
121 |
< |
System.exit(1); |
117 |
> |
public String toString() { |
118 |
> |
return FormatName.getName( |
119 |
> |
NAME, |
120 |
> |
getClass().getName(), |
121 |
> |
REVISION); |
122 |
|
} |
123 |
|
|
103 |
– |
//---CONSTRUCTORS--- |
104 |
– |
|
105 |
– |
//---PUBLIC METHODS--- |
106 |
– |
|
124 |
|
//---PRIVATE METHODS--- |
125 |
|
|
126 |
|
//---ACCESSOR/MUTATOR METHODS--- |
127 |
|
|
128 |
|
//---ATTRIBUTES--- |
129 |
|
|
130 |
+ |
/** |
131 |
+ |
* This holds a reference to the |
132 |
+ |
* system logger that is being used. |
133 |
+ |
*/ |
134 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
135 |
+ |
|
136 |
+ |
/** |
137 |
+ |
* A reference to the reference manager in use |
138 |
+ |
*/ |
139 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
140 |
+ |
|
141 |
|
//---STATIC ATTRIBUTES--- |
142 |
+ |
|
143 |
+ |
/** |
144 |
+ |
* The friendly name for this component, used by |
145 |
+ |
* all related classes. |
146 |
+ |
* This is set from the configuration. |
147 |
+ |
*/ |
148 |
+ |
public static String NAME; |
149 |
|
|
150 |
|
} |