2 |
|
package uk.ac.ukc.iscream.filtermanager; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
+ |
import uk.ac.ukc.iscream.util.*; |
6 |
|
import uk.ac.ukc.iscream.core.*; |
6 |
– |
import uk.ac.ukc.iscream.filter.*; |
7 |
– |
import org.omg.CORBA.*; |
8 |
– |
import org.omg.CosNaming.*; |
7 |
|
|
8 |
|
/** |
9 |
< |
* A FilterManager |
9 |
> |
* The FilterManager handles initialisation |
10 |
> |
* of hosts with the system, allowing hosts to |
11 |
> |
* gain their configuration and a hook to a Filter |
12 |
> |
* to talk to. |
13 |
|
* |
14 |
|
* @author $Author$ |
15 |
|
* @version $Id$ |
16 |
|
*/ |
17 |
< |
class FilterManager { |
17 |
> |
public class FilterManager implements uk.ac.ukc.iscream.util.Component { |
18 |
|
|
19 |
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
23 |
|
*/ |
24 |
|
public static final String REVISION = "$Revision$"; |
25 |
|
|
26 |
+ |
/** |
27 |
+ |
* The friendly name for the FilterManager, used by |
28 |
+ |
* all related classes. |
29 |
+ |
*/ |
30 |
+ |
public static final String NAME = "FilterManager"; |
31 |
+ |
|
32 |
|
//---STATIC METHODS--- |
33 |
|
|
34 |
< |
public static void main(String[] args) { |
35 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
36 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
37 |
< |
|
38 |
< |
// can't have a real toString() :) |
39 |
< |
String toString = "FilterManager(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
40 |
< |
|
41 |
< |
try { |
35 |
< |
ORB orb = ORB.init(args, null); |
36 |
< |
|
37 |
< |
// something to hold objects |
38 |
< |
org.omg.CORBA.Object objRef = null; |
39 |
< |
|
40 |
< |
// get a hook to the name service |
41 |
< |
objRef = orb.resolve_initial_references("NameService"); |
42 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
34 |
> |
//---CONSTRUCTORS--- |
35 |
> |
|
36 |
> |
//---PUBLIC METHODS--- |
37 |
> |
|
38 |
> |
/** |
39 |
> |
* This method starts the FilterManager |
40 |
> |
*/ |
41 |
> |
public void start() throws ComponentStartException { |
42 |
|
|
43 |
< |
// get a ref to the Configurator & the Logger |
44 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
45 |
< |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
46 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
47 |
< |
Logger logger = LoggerHelper.narrow(objRef); |
48 |
< |
|
49 |
< |
logger.write(toString, Logger.SYSINIT, "coming up"); |
50 |
< |
|
51 |
< |
// create the servant |
52 |
< |
//FilterManagerServant servant = new FilterManagerServant(logger); |
53 |
< |
|
54 |
< |
// register the servant with the name service |
55 |
< |
//objRef = poa.servant_to_reference(servant); |
56 |
< |
//ncRef.bind(ncRef.to_name("iscream.FilterManager"), objRef); |
57 |
< |
|
58 |
< |
// start the POA off |
59 |
< |
//poa.the_POAManager().activate(); |
60 |
< |
|
62 |
< |
// get the config |
63 |
< |
Configuration myConfig = configManager.getConfiguration("FilterManager"); |
64 |
< |
|
65 |
< |
// some place holders for the configuration |
66 |
< |
int port = 0; |
67 |
< |
|
68 |
< |
// did we? |
69 |
< |
if (myConfig == null) { |
70 |
< |
System.out.println("Failed: is it there?, can you read it?"); |
43 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
44 |
> |
|
45 |
> |
// configuration variable we require |
46 |
> |
int listenPort = 0; |
47 |
> |
|
48 |
> |
Configuration config = _refman.getCM().getConfiguration("FilterManager"); |
49 |
> |
if (config == null) { |
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 |
> |
listenPort = Integer.parseInt(config.getProperty("FilterManager.listenPort")); |
57 |
> |
} catch (org.omg.CORBA.MARSHAL e) { |
58 |
> |
System.err.println ("CRITICAL:Unable to obtain required configuration property" + |
59 |
> |
"\n Advise you check the i-scream log for more information."); |
60 |
> |
_logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present"); |
61 |
|
System.exit(1); |
72 |
– |
} else { |
73 |
– |
|
74 |
– |
// get the property |
75 |
– |
try { |
76 |
– |
port = new Integer(myConfig.getProperty("FilterManager.listenPort")).intValue(); |
77 |
– |
} catch (org.omg.CORBA.MARSHAL e) { |
78 |
– |
System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back"); |
79 |
– |
System.exit(1); |
80 |
– |
} |
62 |
|
} |
82 |
– |
logger.write(toString, Logger.SYSMSG, "configured"); |
83 |
– |
logger.write(toString, Logger.SYSINIT, "starting listener"); |
84 |
– |
|
85 |
– |
HostListener hostListener = new HostListener(logger, configManager, port, ncRef); |
86 |
– |
hostListener.start(); |
87 |
– |
|
88 |
– |
logger.write(toString, Logger.SYSINIT, "started"); |
89 |
– |
|
90 |
– |
} catch (Exception e) { |
91 |
– |
System.err.println("FILTER MANAGER ERROR: " + e); |
92 |
– |
e.printStackTrace(System.out); |
63 |
|
} |
64 |
+ |
|
65 |
+ |
_logger.write(toString(), Logger.SYSMSG, "configured"); |
66 |
+ |
|
67 |
+ |
HostListener hostListener = new HostListener(listenPort); |
68 |
+ |
hostListener.start(); |
69 |
+ |
|
70 |
+ |
_logger.write(toString(), Logger.SYSINIT, "started"); |
71 |
|
} |
72 |
|
|
73 |
< |
//---CONSTRUCTORS--- |
73 |
> |
/** |
74 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
75 |
> |
* method to provide clean logging (every class should have this). |
76 |
> |
* |
77 |
> |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
78 |
> |
* to format the toString() |
79 |
> |
* |
80 |
> |
* @return the name of this class and its CVS revision |
81 |
> |
*/ |
82 |
> |
public String toString() { |
83 |
> |
return FormatName.getName( |
84 |
> |
_name, |
85 |
> |
this.getClass().getName(), |
86 |
> |
REVISION); |
87 |
> |
} |
88 |
|
|
98 |
– |
//---PUBLIC METHODS--- |
99 |
– |
|
89 |
|
//---PRIVATE METHODS--- |
90 |
|
|
91 |
|
//---ACCESSOR/MUTATOR METHODS--- |
92 |
|
|
93 |
|
//---ATTRIBUTES--- |
94 |
+ |
|
95 |
+ |
/** |
96 |
+ |
* This is the friendly identifier of the |
97 |
+ |
* component this class is running in. |
98 |
+ |
* eg, a Filter may be called "filter1", |
99 |
+ |
* If this class does not have an owning |
100 |
+ |
* component, a name from the configuration |
101 |
+ |
* can be placed here. This name could also |
102 |
+ |
* be changed to null for utility classes. |
103 |
+ |
*/ |
104 |
+ |
private String _name = FilterManager.NAME; |
105 |
+ |
|
106 |
+ |
/** |
107 |
+ |
* This holds a reference to the |
108 |
+ |
* system logger that is being used. |
109 |
+ |
*/ |
110 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
111 |
+ |
|
112 |
+ |
/** |
113 |
+ |
* A reference to the reference manager in use |
114 |
+ |
*/ |
115 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
116 |
|
|
117 |
|
//---STATIC ATTRIBUTES--- |
118 |
|
|