diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-02-21 09:59:26 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-02-21 09:59:26 +0100 |
| commit | 1faab1fd00f70881d4666d766fd0f033e172ff80 (patch) | |
| tree | d3520ca43d518156291144fb536c01ab1a862562 /src/main/java/com/c2kernel | |
| parent | 29dc0d0d2b38a55ed3e3deaf687439fa43c4b346 (diff) | |
ClusterStorage property can now be an already instanciated ArrayList of
ClusterStorage instances, or the original comma separated string of
class names.
Diffstat (limited to 'src/main/java/com/c2kernel')
| -rw-r--r-- | src/main/java/com/c2kernel/persistency/ClusterStorageManager.java | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java index f7304b1..6ca5502 100644 --- a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java +++ b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java @@ -40,34 +40,60 @@ public class ClusterStorageManager { * This property is usually process specific, and so should be in the server/client.conf and not the connect file.
*/
public ClusterStorageManager() throws ClusterStorageException {
- String allClusters = Gateway.getProperty("ClusterStorage");
- if (allClusters == null || allClusters.equals("")) {
+ Object clusterStorageProp = Gateway.getProperty("ClusterStorage");
+ if (clusterStorageProp == null || clusterStorageProp.equals("")) {
throw new ClusterStorageException("ClusterStorageManager.init() - no ClusterStorages defined. No persistency!");
}
+
+ ArrayList<ClusterStorage> rootStores;
+ if (clusterStorageProp instanceof String)
+ rootStores = instantiateStores((String)clusterStorageProp);
+ else if (clusterStorageProp instanceof ArrayList<?>) {
+ ArrayList<?> propStores = (ArrayList<?>)clusterStorageProp;
+ rootStores = new ArrayList<ClusterStorage>();
+ for (Object thisStore : propStores) {
+ if (thisStore instanceof ClusterStorage)
+ rootStores.add((ClusterStorage)thisStore);
+ else
+ throw new ClusterStorageException("Supplied ClusterStorage "+thisStore.toString()+" was not an instance of ClusterStorage");
+ }
+ }
+ else {
+ throw new ClusterStorageException("Unknown class of ClusterStorage property: "+clusterStorageProp.getClass().getName());
+ }
+
+ int clusterNo = 0;
+ for (ClusterStorage newStorage : rootStores) {
+ try {
+ newStorage.open();
+ } catch (ClusterStorageException ex) {
+ Logger.error(ex);
+ throw new ClusterStorageException("ClusterStorageManager.init() - Error initialising storage handler " + newStorage.getClass().getName() +
+ ": " + ex.getMessage());
+ }
+ Logger.msg(5, "ClusterStorageManager.init() - Cluster storage " + newStorage.getClass().getName() +
+ " initialised successfully.");
+ allStores.put(newStorage.getId(), newStorage);
+ clusterPriority[clusterNo++] = newStorage.getId();
+ }
+ clusterReaders.put(ClusterStorage.ROOT, rootStores); // all storages are queried for clusters at the root level
+
+ }
+
+ public ArrayList<ClusterStorage> instantiateStores(String allClusters) throws ClusterStorageException {
+ ArrayList<ClusterStorage> rootStores = new ArrayList<ClusterStorage>();
StringTokenizer tok = new StringTokenizer(allClusters, ",");
clusterPriority = new String[tok.countTokens()];
- int clusterNo = 0;
- ArrayList<ClusterStorage> rootStores = new ArrayList<ClusterStorage>();
+
while (tok.hasMoreTokens()) {
ClusterStorage newStorage = null;
String newStorageClass = tok.nextToken();
try {
try {
- newStorage = (ClusterStorage)(Gateway.getResource().getClassForName(newStorageClass).newInstance());
+ newStorage = (ClusterStorage)(Class.forName(newStorageClass).newInstance());
} catch (ClassNotFoundException ex2) {
- newStorage = (ClusterStorage)(Gateway.getResource().getClassForName("com.c2kernel.persistency."+newStorageClass).newInstance());
+ newStorage = (ClusterStorage)(Class.forName("com.c2kernel.persistency."+newStorageClass).newInstance());
}
- newStorage.open();
- Logger.msg(5, "ClusterStorageManager.init() - Cluster storage " + newStorageClass +
- " initialised successfully.");
- allStores.put(newStorage.getId(), newStorage);
- rootStores.add(newStorage);
- clusterPriority[clusterNo++] = newStorage.getId();
-
- } catch (ClusterStorageException ex) {
- Logger.error(ex);
- throw new ClusterStorageException("ClusterStorageManager.init() - Error initialising storage handler " + newStorageClass +
- ": " + ex.getMessage());
} catch (ClassNotFoundException ex) {
throw new ClusterStorageException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass +
" could not be found.");
@@ -78,8 +104,9 @@ public class ClusterStorageManager { throw new ClusterStorageException("ClusterStorageManager.init() - The cluster storage handler class " + newStorageClass +
" was not allowed to be instantiated.");
}
+ rootStores.add(newStorage);
}
- clusterReaders.put(ClusterStorage.ROOT, rootStores); // all storages are queried for clusters at the root level
+ return rootStores;
}
public void close() {
|
