2 |
|
package uk.ac.ukc.iscream.core; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
5 |
> |
import uk.ac.ukc.iscream.util.*; |
6 |
|
import java.util.*; |
7 |
|
import java.io.*; |
8 |
– |
import org.omg.CORBA.*; |
9 |
– |
import org.omg.PortableServer.*; |
8 |
|
|
9 |
|
/** |
10 |
|
* This class is essentially a Configuration factory. |
17 |
|
* |
18 |
|
* It also relies on the System.properties to set internal values. |
19 |
|
* |
20 |
+ |
* ### |
21 |
+ |
* A point to note is that this class does NOT yet manage |
22 |
+ |
* created configurations which may cause memory problems! |
23 |
+ |
* ### |
24 |
+ |
* |
25 |
|
* @author $Author$ |
26 |
|
* @version $Id$ |
27 |
|
*/ |
41 |
|
/** |
42 |
|
* Creates a new ConfiguratorServant |
43 |
|
* This class uses the System.properties to set internal values |
41 |
– |
* |
42 |
– |
* @param rootPOARef a reference to the RootPOA |
43 |
– |
* @param logRef a reference to the Logger |
44 |
|
*/ |
45 |
< |
ConfigurationManagerServant(POA rootPOARef, Logger logRef) { |
45 |
> |
ConfigurationManagerServant() { |
46 |
|
// assign some local variables |
47 |
– |
_rootPOARef = rootPOARef; |
48 |
– |
_logRef = logRef; |
47 |
|
_configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation"); |
48 |
|
_systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile"); |
49 |
|
|
51 |
|
loadSystemConfig(); |
52 |
|
|
53 |
|
// log our status |
54 |
< |
_logRef.write(this.toString(), Logger.SYSINIT, "started"); |
55 |
< |
_logRef.write(this.toString(), Logger.SYSMSG, "configuration location - " + _configPath); |
56 |
< |
_logRef.write(this.toString(), Logger.SYSMSG, "system configuration file - " + _systemConfigFile); |
54 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
55 |
> |
_logger.write(toString(), Logger.SYSMSG, "configuration location - " + _configPath); |
56 |
> |
_logger.write(toString(), Logger.SYSMSG, "system configuration file - " + _systemConfigFile); |
57 |
|
} |
58 |
|
|
59 |
|
//---PUBLIC METHODS--- |
78 |
|
* @return the Configuration |
79 |
|
*/ |
80 |
|
public Configuration getConfiguration(String source) { |
81 |
< |
_logRef.write(this.toString(), Logger.SYSMSG, "got request for " + source); |
81 |
> |
_logger.write(toString(), Logger.SYSMSG, "got request for " + source); |
82 |
|
Configuration config = null; |
83 |
|
|
84 |
|
// check to see if we need to reload the system config |
85 |
|
// because it has changed |
86 |
|
if (isModified(_systemConfig.getFileList(), _systemConfig.getLastModified())) { |
87 |
< |
_logRef.write(this.toString(), Logger.SYSMSG, "system config changed"); |
87 |
> |
_logger.write(toString(), Logger.SYSMSG, "system config changed"); |
88 |
|
loadSystemConfig(); |
89 |
|
} |
90 |
|
|
91 |
|
// we look for this entry in the systemConfig |
92 |
|
String configFile = _systemConfig.getProperty("config." + source); |
93 |
< |
_logRef.write(this.toString(), Logger.DEBUG, "looking for config tree in - " + configFile); |
93 |
> |
_logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile); |
94 |
|
|
95 |
|
// if there is an entry |
96 |
|
if (configFile != null) { |
97 |
|
try { |
98 |
|
// get the file list of includes etc + the system config |
99 |
|
String fileList = _systemConfigFile + ";" + getIncludedFiles(configFile, ""); |
100 |
< |
_logRef.write(this.toString(), Logger.DEBUG, "config tree - " + fileList); |
100 |
> |
_logger.write(toString(), Logger.DEBUG, "config tree - " + fileList); |
101 |
|
|
102 |
|
// build the properites here from the filelist.... |
103 |
|
StringTokenizer st = new StringTokenizer(fileList, ";"); |
129 |
|
} while (st.hasMoreTokens()); |
130 |
|
|
131 |
|
// this creates the configuration, all nice, ready to be returned |
132 |
< |
ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified, _logRef); |
133 |
< |
org.omg.CORBA.Object objRef = _rootPOARef.servant_to_reference(ref); |
132 |
> |
ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified); |
133 |
> |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
134 |
|
config = ConfigurationHelper.narrow(objRef); |
135 |
|
|
136 |
|
} catch (Exception e) { |
137 |
|
// not sure what to do here |
138 |
< |
System.err.println("CONFIGURATION MANAGER ERROR: " + e); |
139 |
< |
e.printStackTrace(System.out); |
138 |
> |
// so we just log the error |
139 |
> |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); |
140 |
|
} |
141 |
|
|
142 |
|
// if there isn't an entry for the requested config |
143 |
|
} else { |
144 |
< |
_logRef.write(this.toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile); |
144 |
> |
_logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile); |
145 |
|
config = _systemConfig; |
146 |
|
} |
147 |
|
|
174 |
|
} |
175 |
|
return false; |
176 |
|
} |
177 |
< |
|
177 |
> |
|
178 |
|
/** |
179 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
180 |
|
* method to provide clean logging (every class should have this). |
181 |
|
* |
182 |
+ |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
183 |
+ |
* to format the toString() |
184 |
+ |
* |
185 |
|
* @return the name of this class and its CVS revision |
186 |
|
*/ |
187 |
|
public String toString() { |
188 |
< |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
188 |
> |
return FormatName.getName( |
189 |
> |
_name, |
190 |
> |
getClass().getName(), |
191 |
> |
REVISION); |
192 |
|
} |
193 |
|
|
194 |
|
//---PRIVATE METHODS--- |
265 |
|
* local reference _systemConfig |
266 |
|
*/ |
267 |
|
private void loadSystemConfig() { |
268 |
< |
_logRef.write(this.toString(), Logger.SYSMSG, "reloading " + _systemConfigFile); |
268 |
> |
_logger.write(this.toString(), Logger.SYSMSG, "reloading " + _systemConfigFile); |
269 |
|
// get a reference to the system config and store it |
270 |
|
try { |
271 |
|
// create the properties for the configuration |
274 |
|
systemConfigHolder.load(new FileInputStream(systemConfigFile)); |
275 |
|
|
276 |
|
// create the servant |
277 |
< |
ConfigurationServant ref = new ConfigurationServant(systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified(), _logRef); |
278 |
< |
org.omg.CORBA.Object objRef = _rootPOARef.servant_to_reference(ref); |
277 |
> |
ConfigurationServant ref = new ConfigurationServant(systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified()); |
278 |
> |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
279 |
|
|
280 |
|
// narrow it to a Configuration |
281 |
|
_systemConfig = ConfigurationHelper.narrow(objRef); |
282 |
|
|
283 |
|
} catch (Exception e) { |
284 |
< |
_logRef.write(this.toString(), Logger.FATAL, "ERROR: " + e.getMessage()); |
284 |
> |
_logger.write(toString(), Logger.FATAL, "ERROR: " + e.getMessage()); |
285 |
|
} |
286 |
|
} |
287 |
|
|
290 |
|
//---ATTRIBUTES--- |
291 |
|
|
292 |
|
/** |
293 |
< |
* Local storage of the RootPOA |
293 |
> |
* This is the friendly identifier of the |
294 |
> |
* component this class is running in. |
295 |
> |
* eg, a Filter may be called "filter1", |
296 |
> |
* If this class does not have an owning |
297 |
> |
* component, a name from the configuration |
298 |
> |
* can be placed here. This name could also |
299 |
> |
* be changed to null for utility classes. |
300 |
|
*/ |
301 |
< |
private POA _rootPOARef; |
301 |
> |
private String _name = Core.NAME; |
302 |
> |
|
303 |
> |
/** |
304 |
> |
* This holds a reference to the |
305 |
> |
* system logger that is being used. |
306 |
> |
*/ |
307 |
> |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
308 |
|
|
309 |
|
/** |
310 |
< |
* Local storage of the Logger |
310 |
> |
* A reference to the reference manager in use |
311 |
|
*/ |
312 |
< |
private Logger _logRef; |
312 |
> |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
313 |
|
|
314 |
|
/** |
315 |
|
* The root path to all configurations |