| 1 |
+ |
|
| 2 |
|
//---PACKAGE DECLARATION--- |
| 3 |
< |
package uk.ac.ukc.iscream.rootfilter; |
| 3 |
> |
package uk.org.iscream.rootfilter; |
| 4 |
|
|
| 5 |
|
//---IMPORTS--- |
| 6 |
< |
import uk.ac.ukc.iscream.util.*; |
| 7 |
< |
import uk.ac.ukc.iscream.core.*; |
| 8 |
< |
import uk.ac.ukc.iscream.clientinterface.*; |
| 6 |
> |
import uk.org.iscream.util.*; |
| 7 |
> |
import uk.org.iscream.core.*; |
| 8 |
> |
import uk.org.iscream.componentmanager.*; |
| 9 |
> |
import uk.org.iscream.clientinterface.*; |
| 10 |
|
|
| 11 |
|
/** |
| 12 |
|
* The root filter is what all filters talk to |
| 19 |
|
* @author $Author$ |
| 20 |
|
* @version $Id$ |
| 21 |
|
*/ |
| 22 |
< |
public class RootFilter implements uk.ac.ukc.iscream.util.Component { |
| 22 |
> |
public class RootFilter implements Component { |
| 23 |
|
|
| 24 |
|
//---FINAL ATTRIBUTES--- |
| 25 |
|
|
| 38 |
|
* This starts the Root Filter for the system |
| 39 |
|
*/ |
| 40 |
|
public void start() throws ComponentStartException { |
| 41 |
< |
|
| 41 |
> |
// get references to key objects |
| 42 |
> |
_logger = _refman.getLogger(); |
| 43 |
> |
|
| 44 |
|
_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; |
| 45 |
|
|
| 46 |
< |
Configuration config = _refman.getCM().getConfiguration("RootFilter"); |
| 47 |
< |
if (config == null) { |
| 48 |
< |
System.err.println("CRITICAL:Unable to obtain configuration" + |
| 49 |
< |
"\n Advise you check the i-scream log for more information."); |
| 50 |
< |
_logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration"); |
| 51 |
< |
System.exit(1); |
| 52 |
< |
} else { |
| 53 |
< |
try { |
| 54 |
< |
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 |
< |
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 |
< |
} |
| 46 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
| 47 |
> |
String configName = "RootFilter"; |
| 48 |
> |
|
| 49 |
> |
// set the name of the root filter |
| 50 |
> |
try { |
| 51 |
> |
NAME = cp.getProperty(configName, "RootFilter.name"); |
| 52 |
> |
} catch (PropertyNotFoundException e) { |
| 53 |
> |
NAME = null; |
| 54 |
> |
_logger.write(toString(), Logger.WARNING, "RootFilter name not set: "+e); |
| 55 |
|
} |
| 65 |
– |
// now we have the name of the Root Filter we set it |
| 66 |
– |
NAME = ourName; |
| 56 |
|
|
| 57 |
< |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
| 58 |
< |
|
| 57 |
> |
// try and get the names of the ciReal and ciDB |
| 58 |
> |
String realInterface, dbInterface; |
| 59 |
> |
try { |
| 60 |
> |
realInterface = cp.getProperty(configName, "RootFilter.realtimeInterfaceName"); |
| 61 |
> |
dbInterface = cp.getProperty(configName, "RootFilter.dbInterfaceName"); |
| 62 |
> |
} catch (PropertyNotFoundException e) { |
| 63 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
| 64 |
> |
realInterface = null; |
| 65 |
> |
dbInterface = null; |
| 66 |
> |
} |
| 67 |
> |
|
| 68 |
> |
ClientInterface ciReal = null, ciDB = null; |
| 69 |
|
// get reference to the client interfaces - the real time one |
| 70 |
< |
ClientInterface ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
| 70 |
> |
if (realInterface != null) { |
| 71 |
> |
ciReal = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + realInterface)); |
| 72 |
> |
} |
| 73 |
|
// get reference to the client interfaces - and the db one |
| 74 |
< |
ClientInterface ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
| 75 |
< |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
| 74 |
> |
if (dbInterface != null) { |
| 75 |
> |
ciDB = ClientInterfaceHelper.narrow(_refman.getCORBARef("iscream.ClientInterface." + dbInterface)); |
| 76 |
> |
} |
| 77 |
|
|
| 78 |
< |
ClientInterface[] clientInterfaces = {ciReal, ciDB}; |
| 78 |
> |
// setup a queue |
| 79 |
> |
Queue queue; |
| 80 |
> |
// see if this Queue needs a size limit |
| 81 |
> |
try { |
| 82 |
> |
int queueSizeLimit = Integer.parseInt(cp.getProperty(configName, "Queue.SizeLimit")); |
| 83 |
> |
String queueRemoveAlgorithm = cp.getProperty(configName, "Queue.RemoveAlgorithm"); |
| 84 |
> |
int algorithm = StringUtils.getStringPos(queueRemoveAlgorithm, Queue.algorithms); |
| 85 |
> |
if(algorithm != -1) { |
| 86 |
> |
_logger.write(toString(), Logger.DEBUG, "Starting Queue with size limit of "+queueSizeLimit+", using remove algorithm "+queueRemoveAlgorithm); |
| 87 |
> |
// we have valid values, so lets start it. |
| 88 |
> |
queue = new Queue(queueSizeLimit, algorithm); |
| 89 |
> |
} |
| 90 |
> |
else { |
| 91 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue Algorithm configuration, not known: "+queueRemoveAlgorithm); |
| 92 |
> |
// just don't activate a limit |
| 93 |
> |
queue = new Queue(); |
| 94 |
> |
} |
| 95 |
> |
|
| 96 |
> |
} catch (PropertyNotFoundException e) { |
| 97 |
> |
_logger.write(toString(), Logger.DEBUG, "Optional config not set: "+e); |
| 98 |
> |
// just don't activate a limit |
| 99 |
> |
queue = new Queue(); |
| 100 |
> |
} catch (NumberFormatException e) { |
| 101 |
> |
_logger.write(toString(), Logger.WARNING, "Bad Queue SizeLimit configuration: "+e); |
| 102 |
> |
// just don't activate a limit |
| 103 |
> |
queue = new Queue(); |
| 104 |
> |
} |
| 105 |
|
|
| 106 |
+ |
// startup a monitor on this queue |
| 107 |
+ |
try { |
| 108 |
+ |
// try to get the interval, if this fails, we won't start up the monitor |
| 109 |
+ |
int queueMonitorInterval = Integer.parseInt(cp.getProperty(configName, "Queue.MonitorInterval")); |
| 110 |
+ |
String queueName = NAME + " RootFilter"; |
| 111 |
+ |
queue.startMonitor(queueMonitorInterval*1000, queueName); |
| 112 |
+ |
} catch (PropertyNotFoundException e) { |
| 113 |
+ |
_logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e); |
| 114 |
+ |
} |
| 115 |
+ |
|
| 116 |
+ |
if (realInterface == null) { |
| 117 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + dbInterface); |
| 118 |
+ |
CIWrapper c = new CIWrapper(ciDB, queue); |
| 119 |
+ |
c.start(); |
| 120 |
+ |
} else if (dbInterface == null) { |
| 121 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface); |
| 122 |
+ |
CIWrapper c = new CIWrapper(ciReal, queue); |
| 123 |
+ |
c.start(); |
| 124 |
+ |
} else { |
| 125 |
+ |
_logger.write(toString(), Logger.DEBUG, "hooked to interfaces - " + realInterface + " & " + dbInterface); |
| 126 |
+ |
CIWrapper c = new CIWrapper(ciReal, queue); |
| 127 |
+ |
c.start(); |
| 128 |
+ |
c = new CIWrapper(ciDB, queue); |
| 129 |
+ |
c.start(); |
| 130 |
+ |
} |
| 131 |
+ |
|
| 132 |
|
// RootFilterServant start (for inbound child filter data) |
| 133 |
|
_logger.write(toString(), Logger.DEBUG, "starting Root Filter"); |
| 134 |
< |
RootFilterServant filterServant = new RootFilterServant(clientInterfaces); |
| 134 |
> |
RootFilterServant filterServant = new RootFilterServant(queue); |
| 135 |
|
// bind to the naming service as a filter |
| 136 |
< |
_refman.bindToOrb(filterServant, "iscream.Filter." + _name); |
| 136 |
> |
_refman.bindToOrb(filterServant, "iscream.Filter." + RootFilter.NAME); |
| 137 |
|
|
| 138 |
|
_logger.write(toString(), Logger.SYSINIT, "started"); |
| 139 |
+ |
|
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
/** |
| 143 |
+ |
* Does a dependency check. Used mainly at startup to |
| 144 |
+ |
* see if the required dependencies (components) are up |
| 145 |
+ |
* and running. |
| 146 |
+ |
* |
| 147 |
+ |
* @return a boolean value, true if the depdencies are satisfied |
| 148 |
+ |
*/ |
| 149 |
+ |
public boolean depCheck() { |
| 150 |
+ |
org.omg.CORBA.Object obj; |
| 151 |
+ |
|
| 152 |
+ |
// first we need to check the Configuration system is available |
| 153 |
+ |
try { |
| 154 |
+ |
// first check the ConfigurationManager is alive |
| 155 |
+ |
obj = _refman.getCORBARef("iscream.ConfigurationManager"); |
| 156 |
+ |
} catch(ComponentCORBAException e) { |
| 157 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
| 158 |
+ |
return false; |
| 159 |
+ |
} |
| 160 |
+ |
|
| 161 |
+ |
// next we need to check which client interfaces *should* |
| 162 |
+ |
// be active, and check them. Note they do not have to |
| 163 |
+ |
// be enabled, and we should check this. |
| 164 |
+ |
// -- each check only forces a dependency if it's configured |
| 165 |
+ |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
| 166 |
+ |
// first check the client interface |
| 167 |
+ |
try { |
| 168 |
+ |
String cli = cp.getProperty("RootFilter", "RootFilter.realtimeInterfaceName"); |
| 169 |
+ |
obj = _refman.getCORBARef("iscream.ClientInterface." + cli); |
| 170 |
+ |
} catch(ComponentCORBAException e) { |
| 171 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
| 172 |
+ |
return false; |
| 173 |
+ |
} catch(PropertyNotFoundException e) { |
| 174 |
+ |
System.err.println(toString() + ": Client interface not configured and thus not enabled."); |
| 175 |
+ |
} |
| 176 |
+ |
// second check the database interface |
| 177 |
+ |
try { |
| 178 |
+ |
String dbi = cp.getProperty("RootFilter", "RootFilter.dbInterfaceName"); |
| 179 |
+ |
obj = _refman.getCORBARef("iscream.ClientInterface." + dbi); |
| 180 |
+ |
} catch(ComponentCORBAException e) { |
| 181 |
+ |
System.err.println(toString() + ": Dependency Failure: "+e); |
| 182 |
+ |
return false; |
| 183 |
+ |
} catch(PropertyNotFoundException e) { |
| 184 |
+ |
System.err.println(toString() + ": Database interface not configured and thus not enabled."); |
| 185 |
+ |
} |
| 186 |
+ |
|
| 187 |
+ |
// dependency check suceeded |
| 188 |
+ |
return true; |
| 189 |
+ |
} |
| 190 |
+ |
|
| 191 |
+ |
/** |
| 192 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 193 |
|
* method to provide clean logging (every class should have this). |
| 194 |
|
* |
| 195 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
| 195 |
> |
* This uses the uk.org.iscream.util.NameFormat class |
| 196 |
|
* to format the toString() |
| 197 |
|
* |
| 198 |
|
* @return the name of this class and its CVS revision |
| 199 |
|
*/ |
| 200 |
|
public String toString() { |
| 201 |
|
return FormatName.getName( |
| 202 |
< |
_name, |
| 202 |
> |
NAME, |
| 203 |
|
getClass().getName(), |
| 204 |
|
REVISION); |
| 205 |
|
} |
| 211 |
|
//---ATTRIBUTES--- |
| 212 |
|
|
| 213 |
|
/** |
| 110 |
– |
* This is the friendly identifier of the |
| 111 |
– |
* component this class is running in. |
| 112 |
– |
* eg, a Filter may be called "filter1", |
| 113 |
– |
* If this class does not have an owning |
| 114 |
– |
* component, a name from the configuration |
| 115 |
– |
* can be placed here. This name could also |
| 116 |
– |
* be changed to null for utility classes. |
| 117 |
– |
*/ |
| 118 |
– |
private String _name = RootFilter.NAME; |
| 119 |
– |
|
| 120 |
– |
/** |
| 214 |
|
* This holds a reference to the |
| 215 |
|
* system logger that is being used. |
| 216 |
|
*/ |
| 217 |
< |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
| 217 |
> |
private Logger _logger; |
| 218 |
|
|
| 219 |
|
/** |
| 220 |
|
* A reference to the reference manager in use |