1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.org.iscream.cms.server.filtermanager; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
6 |
< |
import uk.ac.ukc.iscream.filter.*; |
7 |
< |
import org.omg.CORBA.*; |
7 |
< |
import org.omg.CosNaming.*; |
8 |
< |
import org.omg.PortableServer.*; |
5 |
> |
import uk.org.iscream.cms.server.util.*; |
6 |
> |
import uk.org.iscream.cms.server.core.*; |
7 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
8 |
|
|
9 |
|
/** |
10 |
< |
* A FilterManager |
10 |
> |
* The FilterManager handles initialisation |
11 |
> |
* of hosts with the system, allowing hosts to |
12 |
> |
* gain their configuration and a hook to a Filter |
13 |
> |
* to talk to. |
14 |
|
* |
15 |
|
* @author $Author$ |
16 |
|
* @version $Id$ |
17 |
|
*/ |
18 |
< |
class FilterManager { |
18 |
> |
public class FilterManager implements Component { |
19 |
|
|
20 |
|
//---FINAL ATTRIBUTES--- |
21 |
|
|
26 |
|
|
27 |
|
//---STATIC METHODS--- |
28 |
|
|
29 |
< |
public static void main(String[] args) { |
30 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
31 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
29 |
> |
//---CONSTRUCTORS--- |
30 |
> |
|
31 |
> |
/** |
32 |
> |
* Constructs a FilterManager with the name given |
33 |
> |
* |
34 |
> |
* @param givenName the name |
35 |
> |
*/ |
36 |
> |
public FilterManager(String givenName) { |
37 |
> |
NAME = givenName; |
38 |
> |
} |
39 |
> |
|
40 |
> |
//---PUBLIC METHODS--- |
41 |
> |
|
42 |
> |
/** |
43 |
> |
* This method starts the FilterManager |
44 |
> |
*/ |
45 |
> |
public void start() throws ComponentStartException { |
46 |
> |
// get references to key objects |
47 |
> |
_logger = _refman.getLogger(); |
48 |
|
|
49 |
< |
// can't have a real toString() :) |
32 |
< |
String toString = "FilterManager(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
49 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
50 |
|
|
51 |
< |
try { |
52 |
< |
ORB orb = ORB.init(args, null); |
53 |
< |
|
54 |
< |
// something to hold objects |
55 |
< |
org.omg.CORBA.Object objRef = null; |
56 |
< |
|
57 |
< |
// get the Root POA |
58 |
< |
objRef = orb.resolve_initial_references("RootPOA"); |
59 |
< |
POA poa = POAHelper.narrow(objRef); |
60 |
< |
|
61 |
< |
// get a hook to the name service |
62 |
< |
objRef = orb.resolve_initial_references("NameService"); |
63 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
64 |
< |
|
65 |
< |
// get a ref to the Configurator & the Logger |
66 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); |
67 |
< |
ConfigurationManager configManager = ConfigurationManagerHelper.narrow(objRef); |
68 |
< |
objRef = ncRef.resolve(ncRef.to_name("iscream.Logger")); |
69 |
< |
Logger logger = LoggerHelper.narrow(objRef); |
70 |
< |
|
71 |
< |
logger.write(toString, Logger.SYSINIT, "coming up"); |
72 |
< |
|
73 |
< |
// create the filterManagerRef to our servant |
74 |
< |
//filterManagerRef = new FilterManagerServant; |
58 |
< |
|
59 |
< |
// register the servant with the name service |
60 |
< |
//objRef = poa.servant_to_reference(filterManagerRef); |
61 |
< |
//ncRef.bind(ncRef.to_name("iscream.FilterManager"), objRef); |
62 |
< |
|
63 |
< |
// start the POA off |
64 |
< |
poa.the_POAManager().activate(); |
65 |
< |
|
66 |
< |
// get the config |
67 |
< |
Configuration myConfig = configManager.getConfiguration("filterManager"); |
68 |
< |
|
69 |
< |
// some place holders for the configuration |
70 |
< |
int port = 0; |
71 |
< |
|
72 |
< |
// did we? |
73 |
< |
if (myConfig == null) { |
74 |
< |
System.out.println("Failed: is it there?, can you read it?"); |
75 |
< |
System.exit(1); |
76 |
< |
} else { |
77 |
< |
|
78 |
< |
// get the property |
79 |
< |
try { |
80 |
< |
port = new Integer(myConfig.getProperty("listenPort")).intValue(); |
81 |
< |
} catch (org.omg.CORBA.MARSHAL e) { |
82 |
< |
System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back"); |
83 |
< |
System.exit(1); |
84 |
< |
} |
85 |
< |
} |
86 |
< |
logger.write(toString, Logger.SYSINIT, "configured"); |
87 |
< |
logger.write(toString, Logger.SYSINIT, "starting listener"); |
88 |
< |
|
89 |
< |
FilterManagerListener fml = new FilterManagerListener(logger, configManager, port); |
90 |
< |
fml.start(); |
91 |
< |
|
92 |
< |
logger.write(toString, Logger.SYSINIT, "started"); |
93 |
< |
|
94 |
< |
} catch (Exception e) { |
95 |
< |
System.err.println("FILTER MANAGER ERROR: " + e); |
96 |
< |
e.printStackTrace(System.out); |
51 |
> |
// startup a thread to listen for hosts |
52 |
> |
HostListener hostListener = new HostListener(); |
53 |
> |
hostListener.start(); |
54 |
> |
|
55 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
56 |
> |
} |
57 |
> |
|
58 |
> |
/** |
59 |
> |
* Does a dependency check. Used mainly at startup to |
60 |
> |
* see if the required dependencies (components) are up |
61 |
> |
* and running. |
62 |
> |
* |
63 |
> |
* @return a boolean value, true if the depdencies are satisfied |
64 |
> |
*/ |
65 |
> |
public boolean depCheck() { |
66 |
> |
// This also depends on Filters.. but only when requested. |
67 |
> |
// I believe the code is in place to handle that elsewhere. |
68 |
> |
try { |
69 |
> |
org.omg.CORBA.Object obj; |
70 |
> |
obj = _refman.getCORBARef("iscream.Logger"); |
71 |
> |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
72 |
> |
} catch(ComponentCORBAException e) { |
73 |
> |
System.err.println(toString() + ": Dependency Failure: "+e); |
74 |
> |
return false; |
75 |
|
} |
76 |
+ |
// dependency check suceeded |
77 |
+ |
return true; |
78 |
|
} |
79 |
+ |
|
80 |
+ |
/** |
81 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
82 |
+ |
* method to provide clean logging (every class should have this). |
83 |
+ |
* |
84 |
+ |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
85 |
+ |
* to format the toString() |
86 |
+ |
* |
87 |
+ |
* @return the name of this class and its CVS revision |
88 |
+ |
*/ |
89 |
+ |
public String toString() { |
90 |
+ |
return FormatName.getName( |
91 |
+ |
NAME, |
92 |
+ |
getClass().getName(), |
93 |
+ |
REVISION); |
94 |
+ |
} |
95 |
|
|
100 |
– |
//---CONSTRUCTORS--- |
101 |
– |
|
102 |
– |
//---PUBLIC METHODS--- |
103 |
– |
|
96 |
|
//---PRIVATE METHODS--- |
97 |
|
|
98 |
|
//---ACCESSOR/MUTATOR METHODS--- |
99 |
|
|
100 |
|
//---ATTRIBUTES--- |
101 |
|
|
102 |
+ |
/** |
103 |
+ |
* This is the friendly identifier of the |
104 |
+ |
* component this class is running in. |
105 |
+ |
* eg, a Filter may be called "filter1", |
106 |
+ |
* If this class does not have an owning |
107 |
+ |
* component, a name from the configuration |
108 |
+ |
* can be placed here. This name could also |
109 |
+ |
* be changed to null for utility classes. |
110 |
+ |
*/ |
111 |
+ |
private String _name = FilterManager.NAME; |
112 |
+ |
|
113 |
+ |
/** |
114 |
+ |
* This holds a reference to the |
115 |
+ |
* system logger that is being used. |
116 |
+ |
*/ |
117 |
+ |
private Logger _logger; |
118 |
+ |
|
119 |
+ |
/** |
120 |
+ |
* A reference to the reference manager in use |
121 |
+ |
*/ |
122 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
123 |
+ |
|
124 |
|
//---STATIC ATTRIBUTES--- |
125 |
+ |
|
126 |
+ |
/** |
127 |
+ |
* The friendly name for this component, used by |
128 |
+ |
* all related classes. |
129 |
+ |
* This is set from the configuration. |
130 |
+ |
*/ |
131 |
+ |
public static String NAME; |
132 |
|
|
133 |
|
} |