summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/persistency
diff options
context:
space:
mode:
authorabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
committerabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
commit0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch)
tree5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/persistency
parent036cbdba66f804743c4c838ed598d6972c4b3e17 (diff)
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/persistency')
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/ClusterStorage.java46
-rw-r--r--source/com/c2kernel/persistency/ClusterStorageManager.java111
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/LDAPClientReader.java10
-rw-r--r--source/com/c2kernel/persistency/LDAPClusterStorage.java39
-rw-r--r--source/com/c2kernel/persistency/ProxyLoader.java55
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/RemoteMap.java353
-rw-r--r--source/com/c2kernel/persistency/TransactionManager.java111
-rw-r--r--source/com/c2kernel/persistency/XMLClusterStorage.java37
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/outcome/Outcome.java45
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/outcome/OutcomeValidator.java63
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/outcome/Schema.java2
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/outcome/SchemaValidator.java7
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/persistency/outcome/Viewpoint.java18
13 files changed, 450 insertions, 447 deletions
diff --git a/source/com/c2kernel/persistency/ClusterStorage.java b/source/com/c2kernel/persistency/ClusterStorage.java
index f0d28a4..80fd86d 100755..100644
--- a/source/com/c2kernel/persistency/ClusterStorage.java
+++ b/source/com/c2kernel/persistency/ClusterStorage.java
@@ -10,7 +10,7 @@ import com.c2kernel.utils.Logger;
Each ClusterStorage must support get() and getClusterContents() for clusters they return READ and READWRITE from queryClusterSupport
and put() and delete() for clusters they return WRITE and READWRITE from queryClusterSupport().
Unsupported operations should throw a ClusterStorageException.
- If a cluster does not exist, get should return null, and delete should return
+ If a cluster does not exist, get should return null, and delete should return
@version $Revision: 1.22 $ $Date: 2006/02/01 13:27:47 $
@author $Author: abranson $
*/
@@ -20,7 +20,7 @@ public abstract class ClusterStorage {
public static final short READ = 1;
public static final short WRITE = 2;
public static final short READWRITE = 3;
-
+
// Cluster types
public static final String ROOT = "";
public static final String PROPERTY = "Property";
@@ -28,13 +28,13 @@ public abstract class ClusterStorage {
public static final String LIFECYCLE = "LifeCycle";
public static final String OUTCOME = "Outcome";
public static final String HISTORY = "AuditTrail";
- public static final String VIEWPOINT = "ViewPoint";
- public static final String JOB = "Job";
-
+ public static final String VIEWPOINT = "ViewPoint";
+ public static final String JOB = "Job";
+
// connection maintenance
- public abstract void open()
+ public abstract void open()
throws ClusterStorageException;
- public abstract void close()
+ public abstract void close()
throws ClusterStorageException;
// introspection
@@ -42,8 +42,8 @@ public abstract class ClusterStorage {
public abstract String getName();
// for addressing queries
public abstract String getId();
-
-
+
+
/** Quickly gets the first string of the slashed path */
public static String getClusterType(String path) {
try {
@@ -52,12 +52,12 @@ public abstract class ClusterStorage {
int end = path.indexOf('/', start + 1);
if (end == -1) end = path.length();
return path.substring(start, end);
- } catch (Exception ex) {
+ } catch (Exception ex) {
Logger.error(ex);
- return ClusterStorage.ROOT;
+ return ClusterStorage.ROOT;
}
}
-
+
public static String getPath(C2KLocalObject obj) {
String root = obj.getClusterType();
if (root == null) return null; // no storage allowed
@@ -71,34 +71,34 @@ public abstract class ClusterStorage {
}
else
return root+"/"+obj.getName();
- }
-
+ }
+
/* object manipulation */
// retrieve object by path
- public abstract C2KLocalObject get(Integer sysKey, String path)
+ public abstract C2KLocalObject get(Integer sysKey, String path)
throws ClusterStorageException;
// store object by path
- public abstract void put(Integer sysKey, C2KLocalObject obj)
+ public abstract void put(Integer sysKey, C2KLocalObject obj)
throws ClusterStorageException;
// delete cluster
- public abstract void delete(Integer sysKey, String path)
+ public abstract void delete(Integer sysKey, String path)
throws ClusterStorageException;
-
+
// db specific queries
- public Object query(Object query)
+ public Object query(Object query)
throws ClusterStorageException {
throw new ClusterStorageException("Query not supported on this storage");
}
-
+
public String queryToXML(String query, boolean genericFormat)
throws ClusterStorageException {
throw new ClusterStorageException("Query not supported on this storage");
}
-
-
+
+
// directory listing
- public abstract String[] getClusterContents(Integer sysKey, String path)
+ public abstract String[] getClusterContents(Integer sysKey, String path)
throws ClusterStorageException;
}
diff --git a/source/com/c2kernel/persistency/ClusterStorageManager.java b/source/com/c2kernel/persistency/ClusterStorageManager.java
index 560e022..5ce8d06 100644
--- a/source/com/c2kernel/persistency/ClusterStorageManager.java
+++ b/source/com/c2kernel/persistency/ClusterStorageManager.java
@@ -1,6 +1,10 @@
package com.c2kernel.persistency;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.StringTokenizer;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
@@ -57,7 +61,7 @@ public class ClusterStorageManager {
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 +
@@ -78,8 +82,7 @@ public class ClusterStorageManager {
}
public void close() {
- for (Iterator<ClusterStorage> iter = allStores.values().iterator(); iter.hasNext();) {
- ClusterStorage thisStorage = (ClusterStorage)iter.next();
+ for (ClusterStorage thisStorage : allStores.values()) {
try {
thisStorage.close();
} catch (ClusterStorageException ex) {
@@ -94,28 +97,28 @@ public class ClusterStorageManager {
* Collection, Property) Must specify if the request is a read or a write.
*/
private ArrayList<ClusterStorage> findStorages(String clusterType, boolean forWrite) {
-
+
if (!ready) {
Logger.error("ClusterStorageManager.findStorages() - called before init!");
return null;
}
-
+
// choose the right cache for readers or writers
HashMap<String, ArrayList<ClusterStorage>> cache;
if (forWrite)
cache = clusterWriters;
else
cache = clusterReaders;
-
+
// check to see if we've been asked to do this before
if (cache.containsKey(clusterType))
- return (ArrayList<ClusterStorage>)cache.get(clusterType);
-
+ return cache.get(clusterType);
+
// not done yet, we'll have to query them all
Logger.msg(7, "ClusterStorageManager.findStorages() - finding storage for "+clusterType+" forWrite:"+forWrite);
ArrayList<ClusterStorage> useableStorages = new ArrayList<ClusterStorage>();
- for (int i = 0; i < clusterPriority.length; i++) {
- ClusterStorage thisStorage = (ClusterStorage)allStores.get(clusterPriority[i]);
+ for (String element : clusterPriority) {
+ ClusterStorage thisStorage = allStores.get(element);
short requiredSupport = forWrite ? ClusterStorage.WRITE : ClusterStorage.READ;
if ((thisStorage.queryClusterSupport(clusterType) & requiredSupport) == requiredSupport) {
Logger.msg(7, "ClusterStorageManager.findStorages() - Got "+thisStorage.getName());
@@ -126,20 +129,18 @@ public class ClusterStorageManager {
return useableStorages;
}
- /**
- * Retrieves the ids of the next level of a cluster
+ /**
+ * Retrieves the ids of the next level of a cluster
* Does not look in any currently open transactions.
*/
public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
//String[] retArr = new String[0];
ArrayList<String> contents = new ArrayList<String>();
// get all readers
- String type = ClusterStorage.getClusterType(path);
Logger.msg(8, "ClusterStorageManager.getClusterContents() - Finding contents of "+path);
ArrayList<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
// try each in turn until we get a result
- for (Iterator<ClusterStorage> i = readers.iterator(); i.hasNext();) {
- ClusterStorage thisReader = (ClusterStorage)i.next();
+ for (ClusterStorage thisReader : readers) {
try {
String[] thisArr = thisReader.getClusterContents(sysKey, path);
if (thisArr != null) {
@@ -154,10 +155,10 @@ public class ClusterStorageManager {
" could not retrieve contents of " + sysKey + "/" + path + ": " + e.getMessage());
}
}
-
+
String[] retArr = new String[0];
- retArr = (String[])contents.toArray(retArr);
- return retArr;
+ retArr = contents.toArray(retArr);
+ return retArr;
}
/** Internal get method. Retrieves clusters from ClusterStorages & maintains the memory cache */
@@ -166,16 +167,16 @@ public class ClusterStorageManager {
// check cache first
SoftCache<String, C2KLocalObject> sysKeyMemCache = null;
if (memoryCache.containsKey(sysKeyIntObj)) {
- sysKeyMemCache = (SoftCache<String, C2KLocalObject>)memoryCache.get(sysKeyIntObj);
+ sysKeyMemCache = memoryCache.get(sysKeyIntObj);
synchronized(sysKeyMemCache) {
- C2KLocalObject obj = (C2KLocalObject)sysKeyMemCache.get(path);
+ C2KLocalObject obj = sysKeyMemCache.get(path);
if (obj != null) {
Logger.msg(7, "ClusterStorageManager.get() - found "+sysKeyIntObj+"/"+path+" in memcache");
return obj;
}
}
}
-
+
// special case - loading viewpoint contents
if (path.startsWith(ClusterStorage.VIEWPOINT) &&
path.endsWith("/data")) {
@@ -188,11 +189,10 @@ public class ClusterStorageManager {
return data;
}
}
-
+
// else try each reader in turn until we find it
ArrayList<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
- for (Iterator<ClusterStorage> i = readers.iterator(); i.hasNext(); ) {
- ClusterStorage thisReader = (ClusterStorage)i.next();
+ for (ClusterStorage thisReader : readers) {
try {
result = thisReader.get(sysKeyIntObj, path);
Logger.msg(7, "ClusterStorageManager.get() - reading "+path+" from "+thisReader.getName() + " for intkey=" + sysKeyIntObj);
@@ -222,8 +222,7 @@ public class ClusterStorageManager {
public void put(Integer sysKeyIntObj, C2KLocalObject obj) throws ClusterStorageException {
String path = ClusterStorage.getPath(obj);
ArrayList<ClusterStorage> writers = findStorages(ClusterStorage.getClusterType(path), true);
- for (Iterator<ClusterStorage> i = writers.iterator(); i.hasNext(); ) {
- ClusterStorage thisWriter = (ClusterStorage)i.next();
+ for (ClusterStorage thisWriter : writers) {
try {
Logger.msg(7, "ClusterStorageManager.put() - writing "+path+" to "+thisWriter.getName());
thisWriter.put(sysKeyIntObj, obj);
@@ -236,18 +235,18 @@ public class ClusterStorageManager {
// put in mem cache if that worked
SoftCache<String, C2KLocalObject> sysKeyMemCache;
if (memoryCache.containsKey(sysKeyIntObj))
- sysKeyMemCache = (SoftCache<String, C2KLocalObject>)memoryCache.get(sysKeyIntObj);
+ sysKeyMemCache = memoryCache.get(sysKeyIntObj);
else {
sysKeyMemCache = new SoftCache<String, C2KLocalObject>();
- synchronized (memoryCache) {
+ synchronized (memoryCache) {
memoryCache.put(sysKeyIntObj, sysKeyMemCache);
}
}
-
+
synchronized(sysKeyMemCache) {
sysKeyMemCache.put(path, obj);
}
-
+
if (Logger.doLog(9)) dumpCacheContents(9);
// transmit proxy event
@@ -257,8 +256,7 @@ public class ClusterStorageManager {
/** Deletes a cluster from all writers */
public void remove(Integer sysKeyIntObj, String path) throws ClusterStorageException {
ArrayList<ClusterStorage> writers = findStorages(ClusterStorage.getClusterType(path), true);
- for (Iterator<ClusterStorage> i = writers.iterator(); i.hasNext(); ) {
- ClusterStorage thisWriter = (ClusterStorage)i.next();
+ for (ClusterStorage thisWriter : writers) {
try {
Logger.msg(7, "ClusterStorageManager.delete() - removing "+path+" from "+thisWriter.getName());
thisWriter.delete(sysKeyIntObj, path);
@@ -268,24 +266,24 @@ public class ClusterStorageManager {
throw e;
}
}
-
+
if (memoryCache.containsKey(sysKeyIntObj)) {
- SoftCache<?, ?> sysKeyMemCache = (SoftCache<?, ?>)memoryCache.get(sysKeyIntObj);
+ SoftCache<?, ?> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
synchronized (sysKeyMemCache) {
sysKeyMemCache.remove(path);
}
}
-
+
// transmit proxy event
EntityProxyManager.sendProxyEvent( new ProxyMessage(sysKeyIntObj.intValue(), path, ProxyMessage.DELETED));
}
-
+
public void clearCache(Integer sysKeyIntObj, String path) {
Logger.msg(7, "CSM.clearCache() - removing "+sysKeyIntObj+"/"+path);
-
+
if (memoryCache.containsKey(sysKeyIntObj)) {
- SoftCache<?, ?> sysKeyMemCache = (SoftCache<?, ?>)memoryCache.get(sysKeyIntObj);
+ SoftCache<?, ?> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
synchronized(sysKeyMemCache) {
for (Iterator<?> iter = sysKeyMemCache.keySet().iterator(); iter.hasNext();) {
String thisPath = (String)iter.next();
@@ -297,15 +295,15 @@ public class ClusterStorageManager {
}
}
}
-
+
public void clearCache(Integer sysKeyIntObj) {
Logger.msg(5, "CSM.clearCache() - removing entire cache of "+sysKeyIntObj);
-
+
if (memoryCache.containsKey(sysKeyIntObj)) {
synchronized (memoryCache) {
if (Logger.doLog(6)) {
- SoftCache<?, ?> sysKeyMemCache = (SoftCache<?, ?>)memoryCache.get(sysKeyIntObj);
+ SoftCache<?, ?> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
int size = sysKeyMemCache.size();
Logger.msg(6, "CSM.clearCache() - "+size+" objects to remove.");
}
@@ -315,25 +313,24 @@ public class ClusterStorageManager {
else
Logger.msg(6, "CSM.clearCache() - No objects cached");
}
-
+
public void clearCache() {
synchronized (memoryCache) {
memoryCache.clear();
}
Logger.msg(5, "CSM.clearCache() - cleared entire cache, "+memoryCache.size()+" entities.");
}
-
+
public void dumpCacheContents(int logLevel) {
if (!Logger.doLog(logLevel)) return;
synchronized(memoryCache) {
- for (Iterator<Integer> iter = memoryCache.keySet().iterator(); iter.hasNext();) {
- Integer sysKey = (Integer) iter.next();
+ for (Integer sysKey : memoryCache.keySet()) {
Logger.msg(logLevel, "Cached Objects of Entity "+sysKey);
- SoftCache<?, ?> sysKeyMemCache = (SoftCache<?, ?>)memoryCache.get(sysKey);
+ SoftCache<?, ?> sysKeyMemCache = memoryCache.get(sysKey);
try {
synchronized(sysKeyMemCache) {
- for (Iterator<?> iterator = sysKeyMemCache.keySet().iterator();iterator.hasNext();) {
- String path = (String) iterator.next();
+ for (Object name : sysKeyMemCache.keySet()) {
+ String path = (String) name;
try {
Logger.msg(logLevel, " Path "+path+": "+sysKeyMemCache.get(path).getClass().getName());
} catch (NullPointerException e) {
@@ -345,20 +342,20 @@ public class ClusterStorageManager {
Logger.msg(logLevel, "Cache modified - aborting");
}
}
- Logger.msg(logLevel, "Total number of cached entities: "+memoryCache.size());
+ Logger.msg(logLevel, "Total number of cached entities: "+memoryCache.size());
}
- }
-
+ }
+
public Object query(String id, Object query) throws ClusterStorageException {
- ClusterStorage requiredStorage = (ClusterStorage)allStores.get(id);
- if (requiredStorage == null)
+ ClusterStorage requiredStorage = allStores.get(id);
+ if (requiredStorage == null)
throw new ClusterStorageException("Storage "+id+" not found.");
return requiredStorage.query(query);
}
-
+
public String queryToXML(String id, String query, boolean genericFormat) throws ClusterStorageException {
- ClusterStorage requiredStorage = (ClusterStorage)allStores.get(id);
- if (requiredStorage == null)
+ ClusterStorage requiredStorage = allStores.get(id);
+ if (requiredStorage == null)
throw new ClusterStorageException("Storage "+id+" not found.");
return requiredStorage.queryToXML(query, genericFormat);
}
diff --git a/source/com/c2kernel/persistency/LDAPClientReader.java b/source/com/c2kernel/persistency/LDAPClientReader.java
index c40658e..ac9215c 100755..100644
--- a/source/com/c2kernel/persistency/LDAPClientReader.java
+++ b/source/com/c2kernel/persistency/LDAPClientReader.java
@@ -8,14 +8,16 @@ import com.c2kernel.entity.C2KLocalObject;
public class LDAPClientReader extends LDAPClusterStorage {
// return all readwrite support as readonly
- public short queryClusterSupport(String clusterType) {
+ @Override
+ public short queryClusterSupport(String clusterType) {
return (short)(super.queryClusterSupport(clusterType) & READ);
}
-
-
+
+
/**
* @see com.c2kernel.persistency.ClusterStorage#delete(Integer, String)
*/
+ @Override
public void delete(Integer sysKey, String path)
throws ClusterStorageException {
throw new ClusterStorageException("Writing not supported in ClientReader");
@@ -24,6 +26,7 @@ public class LDAPClientReader extends LDAPClusterStorage {
/**
* @see com.c2kernel.persistency.ClusterStorage#getName()
*/
+ @Override
public String getName() {
return "LDAP Client Cluster Reader";
}
@@ -31,6 +34,7 @@ public class LDAPClientReader extends LDAPClusterStorage {
/**
* @see com.c2kernel.persistency.ClusterStorage#put(Integer, String, C2KLocalObject)
*/
+
public void put(Integer sysKey, String path, C2KLocalObject obj)
throws ClusterStorageException {
throw new ClusterStorageException("Writing not supported in ClientReader");
diff --git a/source/com/c2kernel/persistency/LDAPClusterStorage.java b/source/com/c2kernel/persistency/LDAPClusterStorage.java
index fb36d9f..16ac7a0 100644
--- a/source/com/c2kernel/persistency/LDAPClusterStorage.java
+++ b/source/com/c2kernel/persistency/LDAPClusterStorage.java
@@ -14,32 +14,38 @@ import com.c2kernel.utils.Logger;
public class LDAPClusterStorage extends ClusterStorage {
LDAPPropertyManager ldapStore;
- public void open() throws ClusterStorageException {
+ @Override
+ public void open() throws ClusterStorageException {
ldapStore = Gateway.getLDAPLookup().getPropManager();
}
- public void close() throws ClusterStorageException {
+ @Override
+ public void close() throws ClusterStorageException {
}
// introspection
- public short queryClusterSupport(String clusterType) {
+ @Override
+ public short queryClusterSupport(String clusterType) {
if (clusterType.equals(PROPERTY))
return READWRITE;
else
return NONE;
}
- public String getName() {
+ @Override
+ public String getName() {
return "LDAP Cluster Storage";
}
-
- public String getId() {
+
+ @Override
+ public String getId() {
return "LDAP";
}
// retrieve object by path
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
Logger.msg(6, "LDAPClusterStorage.get() - "+sysKey+"/"+path);
StringTokenizer tok = new StringTokenizer(path, "/");
int pathLength = tok.countTokens();
@@ -75,7 +81,8 @@ public class LDAPClusterStorage extends ClusterStorage {
return newObj;
}
// store object by path
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
+ @Override
+ public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
Logger.msg(6, "LDAPClusterStorage.put() - "+sysKey+"/"+ClusterStorage.getPath(obj));
String type = obj.getClusterType();
@@ -100,7 +107,8 @@ public class LDAPClusterStorage extends ClusterStorage {
}
// delete cluster
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public void delete(Integer sysKey, String path) throws ClusterStorageException {
StringTokenizer tok = new StringTokenizer(path, "/");
int pathLength = tok.countTokens();
if (pathLength != 2)
@@ -120,7 +128,7 @@ public class LDAPClusterStorage extends ClusterStorage {
} catch (Exception e1) {
Logger.error(e1);
throw new ClusterStorageException("LDAPClusterStorage - could not delete property");
- }
+ }
}
else
throw new ClusterStorageException("Cluster type "+type+" not supported.");
@@ -130,26 +138,27 @@ public class LDAPClusterStorage extends ClusterStorage {
/* navigation */
// directory listing
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
Logger.msg(6, "LDAPClusterStorage.getClusterContents() - "+sysKey+"/"+path);
StringTokenizer tok = new StringTokenizer(path, "/");
int pathLength = tok.countTokens();
if (pathLength > 1)
return new String[0];
-
+
String type = getClusterType(path);
- try
+ try
{
EntityPath thisEntity = new EntityPath(sysKey.intValue());
if (type.equals(PROPERTY))
return ldapStore.getPropertyNames(thisEntity);
- else
+ else
if (type.equals("")) { // root query
String[] allClusters = new String[0];
ArrayList<String> clusterList = new ArrayList<String>();
if (ldapStore.hasProperties(thisEntity))
clusterList.add(PROPERTY);
- allClusters = (String[])clusterList.toArray(allClusters);
+ allClusters = clusterList.toArray(allClusters);
return allClusters;
}
else
diff --git a/source/com/c2kernel/persistency/ProxyLoader.java b/source/com/c2kernel/persistency/ProxyLoader.java
index 687141f..e614b0d 100644
--- a/source/com/c2kernel/persistency/ProxyLoader.java
+++ b/source/com/c2kernel/persistency/ProxyLoader.java
@@ -21,38 +21,44 @@ public class ProxyLoader extends ClusterStorage {
HashMap<Integer, ManageableEntity> entities = new HashMap<Integer, ManageableEntity>();
LDAPLookup lookup;
- public void open() throws ClusterStorageException {
+ @Override
+ public void open() throws ClusterStorageException {
lookup = Gateway.getLDAPLookup();
}
- public void close() throws ClusterStorageException {
+ @Override
+ public void close() throws ClusterStorageException {
}
// introspection
- public short queryClusterSupport(String clusterType) {
+ @Override
+ public short queryClusterSupport(String clusterType) {
return READ;
}
- public String getName() {
+ @Override
+ public String getName() {
return "Proxy Cluster Loader";
}
-
- public String getId() {
+
+ @Override
+ public String getId() {
return "CORBA";
}
// retrieve object by path
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
try {
ManageableEntity thisEntity = getIOR(sysKey);
String type = getClusterType(path);
// fetch the xml from the item
String queryData = thisEntity.queryData(path);
-
+
if (queryData != null) {
- if (type.equals(OUTCOME))
+ if (type.equals(OUTCOME))
return new Outcome(path, queryData);
- else
+ else
return (C2KLocalObject)CastorXMLUtility.unmarshall(queryData);
}
} catch (Exception e) {
@@ -61,14 +67,16 @@ public class ProxyLoader extends ClusterStorage {
}
return null;
}
-
+
// store object by path
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
+ @Override
+ public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
// not supported
throw new ClusterStorageException("Cannot write to items through the ProxyLoader");
}
// delete cluster
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public void delete(Integer sysKey, String path) throws ClusterStorageException {
// not supported
throw new ClusterStorageException("Cannot write to items through the ProxyLoader");
}
@@ -76,33 +84,34 @@ public class ProxyLoader extends ClusterStorage {
/* navigation */
// directory listing
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
try {
ManageableEntity thisEntity = getIOR(sysKey);
String contents = thisEntity.queryData(path+"/all");
StringTokenizer tok = new StringTokenizer(contents, ",");
String[] result = new String[tok.countTokens()];
- for (int i=0; i<result.length; i++)
+ for (int i=0; i<result.length; i++)
result[i] = tok.nextToken();
-
+
return result;
} catch (Exception e) {
throw new ClusterStorageException(e.getMessage());
}
}
-
+
private ManageableEntity getIOR(Integer sysKey) throws ClusterStorageException {
if (entities.containsKey(sysKey)) {
// check the cache
Logger.msg(7, "ProxyLoader.getIOR() - "+sysKey+" cached.");
- return (ManageableEntity)entities.get(sysKey);
+ return entities.get(sysKey);
}
-
+
try {
Logger.msg(7, "ProxyLoader.getIOR() - Resolving "+sysKey+".");
-
+
org.omg.CORBA.Object ior = lookup.getIOR(new EntityPath(sysKey.intValue()));
-
+
ManageableEntity thisEntity = null;
try {
thisEntity = ItemHelper.narrow(ior);
@@ -113,7 +122,7 @@ public class ProxyLoader extends ClusterStorage {
throw new ClusterStorageException ("Could not narrow "+sysKey+" as a known Entity type");
}
}
-
+
Logger.msg(7, "ProxyLoader.getIOR() - Found "+sysKey+".");
entities.put(sysKey, thisEntity);
return thisEntity;
@@ -121,4 +130,4 @@ public class ProxyLoader extends ClusterStorage {
throw new ClusterStorageException("Error narrowing "+sysKey+": "+e.getMessage());
}
}
-}
+}
diff --git a/source/com/c2kernel/persistency/RemoteMap.java b/source/com/c2kernel/persistency/RemoteMap.java
index ca9cbc4..bc17e3f 100755..100644
--- a/source/com/c2kernel/persistency/RemoteMap.java
+++ b/source/com/c2kernel/persistency/RemoteMap.java
@@ -2,22 +2,23 @@ package com.c2kernel.persistency;
import java.util.AbstractSet;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.TreeMap;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.entity.proxy.*;
+import com.c2kernel.entity.proxy.EntityProxy;
import com.c2kernel.entity.proxy.EntityProxyObserver;
+import com.c2kernel.entity.proxy.MemberSubscription;
import com.c2kernel.lookup.EntityPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
/**
* Maps a storage cluster onto a java.util.Map
- *
+ *
* @author Andrew Branson
* $Revision: 1.22 $
* $Date: 2006/03/03 13:52:21 $
@@ -25,24 +26,34 @@ import com.c2kernel.utils.Logger;
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
* All rights reserved.
*/
-public class RemoteMap implements C2KLocalObject, Map {
-
- protected static final boolean KEYS = false;
- protected static final boolean VALUES = true;
+public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> implements C2KLocalObject {
private int mID=-1;
private String mName;
protected int mSysKey;
private String mPath = "";
- protected String[] keys = null;
- Object keyLock = new Object();
- protected C2KLocalObject[] values = null;
+ Object keyLock = null;
TransactionManager storage;
- EntityProxyObserver listener;
+ EntityProxyObserver<V> listener;
+ Comparator<String> comp;
EntityProxy source;
- Object mLocker; // if this remote map will participate in a transaction
-
+ Object mLocker; // if this remote map will participate in a transaction
+
public RemoteMap(int sysKey, String path, Object locker) {
+
+ super(new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ Integer i1 = null, i2 = null;
+ try {
+ i1 = Integer.valueOf(o1);
+ i2 = Integer.valueOf(o2);
+ return i1.compareTo(i2);
+ } catch (NumberFormatException ex) { }
+ return o1.compareTo(o2);
+ }
+ });
+
mSysKey = sysKey;
mLocker = locker;
@@ -56,138 +67,99 @@ public class RemoteMap implements C2KLocalObject, Map {
mID = Integer.parseInt(mName);
} catch (NumberFormatException e) {}
storage = Gateway.getStorage();
-
- listener = new EntityProxyObserver() {
- public void add(C2KLocalObject obj) {
- synchronized (keyLock) {
- if (keys == null) return;
- boolean found = false;
- for (int i=0; i<keys.length; i++) {
- if (keys[i].equals(obj.getName())) { //replaced
- values[i] = obj;
- found = true;
- break;
- }
- }
-
- if (found == false) { // new
- String[] newKeys = new String[keys.length+1];
- C2KLocalObject[] newValues = new C2KLocalObject[keys.length+1];
- System.arraycopy(keys, 0, newKeys, 0, keys.length);
- if (values!=null) System.arraycopy(values, 0, newValues, 0, keys.length);
- newKeys[newKeys.length-1] = obj.getName();
- newValues[newValues.length-1] = obj;
- keys = newKeys;
- values = newValues;
- }
- }
+
+ listener = new EntityProxyObserver<V>() {
+ @Override
+ public void add(V obj) {
+ synchronized (this) {
+ putLocal(obj.getName(), obj);
+ }
}
- public void remove(String id) {
- synchronized (keyLock) {
- if (keys == null) return;
- boolean found = false;
- for (int i=0; i<keys.length; i++) {
- if (keys[i].equals(id)) { //replaced
- String[] newKeys = new String[keys.length-1];
- C2KLocalObject[] newValues = new C2KLocalObject[keys.length-1];
- int pos = 0;
- for (int j=0; j<keys.length;j++) {
- if (i!=j) {
- newKeys[pos] = keys[j];
- newValues[pos++] = values[j];
- }
- }
- keys = newKeys;
- values = newValues;
- break;
- }
- }
+ @Override
+ public void remove(String id) {
+ synchronized (this) {
+ removeLocal(id);
}
}
+
+ @Override
+ public void control(String control, String msg) { }
};
try {
source = Gateway.getProxyManager().getProxy(new EntityPath(sysKey));
- source.subscribe(listener, path, false);
+ source.subscribe(new MemberSubscription<V>(listener, path, false));
} catch (Exception ex) {
Logger.error("Error subscribing to remote map. Changes will not be received");
Logger.error(ex);
}
}
-
- protected void loadKeys() throws ClusterStorageException {
- synchronized(keyLock) {
- keys = storage.getClusterContents(mSysKey, mPath+mName);
- values = new C2KLocalObject[keys.length];
+
+ protected void loadKeys() {
+ if (keyLock != null) return;
+ clear();
+ keyLock = new Object();
+ synchronized(this) {
+ String[] keys;
+ try {
+ keys = storage.getClusterContents(mSysKey, mPath+mName);
+ for (String key : keys) super.put(key, null);
+ } catch (ClusterStorageException e) {
+ Logger.error(e);
+ }
+
}
}
-
- protected String[] getKeys() {
- try {
- if (keys == null) loadKeys();
- } catch (ClusterStorageException e) {
- Logger.error(e);
- keys = new String[0];
- }
- return keys;
- }
-
+
public synchronized int getLastId() {
-
- synchronized (this) {
- int lastID = -1;
-
- String[] allIds = getKeys();
-
- for (int i = 0; i < allIds.length; i++) {
- try {
- int thisID = Integer.parseInt(allIds[i]);
- if (thisID > lastID) lastID = thisID;
- } catch (NumberFormatException e) {
- Logger.warning("RemoteMap.getLastID() - Cluster contained invalid id: "+allIds[i]);
- }
- }
- Logger.msg(7, "RemoteMap.getLastID() - last id in "+mPath+mName+" of "+mSysKey+" is "+lastID);
- return lastID;
- }
- }
-
+ loadKeys();
+ try {
+ return Integer.parseInt(lastKey());
+ } catch (NumberFormatException ex) {
+ return -1;
+ }
+ }
+
// c2kLocalObject methods
public void setID(int id) { mID = id; }
public int getID() { return mID; }
+ @Override
public void setName(String name) { mName = name; }
+ @Override
public String getName() { return mName; }
/**
* Cannot be stored
*/
+ @Override
public String getClusterType() {
return null;
}
/**
* @see java.util.Map#clear()
*/
+ @Override
public synchronized void clear() {
- keys = null;
+ synchronized (this) {
+ super.clear();
+ }
+ keyLock = null;
}
-
+
/**
* @see java.util.Map#containsKey(Object)
*/
+ @Override
public synchronized boolean containsKey(Object key) {
- getKeys();
- for (int i = 0; i < keys.length; i++) {
- if (key.equals(keys[i]))
- return true;
- }
- return false;
+ if (keyLock == null) loadKeys();
+ return super.containsKey(key);
}
/**
@@ -195,46 +167,40 @@ public class RemoteMap implements C2KLocalObject, Map {
* Very expensive, but if you must, you must.
* @see java.util.Map#containsValue(Object)
*/
+ @Override
public synchronized boolean containsValue(Object value) {
- getKeys();
- synchronized(keyLock) {
- if (values == null) values = new C2KLocalObject[keys.length];
- for (int i = 0; i < keys.length; i++) {
- try {
- if (values[i] == null) values[i] = storage.get(mSysKey, mPath+mName+"/"+keys[i], mLocker);
- if (value.equals(values[i])) return true;
- } catch (ClusterStorageException ex) {
- Logger.error(ex);
- } catch (ObjectNotFoundException e) {
- Logger.error(e);
- }
+ loadKeys();
+ synchronized(this) {
+ for (String key: keySet()) {
+ if (get(key).equals(value)) return true;
}
}
return false;
}
- /**
- * @see java.util.Map#entrySet()
- */
- public synchronized Set entrySet() {
- return new RemoteMap.RemoteSet(this, KEYS);
- }
/**
* @see java.util.Map#get(Object)
*/
- public synchronized Object get(Object key) {
- getKeys();
- synchronized(keyLock) {
- if (values == null) values = new C2KLocalObject[keys.length];
+ @Override
+ public synchronized V get(Object objKey) {
+ loadKeys();
+ String key;
+ if (objKey instanceof Integer)
+ key = ((Integer)objKey).toString();
+ else if (objKey instanceof String)
+ key = (String)objKey;
+ else
+ return null;
+
+ synchronized(this) {
try {
- for (int i = 0; i < keys.length; i++) {
- if (key.equals(keys[i])) {
- if (values[i] == null)
- values[i] = storage.get(mSysKey, mPath+mName+"/"+keys[i], mLocker);
- return values[i];
- }
+ V value = super.get(key);
+ if (value == null) {
+ value = (V)storage.get(mSysKey, mPath+mName+"/"+key, mLocker);
+ super.put(key, value);
}
+ return value;
} catch (ClusterStorageException e) {
Logger.error(e);
} catch (ObjectNotFoundException e) {
@@ -247,15 +213,19 @@ public class RemoteMap implements C2KLocalObject, Map {
/**
* @see java.util.Map#isEmpty()
*/
+ @Override
public synchronized boolean isEmpty() {
- return getKeys().length==0;
+ loadKeys();
+ return super.isEmpty();
}
/**
* @see java.util.Map#keySet()
*/
- public synchronized Set keySet() {
- return new RemoteMap.RemoteSet(this, KEYS);
+ @Override
+ public synchronized Set<String> keySet() {
+ loadKeys();
+ return super.keySet();
}
/**
@@ -263,60 +233,59 @@ public class RemoteMap implements C2KLocalObject, Map {
* the key is ignored - it can be fetched from the value.
* @see java.util.Map#put(Object, Object)
*/
- public synchronized Object put(Object key, Object value) {
+ @Override
+ public synchronized V put(String key, V value) {
try {
- C2KLocalObject newValue = (C2KLocalObject)value;
- synchronized(keyLock) {
- storage.put(mSysKey, newValue, mLocker);
- keys = null; values = null;
+ synchronized(this) {
+ storage.put(mSysKey, value, mLocker);
+ return putLocal(key, value);
}
} catch (ClusterStorageException e) {
Logger.error(e);
return null;
- } catch (ClassCastException e) {
- Logger.error("RemoteMap.put() - value was not a localobject, it was a "+value.getClass().getName());
- return null;
}
- return value;
}
-
- /**
- * @see java.util.Map#putAll(Map)
- */
- public synchronized void putAll(Map t) {
- for (Iterator iter = t.keySet().iterator(); iter.hasNext();) {
- Object key = iter.next();
- put(key, t.get(key));
- }
+
+ protected synchronized V putLocal(String key, V value) {
+ return super.put(key, value);
}
/**
* @see java.util.Map#remove(Object)
*/
- public synchronized Object remove(Object key) {
- try {
+ @Override
+ public synchronized V remove(Object key) {
+ loadKeys();
+ if (containsKey(key)) try {
synchronized(keyLock) {
storage.remove(mSysKey, mPath+mName+"/"+key, mLocker);
- keys = null; values = null;
- }
+ return super.remove(key);
+ }
} catch (ClusterStorageException e) {
Logger.error(e);
}
return null;
}
+
+ protected synchronized V removeLocal(Object key) {
+ return super.remove(key);
+ }
/**
* @see java.util.Map#size()
*/
+ @Override
public synchronized int size() {
- return getKeys().length;
+ loadKeys();
+ return super.size();
}
/**
* @see java.util.Map#values()
*/
- public synchronized Collection values() {
- return new RemoteMap.RemoteSet(this, VALUES);
+ @Override
+ public synchronized Collection<V> values() {
+ return new RemoteSet<V>(this);
}
/**
@@ -324,39 +293,45 @@ public class RemoteMap implements C2KLocalObject, Map {
* Disallows all writes.
*/
- private class RemoteSet extends AbstractSet {
- RemoteMap mParent;
- boolean mMode;
-
- public RemoteSet(RemoteMap parent, boolean mode) {
+ private class RemoteSet<E extends C2KLocalObject> extends AbstractSet<E> {
+ RemoteMap<E> mParent;
+
+ public RemoteSet(RemoteMap<E> parent) {
mParent = parent;
- mMode = mode;
}
- // no modifications allowed
- public boolean add(Object o) {
+ // no modifications allowed
+ @Override
+ public boolean add(E o) {
throw new UnsupportedOperationException();
}
- public boolean addAll(Collection c) {
+ @Override
+ public boolean addAll(Collection<? extends E> c) {
throw new UnsupportedOperationException();
}
- public void clear() {
+ @Override
+ public void clear() {
throw new UnsupportedOperationException();
}
- public boolean remove(Object o) {
+ @Override
+ public boolean remove(Object o) {
throw new UnsupportedOperationException();
}
- public boolean removeAll(Collection c) {
+ @Override
+ public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
- public boolean retainAll(Collection c) {
+ @Override
+ public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
- public Iterator iterator() {
- return new RemoteIterator(mParent, mMode);
+ @Override
+ public Iterator<E> iterator() {
+ return new RemoteIterator<E>(mParent);
}
+ @Override
public int size() {
return mParent.size();
}
@@ -366,32 +341,26 @@ public class RemoteMap implements C2KLocalObject, Map {
* Iterator view on RemoteMap data. Doesn't preload anything.
* REVISIT: Will go strange if the RemoteMap is modified. Detect this and throw ConcurrentMod ex
*/
- private class RemoteIterator implements Iterator {
- RemoteMap mParent;
- boolean mMode;
- String[] keyArr;
- int pos;
-
- public RemoteIterator(RemoteMap parent, boolean mode) {
+ private class RemoteIterator<C extends C2KLocalObject> implements Iterator<C> {
+ RemoteMap<C> mParent;
+ Iterator<String> iter;
+
+ public RemoteIterator(RemoteMap<C> parent) {
mParent = parent;
- mMode = mode;
- keyArr = mParent.getKeys();
+ iter = mParent.keySet().iterator();
}
+ @Override
public boolean hasNext() {
- return (pos<keyArr.length);
+ return iter.hasNext();
}
- public Object next() {
- if (pos == keyArr.length)
- throw new NoSuchElementException();
-
- if (mMode == KEYS)
- return keyArr[pos++];
- else
- return mParent.get(keyArr[pos++]);
+ @Override
+ public C next() {
+ return mParent.get(iter.next());
}
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}
diff --git a/source/com/c2kernel/persistency/TransactionManager.java b/source/com/c2kernel/persistency/TransactionManager.java
index 0908051..6517d8b 100644
--- a/source/com/c2kernel/persistency/TransactionManager.java
+++ b/source/com/c2kernel/persistency/TransactionManager.java
@@ -2,13 +2,11 @@ package com.c2kernel.persistency;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.agent.JobList;
import com.c2kernel.events.History;
-import com.c2kernel.lookup.InvalidEntityPathException;
import com.c2kernel.utils.Logger;
public class TransactionManager {
@@ -22,12 +20,12 @@ public class TransactionManager {
locks = new HashMap<Integer, Object>();
pendingTransactions = new HashMap<Object, ArrayList<TransactionEntry>>();
}
-
+
public boolean hasPendingTransactions()
{
return pendingTransactions.size() > 0;
}
-
+
public ClusterStorageManager getDb() {
return storage;
}
@@ -40,40 +38,36 @@ public class TransactionManager {
Logger.msg("Transaction Manager: Closing storages");
storage.close();
}
-
+
public String[] getClusterContents(int sysKey, String path) throws ClusterStorageException {
if (path.startsWith("/") && path.length() > 1) path = path.substring(1);
return storage.getClusterContents(new Integer(sysKey), path);
}
-
+
/**
* Public get method. Required a 'locker' object for a transaction key.
* Checks the transaction table first to see if the caller has uncommitted changes
*/
- public C2KLocalObject get(int sysKey, String path, Object locker)
- throws ClusterStorageException,
+ public C2KLocalObject get(int sysKey, String path, Object locker)
+ throws ClusterStorageException,
ObjectNotFoundException {
if (path.startsWith("/") && path.length() > 1) path = path.substring(1);
-
+
// deal out top level remote maps
- if (path.indexOf('/') == -1) {
- try {
- if (path.equals(ClusterStorage.HISTORY))
- return new History(sysKey, locker);
- if (path.equals(ClusterStorage.JOB))
- return new JobList(sysKey, locker);
- } catch (InvalidEntityPathException ex) {
- throw new ObjectNotFoundException("Invalid key");
- }
+ if (path.indexOf('/') == -1) {
+ if (path.equals(ClusterStorage.HISTORY))
+ return new History(sysKey, locker);
+ if (path.equals(ClusterStorage.JOB))
+ return new JobList(sysKey, locker);
}
-
+
Integer sysKeyIntObj = new Integer(sysKey);
// check to see if the locker has been modifying this cluster
synchronized(locks) {
if (locks.containsKey(sysKeyIntObj) && locks.get(sysKeyIntObj).equals(locker)) {
- ArrayList lockerTransaction = (ArrayList)pendingTransactions.get(locker);
- for (Iterator i = lockerTransaction.iterator(); i.hasNext(); ) {
- TransactionEntry thisEntry = (TransactionEntry)i.next();
+ ArrayList<?> lockerTransaction = pendingTransactions.get(locker);
+ for (Object name : lockerTransaction) {
+ TransactionEntry thisEntry = (TransactionEntry)name;
if (sysKey == thisEntry.sysKey.intValue() && path.equals(thisEntry.getPath())) {
if (thisEntry.obj == null)
throw new ClusterStorageException("ClusterStorageManager.get() - Cluster " + path + " has been deleted in " + sysKey +
@@ -94,7 +88,7 @@ public class TransactionManager {
Integer sysKeyIntObj = new Integer(sysKey);
ArrayList<TransactionEntry> lockerTransaction;
String path = ClusterStorage.getPath(obj);
-
+
synchronized(locks) {
// look to see if this object is already locked
if (locks.containsKey(sysKeyIntObj)) {
@@ -157,7 +151,7 @@ public class TransactionManager {
pendingTransactions.put(locker, lockerTransaction);
}
}
-
+
// create the new entry in the transaction table
TransactionEntry newEntry = new TransactionEntry(sysKeyIntObj, path, null);
/* equals() in TransactionEntry only compares sysKey and path, so we can use
@@ -167,38 +161,38 @@ public class TransactionManager {
if (lockerTransaction.contains(newEntry))
lockerTransaction.remove(newEntry);
lockerTransaction.add(newEntry);
- }
+ }
}
-
+
/**
* Removes all child objects from the given path
- *
+ *
* @param sysKey - entity to delete from
* @param path - root path to delete
* @param locker - locking object
- *
+ *
* @throws ClusterStorageException - when deleting fails
*/
public void removeCluster(int sysKey, String path, Object locker) throws ClusterStorageException {
-
+
String[] children = getClusterContents(sysKey, path);
- for (int i = 0; i < children.length; i++)
- removeCluster(sysKey, path+(path.length()>0?"/":"")+children[i], locker);
+ for (String element : children)
+ removeCluster(sysKey, path+(path.length()>0?"/":"")+element, locker);
if (children.length==0 && path.indexOf("/") > -1)
remove(sysKey, path, locker);
- }
+ }
/**
* Writes all pending changes to the backends.
*/
public void commit(Object locker) {
synchronized(locks) {
- ArrayList lockerTransactions = (ArrayList)pendingTransactions.get(locker);
+ ArrayList<?> lockerTransactions = pendingTransactions.get(locker);
HashMap<TransactionEntry, Exception> exceptions = new HashMap<TransactionEntry, Exception>();
// quit if no transactions are present;
if (lockerTransactions == null) return;
- for (Iterator i = lockerTransactions.iterator();i.hasNext();) {
- TransactionEntry thisEntry = (TransactionEntry)i.next();
+ for (Object name : lockerTransactions) {
+ TransactionEntry thisEntry = (TransactionEntry)name;
try {
if (thisEntry.obj == null)
storage.remove(thisEntry.sysKey, thisEntry.path);
@@ -207,14 +201,13 @@ public class TransactionManager {
locks.remove(thisEntry.sysKey);
} catch (Exception e) {
exceptions.put(thisEntry, e);
- }
+ }
}
pendingTransactions.remove(locker);
if (exceptions.size() > 0) { // oh dear
Logger.error("TransactionManager.commit() - Problems during transaction commit of locker "+locker.toString()+". Database may be in an inconsistent state.");
- for (Iterator iter = exceptions.keySet().iterator(); iter.hasNext();) {
- TransactionEntry entry = (TransactionEntry) iter.next();
- Exception ex = (Exception)exceptions.get(entry);
+ for (TransactionEntry entry : exceptions.keySet()) {
+ Exception ex = exceptions.get(entry);
Logger.msg(entry.toString());
Logger.error(ex);
}
@@ -231,8 +224,7 @@ public class TransactionManager {
public void abort(Object locker) {
synchronized(locks) {
if (locks.containsValue(locker)) {
- for (Iterator i=locks.keySet().iterator(); i.hasNext();) {
- Integer thisKey = (Integer)i.next();
+ for (Integer thisKey : locks.keySet()) {
if (locks.get(thisKey).equals(locker))
locks.remove(thisKey);
}
@@ -240,7 +232,7 @@ public class TransactionManager {
pendingTransactions.remove(locker);
}
}
-
+
public void clearCache(int sysKey, String path) {
if (sysKey == -1)
storage.clearCache();
@@ -248,9 +240,9 @@ public class TransactionManager {
storage.clearCache(new Integer(sysKey));
else
storage.clearCache(new Integer(sysKey), path);
-
+
}
-
+
public void dumpPendingTransactions(int logLevel) {
Logger.msg(logLevel, "================");
Logger.msg(logLevel, "Transaction dump");
@@ -258,22 +250,20 @@ public class TransactionManager {
if (locks.size() == 0)
Logger.msg(logLevel, " None");
else
- for (Iterator iter = locks.keySet().iterator(); iter.hasNext();) {
- Integer thisKey = (Integer)iter.next();
+ for (Integer thisKey : locks.keySet()) {
Object locker = locks.get(thisKey);
Logger.msg(logLevel, " "+thisKey+" locked by "+locker);
}
-
+
Logger.msg(logLevel, "Open transactions:");
if (pendingTransactions.size() == 0)
Logger.msg(logLevel, " None");
else
- for (Iterator iter = pendingTransactions.keySet().iterator(); iter.hasNext();) {
- Object thisLocker = iter.next();
+ for (Object thisLocker : pendingTransactions.keySet()) {
Logger.msg(logLevel, " Transaction owner:"+thisLocker);
- ArrayList entries = (ArrayList)pendingTransactions.get(thisLocker);
- for (Iterator iterator = entries.iterator(); iterator.hasNext();) {
- TransactionEntry thisEntry = (TransactionEntry) iterator.next();
+ ArrayList<?> entries = pendingTransactions.get(thisLocker);
+ for (Object name : entries) {
+ TransactionEntry thisEntry = (TransactionEntry) name;
Logger.msg(logLevel, " "+thisEntry.toString());
}
}
@@ -290,12 +280,13 @@ public class TransactionManager {
this.path = path;
this.obj = obj;
}
-
+
public String getPath() {
return ClusterStorage.getPath(obj);
}
- public String toString() {
+ @Override
+ public String toString() {
StringBuffer report = new StringBuffer();
if (obj == null)
report.append("Delete");
@@ -303,11 +294,12 @@ public class TransactionManager {
report.append("Put "+obj.getClass().getName());
report.append(" at ").append(path).append(" in ").append(sysKey);
return report.toString();
-
+
}
/**
* @see java.lang.Object#hashCode()
*/
+ @Override
public int hashCode() {
return sysKey.hashCode()*getPath().hashCode();
}
@@ -315,20 +307,21 @@ public class TransactionManager {
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object other) {
if (other instanceof TransactionEntry)
- return hashCode() == ((TransactionEntry)other).hashCode();
+ return hashCode() == ((TransactionEntry)other).hashCode();
return false;
}
}
-
+
public Object query(String id, Object query) throws ClusterStorageException {
return storage.query(id, query);
}
-
+
public String queryToXML(String id, String query, boolean genericFormat) throws ClusterStorageException {
return storage.queryToXML(id, query, genericFormat);
}
-
+
}
diff --git a/source/com/c2kernel/persistency/XMLClusterStorage.java b/source/com/c2kernel/persistency/XMLClusterStorage.java
index 24697af..277551d 100644
--- a/source/com/c2kernel/persistency/XMLClusterStorage.java
+++ b/source/com/c2kernel/persistency/XMLClusterStorage.java
@@ -17,7 +17,8 @@ public class XMLClusterStorage extends ClusterStorage {
public XMLClusterStorage() {
}
- public void open() throws ClusterStorageException {
+ @Override
+ public void open() throws ClusterStorageException {
String rootProp = Gateway.getProperty("XMLStorage.root");
if (rootProp == null)
throw new ClusterStorageException("XMLClusterStorage.open() - Root path not given in config file.");
@@ -31,33 +32,38 @@ public class XMLClusterStorage extends ClusterStorage {
}
}
- public void close() {
+ @Override
+ public void close() {
rootDir = null;
}
// introspection
- public short queryClusterSupport(String clusterType) {
+ @Override
+ public short queryClusterSupport(String clusterType) {
return ClusterStorage.READWRITE;
}
- public String getName() {
+ @Override
+ public String getName() {
return "XML File Cluster Storage";
}
-
- public String getId() {
+
+ @Override
+ public String getId() {
return "XML";
}
/* object manipulation */
// retrieve object by path
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
try {
String type = ClusterStorage.getClusterType(path);
String filePath = getFilePath(sysKey, path)+".xml";
String objString = FileStringUtility.file2String(filePath);
if (objString.length() == 0) return null;
-
+
if (type.equals("Outcome"))
return new Outcome(path, objString);
else
@@ -70,7 +76,8 @@ public class XMLClusterStorage extends ClusterStorage {
}
// store object by path
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
+ @Override
+ public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
try {
String filePath = getFilePath(sysKey, getPath(obj)+".xml");
Logger.msg(7, "Writing "+filePath);
@@ -89,7 +96,8 @@ public class XMLClusterStorage extends ClusterStorage {
}
// delete cluster
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public void delete(Integer sysKey, String path) throws ClusterStorageException {
try {
String filePath = getFilePath(sysKey, path+".xml");
boolean success = FileStringUtility.deleteDir(filePath, true, true);
@@ -104,11 +112,12 @@ public class XMLClusterStorage extends ClusterStorage {
/* navigation */
// directory listing
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
+ @Override
+ public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
String[] result = new String[0];
try {
String filePath = getFilePath(sysKey, path);
- ArrayList paths = FileStringUtility.listDir( filePath, true, false );
+ ArrayList<?> paths = FileStringUtility.listDir( filePath, true, false );
if (paths == null) return result; // dir doesn't exist yet
ArrayList<String> contents = new ArrayList<String>();
String previous = null;
@@ -126,8 +135,8 @@ public class XMLClusterStorage extends ClusterStorage {
if (next.indexOf('/') > -1) next = next.substring(next.lastIndexOf('/')+1);
contents.add(next);
}
-
- result = (String[])contents.toArray(result);
+
+ result = contents.toArray(result);
return result;
} catch (Exception e) {
Logger.error(e);
diff --git a/source/com/c2kernel/persistency/outcome/Outcome.java b/source/com/c2kernel/persistency/outcome/Outcome.java
index f919230..a5ecb29 100755..100644
--- a/source/com/c2kernel/persistency/outcome/Outcome.java
+++ b/source/com/c2kernel/persistency/outcome/Outcome.java
@@ -24,18 +24,18 @@ public class Outcome implements C2KLocalObject {
String mSchemaType;
int mSchemaVersion;
static DocumentBuilder parser;
-
+
static {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
- dbf.setNamespaceAware(false);
+ dbf.setNamespaceAware(false);
try {
parser = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
Logger.error(e);
- }
+ }
}
-
+
//id is the eventID
public Outcome(int id, String data, String schemaType, int schemaVersion) {
mID = id;
@@ -43,23 +43,23 @@ public class Outcome implements C2KLocalObject {
mSchemaType = schemaType;
mSchemaVersion = schemaVersion;
}
-
+
public Outcome(String path, String data) throws PersistencyException {
// derive all the meta data from the path
StringTokenizer tok = new StringTokenizer(path,"/");
- if (tok.countTokens() != 3 && !(tok.nextToken().equals("Outcome")))
+ if (tok.countTokens() != 3 && !(tok.nextToken().equals("Outcome")))
throw new PersistencyException("Outcome() - Outcome path must have three components: "+path, null);
mSchemaType = tok.nextToken();
String verstring = tok.nextToken();
String objId = tok.nextToken();
try {
mSchemaVersion = Integer.parseInt(verstring);
- } catch (NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
throw new PersistencyException("Outcome() - Outcome version was an invalid number: "+verstring, null);
}
try {
mID = Integer.parseInt(objId);
- } catch (NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
mID = -1;
}
mData = data;
@@ -73,7 +73,8 @@ public class Outcome implements C2KLocalObject {
return mID;
}
- public void setName(String name) {
+ @Override
+ public void setName(String name) {
try {
mID = Integer.parseInt(name);
} catch (NumberFormatException e) {
@@ -81,14 +82,15 @@ public class Outcome implements C2KLocalObject {
}
}
- public String getName() {
+ @Override
+ public String getName() {
return String.valueOf(mID);
}
public void setData(String data) {
mData = data;
}
-
+
public void setData(Document data) {
mData = serialize(data, false);
}
@@ -96,11 +98,11 @@ public class Outcome implements C2KLocalObject {
public String getData() {
return mData;
}
-
+
public void setSchemaType(String schemaType) {
mSchemaType = schemaType;
}
-
+
public String getSchemaType() {
return mSchemaType;
}
@@ -108,24 +110,25 @@ public class Outcome implements C2KLocalObject {
public void setSchemaURL(int schemaVersion) {
mSchemaVersion = schemaVersion;
}
-
+
public int getSchemaVersion() {
return mSchemaVersion;
- }
-
+ }
+
public void setSchemaVersion(int schVer) {
mSchemaVersion = schVer;
- }
-
+ }
+
+ @Override
public String getClusterType() {
return ClusterStorage.OUTCOME;
}
-
+
// special script API methods
/**
* Parses the outcome into a DOM tree
- * @return a DOM Document
+ * @return a DOM Document
*/
public Document getDOM() {
try {
@@ -137,7 +140,7 @@ public class Outcome implements C2KLocalObject {
return null;
}
}
-
+
static public String serialize(Document doc, boolean prettyPrint)
{
String serializedDoc = null;
diff --git a/source/com/c2kernel/persistency/outcome/OutcomeValidator.java b/source/com/c2kernel/persistency/outcome/OutcomeValidator.java
index 1a76322..73f5706 100755..100644
--- a/source/com/c2kernel/persistency/outcome/OutcomeValidator.java
+++ b/source/com/c2kernel/persistency/outcome/OutcomeValidator.java
@@ -10,7 +10,6 @@ import org.apache.xerces.parsers.XMLGrammarPreparser;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.XMLGrammarPoolImpl;
import org.apache.xerces.xni.XNIException;
-import org.apache.xerces.xni.grammars.Grammar;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
import org.apache.xerces.xni.parser.XMLErrorHandler;
import org.apache.xerces.xni.parser.XMLInputSource;
@@ -43,33 +42,33 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
/** Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking). */
protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking";
public static final String GRAMMAR_POOL = "http://apache.org/xml/properties/internal/grammar-pool";
-
+
static SchemaValidator schemaValid = new SchemaValidator();
-
+
Schema schema;
protected StringBuffer errors = null;
- XMLGrammarPoolImpl schemaGrammarPool = new XMLGrammarPoolImpl(1);
- SymbolTable sym = new SymbolTable();
-
+ XMLGrammarPoolImpl schemaGrammarPool = new XMLGrammarPoolImpl(1);
+ SymbolTable sym = new SymbolTable();
+
public static OutcomeValidator getValidator(Schema schema) throws InvalidDataException {
String schemaId = schema.docType+"_"+schema.docVersion;
-
+
if (schemaId.equals("Schema_0"))
return schemaValid;
-
+
return new OutcomeValidator(schema);
}
-
+
protected OutcomeValidator() {
errors = new StringBuffer();
}
-
+
public OutcomeValidator(Schema schema) throws InvalidDataException {
this.schema = schema;
-
+
if (schema.docType.equals("Schema"))
throw new InvalidDataException("Use SchemaValidator to validate schema", "");
-
+
errors = new StringBuffer();
Logger.msg(5, "Parsing "+schema.docType+" version "+schema.docVersion+". "+schema.schema.length()+" chars");
@@ -83,7 +82,7 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
preparser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
preparser.setErrorHandler(this);
try {
- Grammar g = preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, null, null, new StringReader(schema.schema), null));
+ preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, null, null, new StringReader(schema.schema), null));
} catch (IOException ex) {
throw new InvalidDataException("Error parsing schema: "+ex.getMessage(), "");
}
@@ -91,13 +90,13 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
if (errors.length() > 0) {
throw new InvalidDataException("Schema error: \n"+errors.toString(), "");
}
-
+
}
-
+
public synchronized String validate(Outcome outcome) {
if (outcome == null) return "Outcome object was null";
Logger.msg(5, "Validating outcome no "+outcome.getID()+" as "+schema.docType+" v"+schema.docVersion);
- if (outcome.getSchemaType().equals(schema.docType)
+ if (outcome.getSchemaType().equals(schema.docType)
&& outcome.getSchemaVersion() == schema.docVersion) {
return validate(outcome.getData());
}
@@ -112,20 +111,20 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
XMLParserConfiguration parserConfiguration = new IntegratedParserConfiguration(sym, schemaGrammarPool);
parserConfiguration.setFeature(NAMESPACES_FEATURE_ID, true);
parserConfiguration.setFeature(VALIDATION_FEATURE_ID, true);
- // now we can still do schema features just in case,
+ // now we can still do schema features just in case,
// so long as it's our configuraiton......
parserConfiguration.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
parserConfiguration.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
DOMParser parser = new DOMParser(parserConfiguration);
parser.setErrorHandler(this);
-
+
parser.parse(new XMLInputSource(null, null, null, new StringReader(outcome), null));
} catch (Exception e) {
return e.getMessage();
}
- return errors.toString();
- }
-
+ return errors.toString();
+ }
+
private void appendError(String level, Exception ex) {
errors.append(level);
String message = ex.getMessage();
@@ -134,32 +133,36 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
errors.append(message);
errors.append("\n");
}
-
+
/**
* ErrorHandler for instances
*/
- public void error(SAXParseException ex) throws SAXException {
+ @Override
+ public void error(SAXParseException ex) throws SAXException {
appendError("ERROR: ", ex);
}
/**
*
*/
- public void fatalError(SAXParseException ex) throws SAXException {
+ @Override
+ public void fatalError(SAXParseException ex) throws SAXException {
appendError("FATAL: ", ex);
}
/**
*
*/
- public void warning(SAXParseException ex) throws SAXException {
+ @Override
+ public void warning(SAXParseException ex) throws SAXException {
appendError("WARNING: ", ex);
}
/**
* XMLErrorHandler for schema
*/
- public void error(String domain, String key, XMLParseException ex)
+ @Override
+ public void error(String domain, String key, XMLParseException ex)
throws XNIException {
appendError("ERROR: ", ex);
}
@@ -167,7 +170,8 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
/**
*
*/
- public void fatalError(String domain, String key, XMLParseException ex)
+ @Override
+ public void fatalError(String domain, String key, XMLParseException ex)
throws XNIException {
appendError("FATAL: ", ex);
}
@@ -175,9 +179,10 @@ public class OutcomeValidator implements ErrorHandler, XMLErrorHandler {
/**
*
*/
- public void warning(String domain, String key, XMLParseException ex)
+ @Override
+ public void warning(String domain, String key, XMLParseException ex)
throws XNIException {
- appendError("WARNING: ", ex);
+ appendError("WARNING: ", ex);
}
}
diff --git a/source/com/c2kernel/persistency/outcome/Schema.java b/source/com/c2kernel/persistency/outcome/Schema.java
index 9514ebe..73969f2 100755..100644
--- a/source/com/c2kernel/persistency/outcome/Schema.java
+++ b/source/com/c2kernel/persistency/outcome/Schema.java
@@ -7,7 +7,7 @@ package com.c2kernel.persistency.outcome;
* $Date: 2006/09/14 14:13:26 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
+ * All rights reserved.
*/
public class Schema {
diff --git a/source/com/c2kernel/persistency/outcome/SchemaValidator.java b/source/com/c2kernel/persistency/outcome/SchemaValidator.java
index f2dfa0b..be8564b 100755..100644
--- a/source/com/c2kernel/persistency/outcome/SchemaValidator.java
+++ b/source/com/c2kernel/persistency/outcome/SchemaValidator.java
@@ -26,18 +26,19 @@ public class SchemaValidator extends OutcomeValidator {
*/
public SchemaValidator() {
-
+
}
public org.exolab.castor.xml.schema.Schema getSOM() {
- return castorSchema;
+ return castorSchema;
}
/**
*
*/
- public synchronized String validate(String outcome) {
+ @Override
+ public synchronized String validate(String outcome) {
errors = new StringBuffer();
try {
InputSource schemaSource = new InputSource(new StringReader(outcome));
diff --git a/source/com/c2kernel/persistency/outcome/Viewpoint.java b/source/com/c2kernel/persistency/outcome/Viewpoint.java
index 7fc2aa5..a3fe283 100755..100644
--- a/source/com/c2kernel/persistency/outcome/Viewpoint.java
+++ b/source/com/c2kernel/persistency/outcome/Viewpoint.java
@@ -16,13 +16,13 @@ import com.c2kernel.process.Gateway;
* $Date: 2005/10/05 07:39:36 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
+ * All rights reserved.
*/
// public static final String codeRevision =
// "$Revision: 1.10 $ $Date: 2005/10/05 07:39:36 $ $Author: abranson $";
public class Viewpoint implements C2KLocalObject {
-
+
int ID = -1; // not really used in this
// db fields
@@ -30,9 +30,9 @@ public class Viewpoint implements C2KLocalObject {
String schemaName;
String name;
int schemaVersion;
- int eventId;
+ int eventId;
public static final int NONE = -1;
-
+
public Viewpoint() {
eventId = NONE;
sysKey = Path.INVALID;
@@ -40,7 +40,7 @@ public class Viewpoint implements C2KLocalObject {
schemaName = null;
name = null;
}
-
+
public Viewpoint(int sysKey, String schemaName, String name, int schemaVersion, int eventId) {
this.sysKey = sysKey;
this.schemaName = schemaName;
@@ -55,6 +55,7 @@ public class Viewpoint implements C2KLocalObject {
return retVal;
}
+ @Override
public String getClusterType() {
return ClusterStorage.VIEWPOINT;
}
@@ -80,6 +81,7 @@ public class Viewpoint implements C2KLocalObject {
* Returns the name.
* @return String
*/
+ @Override
public String getName() {
return name;
}
@@ -128,6 +130,7 @@ public class Viewpoint implements C2KLocalObject {
* Sets the name.
* @param name The name to set
*/
+ @Override
public void setName(String name) {
this.name = name;
}
@@ -168,8 +171,9 @@ public class Viewpoint implements C2KLocalObject {
return (Event)Gateway.getStorage().get(sysKey, ClusterStorage.HISTORY+"/"+eventId, null);
}
-
- public String toString() {
+
+ @Override
+ public String toString() {
return name;
}