1 |
//---PACKAGE DECLARATION--- |
2 |
|
3 |
//---IMPORTS--- |
4 |
import uk.ac.ukc.iscream.core.*; |
5 |
import uk.ac.ukc.iscream.filter.*; |
6 |
import org.omg.CORBA.*; |
7 |
import org.omg.CosNaming.*; |
8 |
import org.omg.PortableServer.*; |
9 |
|
10 |
/** |
11 |
* A RootFilter Startup Class |
12 |
* |
13 |
* @author $Author$ |
14 |
* @version $Id$ |
15 |
*/ |
16 |
class RootFilter { |
17 |
|
18 |
//---FINAL ATTRIBUTES--- |
19 |
|
20 |
/** |
21 |
* The current CVS revision of this class |
22 |
*/ |
23 |
public static final String REVISION = "$Revision: 1.1 $"; |
24 |
|
25 |
//---STATIC METHODS--- |
26 |
|
27 |
public static void main(String[] args) { |
28 |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
29 |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
30 |
|
31 |
// get our name from the command line |
32 |
String ourName = ""; |
33 |
if (args.length == 1) { |
34 |
ourName = args[0]; |
35 |
} |
36 |
else { |
37 |
usage(); |
38 |
} |
39 |
|
40 |
// 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); |
56 |
|
57 |
// get a ref to the ConfigurationManager, Logger & the FilterManager |
58 |
|
59 |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
60 |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
61 |
|
62 |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
63 |
Logger logger = LoggerHelper.narrow(objRef); |
64 |
|
65 |
//objRef = ncRef.resolve(ncRef.to_name("iscream.FilterManager")); |
66 |
//FilterManager filterManager = FilterManagerHelper.narrow(objRef); |
67 |
|
68 |
logger.write(toString, Logger.SYSINIT, "coming up"); |
69 |
|
70 |
|
71 |
// **** 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 |
} |
131 |
} |
132 |
|
133 |
/** |
134 |
* A simple method to print the usage of this class. |
135 |
* It never returns, but instead exits to the system |
136 |
* with a value 1, to indicate the system did not start |
137 |
* properly. |
138 |
*/ |
139 |
public static void usage() { |
140 |
System.out.println("USAGE: java RootFilter <name>"); |
141 |
System.out.println("WHERE <name>:"); |
142 |
System.out.println(" The unique identifier for the RootFilter in the system."); |
143 |
System.exit(1); |
144 |
} |
145 |
|
146 |
//---CONSTRUCTORS--- |
147 |
|
148 |
//---PUBLIC METHODS--- |
149 |
|
150 |
//---PRIVATE METHODS--- |
151 |
|
152 |
//---ACCESSOR/MUTATOR METHODS--- |
153 |
|
154 |
//---ATTRIBUTES--- |
155 |
|
156 |
//---STATIC ATTRIBUTES--- |
157 |
|
158 |
} |