3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.util.*; |
6 |
+ |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
|
import java.util.*; |
8 |
|
import java.io.*; |
9 |
|
|
80 |
|
*/ |
81 |
|
public Configuration getConfiguration(String source) { |
82 |
|
_logger.write(toString(), Logger.SYSMSG, "got request for " + source); |
83 |
< |
Configuration config = null; |
83 |
> |
|
84 |
|
|
85 |
|
// check to see if we need to reload the system config |
86 |
|
// because it has changed |
89 |
|
loadSystemConfig(); |
90 |
|
} |
91 |
|
|
92 |
< |
// we look for this entry in the systemConfig |
93 |
< |
String configFile = _systemConfig.getProperty("config." + source); |
93 |
< |
_logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile); |
92 |
> |
// search config for group membership |
93 |
> |
LinkedList groups = getGroupMembership(source); |
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 |
< |
_logger.write(toString(), Logger.DEBUG, "config tree - " + fileList); |
101 |
< |
|
102 |
< |
// build the properites here from the filelist.... |
103 |
< |
StringTokenizer st = new StringTokenizer(fileList, ";"); |
104 |
< |
|
105 |
< |
// some holders for variables |
106 |
< |
File currentFile; |
107 |
< |
long lastModified, newLastModified; |
108 |
< |
Properties properties, prevProperties; |
109 |
< |
|
110 |
< |
// the root of all configurations will be the system config |
111 |
< |
// so we need to open the properties of that |
112 |
< |
Properties defaultProperties = new Properties(); |
113 |
< |
currentFile = new File(_configPath, _systemConfigFile); |
114 |
< |
lastModified = currentFile.lastModified(); |
115 |
< |
defaultProperties.load(new FileInputStream(currentFile)); |
116 |
< |
|
117 |
< |
// This loop then iterates over the file list |
118 |
< |
// creates the properties to be passed to the |
119 |
< |
// Configuration constructor |
120 |
< |
do { |
121 |
< |
properties = new Properties(defaultProperties); |
122 |
< |
currentFile = new File(_configPath, st.nextToken()); |
123 |
< |
newLastModified = currentFile.lastModified(); |
124 |
< |
if (newLastModified > lastModified) { |
125 |
< |
lastModified = newLastModified; |
126 |
< |
} |
127 |
< |
properties.load(new FileInputStream(currentFile)); |
128 |
< |
defaultProperties = properties; |
129 |
< |
} while (st.hasMoreTokens()); |
95 |
> |
// add the hosts individual config to the start of the list |
96 |
> |
groups.addFirst(source); |
97 |
|
|
98 |
< |
// this creates the configuration, all nice, ready to be returned |
99 |
< |
ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified); |
100 |
< |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
101 |
< |
config = ConfigurationHelper.narrow(objRef); |
102 |
< |
|
103 |
< |
} catch (Exception e) { |
104 |
< |
// not sure what to do here |
105 |
< |
// so we just log the error |
106 |
< |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); |
98 |
> |
Iterator i = groups.iterator(); |
99 |
> |
String fileList = ""; |
100 |
> |
while (i.hasNext()) { |
101 |
> |
String groupName = (String) i.next(); |
102 |
> |
_logger.write(toString(), Logger.DEBUG, "looking for config entry for - " + groupName); |
103 |
> |
// we look for this entry in the systemConfig |
104 |
> |
String configFile = _systemConfig.getProperty("config." + groupName); |
105 |
> |
// if there is a config entry then |
106 |
> |
if (configFile != null) { |
107 |
> |
_logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile); |
108 |
> |
|
109 |
> |
// get the file list of includes etc + the system config |
110 |
> |
String groupFileList = null; |
111 |
> |
try { |
112 |
> |
groupFileList = getIncludedFiles(configFile, "") + ";"; |
113 |
> |
} catch (Exception e) { |
114 |
> |
// not sure what to do here |
115 |
> |
// so we just log the error |
116 |
> |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e); |
117 |
> |
} |
118 |
> |
if (groupFileList != null) { |
119 |
> |
fileList += groupFileList; |
120 |
> |
} |
121 |
> |
} else { |
122 |
> |
_logger.write(toString(), Logger.DEBUG, "no config entry for - " + groupName); |
123 |
|
} |
141 |
– |
|
142 |
– |
// if there isn't an entry for the requested config |
143 |
– |
} else { |
144 |
– |
_logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile); |
145 |
– |
config = _systemConfig; |
124 |
|
} |
125 |
+ |
// add the system config as the final check |
126 |
+ |
fileList = _systemConfigFile + ";" + fileList; |
127 |
+ |
_logger.write(toString(), Logger.DEBUG, "config tree - " + fileList); |
128 |
|
|
129 |
+ |
// build the configuration |
130 |
+ |
Configuration config = buildConfiguration(fileList); |
131 |
+ |
|
132 |
|
// if this is null at this point, then there will have been an error |
133 |
|
return config; |
134 |
|
} |
254 |
|
try { |
255 |
|
// create the properties for the configuration |
256 |
|
File systemConfigFile = new File(_configPath, _systemConfigFile); |
257 |
< |
Properties systemConfigHolder = new Properties(); |
258 |
< |
systemConfigHolder.load(new FileInputStream(systemConfigFile)); |
259 |
< |
|
257 |
> |
_systemConfigHolder = new Properties(); |
258 |
> |
_systemConfigHolder.load(new FileInputStream(systemConfigFile)); |
259 |
> |
|
260 |
|
// create the servant |
261 |
< |
ConfigurationServant ref = new ConfigurationServant(systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified()); |
261 |
> |
ConfigurationServant ref = new ConfigurationServant(_systemConfigHolder, _systemConfigFile, systemConfigFile.lastModified()); |
262 |
|
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
263 |
|
|
264 |
|
// narrow it to a Configuration |
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
+ |
/** |
273 |
+ |
* Parses the system configuration file |
274 |
+ |
* for group membership entries. |
275 |
+ |
* |
276 |
+ |
* It looks for all entries of group.<name> |
277 |
+ |
* which contain the given source name |
278 |
+ |
* |
279 |
+ |
* @param source the source to find membership for |
280 |
+ |
* |
281 |
+ |
* @return the list of groups that this source is a member of |
282 |
+ |
*/ |
283 |
+ |
private LinkedList getGroupMembership(String source) { |
284 |
+ |
LinkedList groupMembership = new LinkedList(); |
285 |
+ |
Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator(); |
286 |
+ |
while(i.hasNext()) { |
287 |
+ |
String key = (String) i.next(); |
288 |
+ |
if (key.startsWith("group.")) { |
289 |
+ |
String group = _systemConfig.getProperty(key); |
290 |
+ |
if (group.indexOf(source) != -1) { |
291 |
+ |
groupMembership.add(key.substring(6)); |
292 |
+ |
} |
293 |
+ |
} |
294 |
+ |
} |
295 |
+ |
return groupMembership; |
296 |
+ |
} |
297 |
+ |
|
298 |
+ |
/** |
299 |
+ |
* Build the properties as a Configuration to be |
300 |
+ |
* returned to the caller |
301 |
+ |
* |
302 |
+ |
* @param fileList the list of files to build the configuration from |
303 |
+ |
* |
304 |
+ |
* @return the built Configuration |
305 |
+ |
*/ |
306 |
+ |
private Configuration buildConfiguration(String fileList) { |
307 |
+ |
Configuration config = null; |
308 |
+ |
|
309 |
+ |
// if there is an entry |
310 |
+ |
if (!fileList.equals("")) { |
311 |
+ |
try { |
312 |
+ |
|
313 |
+ |
// build the properites here from the filelist.... |
314 |
+ |
StringTokenizer st = new StringTokenizer(fileList, ";"); |
315 |
+ |
|
316 |
+ |
// some holders for variables |
317 |
+ |
File currentFile; |
318 |
+ |
long lastModified = 0, newLastModified = 0; |
319 |
+ |
Properties properties = null, prevProperties = null; |
320 |
+ |
|
321 |
+ |
// the root of all configurations will be the system config |
322 |
+ |
// so we need to open the properties of that |
323 |
+ |
Properties defaultProperties = new Properties(); |
324 |
+ |
|
325 |
+ |
// This loop then iterates over the file list |
326 |
+ |
// creates the properties to be passed to the |
327 |
+ |
// Configuration constructor |
328 |
+ |
while (st.hasMoreTokens()) { |
329 |
+ |
properties = new Properties(defaultProperties); |
330 |
+ |
currentFile = new File(_configPath, st.nextToken()); |
331 |
+ |
newLastModified = currentFile.lastModified(); |
332 |
+ |
if (newLastModified > lastModified) { |
333 |
+ |
lastModified = newLastModified; |
334 |
+ |
} |
335 |
+ |
properties.load(new FileInputStream(currentFile)); |
336 |
+ |
defaultProperties = properties; |
337 |
+ |
} |
338 |
+ |
|
339 |
+ |
// this creates the configuration, all nice, ready to be returned |
340 |
+ |
ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified); |
341 |
+ |
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
342 |
+ |
config = ConfigurationHelper.narrow(objRef); |
343 |
+ |
_logger.write(toString(), Logger.DEBUG, "returning built configuration"); |
344 |
+ |
} catch (Exception e) { |
345 |
+ |
// not sure what to do here |
346 |
+ |
// so we just log the error |
347 |
+ |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e); |
348 |
+ |
} |
349 |
+ |
|
350 |
+ |
// if there isn't an entry for the requested config |
351 |
+ |
} else { |
352 |
+ |
_logger.write(toString(), Logger.DEBUG, "no configured config, returning " + _systemConfigFile); |
353 |
+ |
config = _systemConfig; |
354 |
+ |
} |
355 |
+ |
return config; |
356 |
+ |
} |
357 |
+ |
|
358 |
|
//---ACCESSOR/MUTATOR METHODS--- |
359 |
|
|
360 |
|
//---ATTRIBUTES--- |
395 |
|
* An instance of the system config |
396 |
|
*/ |
397 |
|
private Configuration _systemConfig; |
398 |
+ |
|
399 |
+ |
/** |
400 |
+ |
* The system config file represented by a |
401 |
+ |
* properties object. |
402 |
+ |
*/ |
403 |
+ |
private Properties _systemConfigHolder; |
404 |
|
|
405 |
|
//---STATIC ATTRIBUTES--- |
406 |
|
|