diff options
Diffstat (limited to 'src/main/java/com/c2kernel/persistency')
10 files changed, 210 insertions, 275 deletions
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorage.java b/src/main/java/com/c2kernel/persistency/ClusterStorage.java index 29f9174..cf7f401 100644 --- a/src/main/java/com/c2kernel/persistency/ClusterStorage.java +++ b/src/main/java/com/c2kernel/persistency/ClusterStorage.java @@ -1,6 +1,7 @@ package com.c2kernel.persistency;
import com.c2kernel.entity.C2KLocalObject;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.auth.Authenticator;
@@ -214,7 +215,7 @@ public abstract class ClusterStorage { * @throws ClusterStorageException
* when retrieval failed
*/
- public abstract C2KLocalObject get(Integer sysKey, String path)
+ public abstract C2KLocalObject get(ItemPath itemPath, String path)
throws ClusterStorageException;
/**
@@ -227,7 +228,7 @@ public abstract class ClusterStorage { * @throws ClusterStorageException
* When storage fails
*/
- public abstract void put(Integer sysKey, C2KLocalObject obj)
+ public abstract void put(ItemPath itemPath, C2KLocalObject obj)
throws ClusterStorageException;
/**
@@ -242,7 +243,7 @@ public abstract class ClusterStorage { * @throws ClusterStorageException
* When deletion fails or is not allowed
*/
- public abstract void delete(Integer sysKey, String path)
+ public abstract void delete(ItemPath itemPath, String path)
throws ClusterStorageException;
// directory listing
@@ -259,7 +260,7 @@ public abstract class ClusterStorage { * @throws ClusterStorageException
* When an error occurred during the query
*/
- public abstract String[] getClusterContents(Integer sysKey, String path)
+ public abstract String[] getClusterContents(ItemPath itemPath, String path)
throws ClusterStorageException;
}
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageException.java b/src/main/java/com/c2kernel/persistency/ClusterStorageException.java index 3b3ad50..8648f9e 100644 --- a/src/main/java/com/c2kernel/persistency/ClusterStorageException.java +++ b/src/main/java/com/c2kernel/persistency/ClusterStorageException.java @@ -1,32 +1,19 @@ package com.c2kernel.persistency;
/**
- *
- * @author abranson
- * @author ogattaz
+ *
+ * @version $Revision: 1.2 $ $Date: 2003/07/14 07:57:06 $
+ * @author $Author: abranson $
*/
public class ClusterStorageException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = -497478376391615904L;
-
- /**
- *
- */
- public ClusterStorageException() {
- super();
- }
-
- /**
- * @param aMessage
- * the detail message.
- */
- public ClusterStorageException(String aMessage) {
- super(aMessage);
- }
+ public ClusterStorageException() {
+ super();
+ }
+
+ public ClusterStorageException(String s) {
+ super(s);
+ }
/**
* @param aMessage
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java index 5227ab8..c82a50d 100644 --- a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java +++ b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java @@ -12,6 +12,7 @@ import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.agent.JobList;
import com.c2kernel.entity.proxy.ProxyMessage;
import com.c2kernel.events.History;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
@@ -23,10 +24,9 @@ import com.c2kernel.utils.WeakCache; /**
* instantiates ClusterStorages listed in properties file All read/write requests to storage pass through this object, which
* can query the capabilities of each declared storage, and channel requests accordingly. Transaction based.
- *
- * @author abranson
- * @author ogattaz
- *
+ *
+ * * @version $Revision: 1.62 $ $Date: 2006/02/01 13:27:46 $
+ * @author $Author: abranson $
*/
public class ClusterStorageManager {
HashMap<String, ClusterStorage> allStores = new HashMap<String, ClusterStorage>();
@@ -34,22 +34,12 @@ public class ClusterStorageManager { HashMap<String, ArrayList<ClusterStorage>> clusterWriters = new HashMap<String, ArrayList<ClusterStorage>>();
HashMap<String, ArrayList<ClusterStorage>> clusterReaders = new HashMap<String, ArrayList<ClusterStorage>>();
// we don't need a soft cache for the top level cache - the proxies and entities clear that when reaped
- HashMap<Integer, Map<String, C2KLocalObject>> memoryCache = new HashMap<Integer, Map<String, C2KLocalObject>>();
+ HashMap<ItemPath, Map<String, C2KLocalObject>> memoryCache = new HashMap<ItemPath, Map<String, C2KLocalObject>>();
- /**
- * Initialises all ClusterStorage handlers listed by class name in the
- * property "ClusterStorages" This property is usually process specific, and
- * so should be in the server/client.conf and not the connect file.
- *
- * 2014/08/28 ogattaz : put in place a protection in the constructor : set
- * the clusterPriority at the right size according the fact that the
- * "clusterStorageProp" property could contains a List of instance of String
- * and/or ClusterStorage
- *
- * @param auth
- * an instance of Authenticator
- * @throws ClusterStorageException
- */
+ /**
+ * Initialises all ClusterStorage handlers listed by class name in the property "ClusterStorages"
+ * This property is usually process specific, and so should be in the server/client.conf and not the connect file.
+ */
public ClusterStorageManager(Authenticator auth) throws ClusterStorageException {
Object clusterStorageProp = Gateway.getProperties().getObject("ClusterStorage");
if (clusterStorageProp == null || clusterStorageProp.equals("")) {
@@ -60,13 +50,10 @@ public class ClusterStorageManager { if (clusterStorageProp instanceof String)
rootStores = instantiateStores((String)clusterStorageProp);
else if (clusterStorageProp instanceof ArrayList<?>) {
- ArrayList<?> wTempStorages = (ArrayList<?>)clusterStorageProp;
-
- // set the clusterPriority at the right size
- clusterPriority = new String[wTempStorages.size()];
-
+ ArrayList<?> propStores = (ArrayList<?>)clusterStorageProp;
rootStores = new ArrayList<ClusterStorage>();
- for (Object thisStore : wTempStorages) {
+ clusterPriority = new String[propStores.size()];
+ for (Object thisStore : propStores) {
if (thisStore instanceof ClusterStorage)
rootStores.add((ClusterStorage)thisStore);
else
@@ -89,7 +76,7 @@ public class ClusterStorageManager { Logger.msg(5, "ClusterStorageManager.init() - Cluster storage " + newStorage.getClass().getName() +
" initialised successfully.");
allStores.put(newStorage.getId(), newStorage);
- clusterPriority[clusterNo++] = newStorage.getId();
+ clusterPriority[clusterNo++] = newStorage.getId();
}
clusterReaders.put(ClusterStorage.ROOT, rootStores); // all storages are queried for clusters at the root level
@@ -170,7 +157,7 @@ public class ClusterStorageManager { * 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 {
+ public String[] getClusterContents(ItemPath itemPath, String path) throws ClusterStorageException {
ArrayList<String> contents = new ArrayList<String>();
// get all readers
@@ -179,7 +166,7 @@ public class ClusterStorageManager { // try each in turn until we get a result
for (ClusterStorage thisReader : readers) {
try {
- String[] thisArr = thisReader.getClusterContents(sysKey, path);
+ String[] thisArr = thisReader.getClusterContents(itemPath, path);
if (thisArr != null) {
for (int j = 0; j < thisArr.length; j++)
if (!contents.contains(thisArr[j])) {
@@ -189,7 +176,7 @@ public class ClusterStorageManager { }
} catch (ClusterStorageException e) {
Logger.msg(5, "ClusterStorageManager.getClusterContents() - reader " + thisReader.getName() +
- " could not retrieve contents of " + sysKey + "/" + path + ": " + e.getMessage());
+ " could not retrieve contents of " + itemPath + "/" + path + ": " + e.getMessage());
}
}
@@ -199,16 +186,16 @@ public class ClusterStorageManager { }
/** Internal get method. Retrieves clusters from ClusterStorages & maintains the memory cache */
- public C2KLocalObject get(Integer sysKeyIntObj, String path) throws ClusterStorageException, ObjectNotFoundException {
+ public C2KLocalObject get(ItemPath itemPath, String path) throws ClusterStorageException, ObjectNotFoundException {
C2KLocalObject result = null;
// check cache first
Map<String, C2KLocalObject> sysKeyMemCache = null;
- sysKeyMemCache = memoryCache.get(sysKeyIntObj);
+ sysKeyMemCache = memoryCache.get(itemPath);
if (sysKeyMemCache != null) {
synchronized(sysKeyMemCache) {
C2KLocalObject obj = sysKeyMemCache.get(path);
if (obj != null) {
- Logger.msg(7, "ClusterStorageManager.get() - found "+sysKeyIntObj+"/"+path+" in memcache");
+ Logger.msg(7, "ClusterStorageManager.get() - found "+itemPath+"/"+path+" in memcache");
return obj;
}
}
@@ -220,7 +207,7 @@ public class ClusterStorageManager { StringTokenizer tok = new StringTokenizer(path,"/");
if (tok.countTokens() == 4) { // to not catch viewpoints called 'data'
Outcome data = null;
- Viewpoint view = (Viewpoint)get(sysKeyIntObj, path.substring(0, path.lastIndexOf("/")));
+ Viewpoint view = (Viewpoint)get(itemPath, path.substring(0, path.lastIndexOf("/")));
if (view != null)
data = view.getOutcome();
return data;
@@ -230,9 +217,9 @@ public class ClusterStorageManager { // deal out top level remote maps
if (path.indexOf('/') == -1) {
if (path.equals(ClusterStorage.HISTORY))
- result = new History(sysKeyIntObj, null);
+ result = new History(itemPath, null);
if (path.equals(ClusterStorage.JOB))
- result = new JobList(sysKeyIntObj, null);
+ result = new JobList(itemPath, null);
if (result!=null) {
synchronized(sysKeyMemCache) {
sysKeyMemCache.put(path, result);
@@ -246,16 +233,16 @@ public class ClusterStorageManager { ArrayList<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
for (ClusterStorage thisReader : readers) {
try {
- result = thisReader.get(sysKeyIntObj, path);
- Logger.msg(7, "ClusterStorageManager.get() - reading "+path+" from "+thisReader.getName() + " for intkey=" + sysKeyIntObj);
+ result = thisReader.get(itemPath, path);
+ Logger.msg(7, "ClusterStorageManager.get() - reading "+path+" from "+thisReader.getName() + " for item " + itemPath);
if (result != null) { // got it!
// store it in the cache
if (sysKeyMemCache == null) { // create cache if needed
boolean useWeak = Gateway.getProperties().getBoolean("Storage.useWeakCache", false);
- Logger.msg(7,"ClusterStorageManager.put() - Creating "+(useWeak?"Weak":"Strong")+" cache for entity "+sysKeyIntObj);
+ Logger.msg(7,"ClusterStorageManager.put() - Creating "+(useWeak?"Weak":"Strong")+" cache for item "+itemPath);
sysKeyMemCache = useWeak?new WeakCache<String, C2KLocalObject>():new SoftCache<String, C2KLocalObject>(0);
synchronized (memoryCache) {
- memoryCache.put(sysKeyIntObj, sysKeyMemCache);
+ memoryCache.put(itemPath, sysKeyMemCache);
}
}
synchronized(sysKeyMemCache) {
@@ -265,37 +252,37 @@ public class ClusterStorageManager { return result;
}
} catch (ClusterStorageException e) {
- Logger.msg(7, "ClusterStorageManager.get() - reader " + thisReader.getName() + " could not retrieve " + sysKeyIntObj +
+ Logger.msg(7, "ClusterStorageManager.get() - reader " + thisReader.getName() + " could not retrieve " + itemPath +
"/" + path + ": " + e.getMessage());
}
}
- throw new ObjectNotFoundException("ClusterStorageManager.get() - Path " + path + " not found in " + sysKeyIntObj, "");
+ throw new ObjectNotFoundException("ClusterStorageManager.get() - Path " + path + " not found in " + itemPath, "");
}
/** Internal put method. Creates or overwrites a cluster in all writers. Used when committing transactions. */
- public void put(Integer sysKeyIntObj, C2KLocalObject obj) throws ClusterStorageException {
+ public void put(ItemPath itemPath, C2KLocalObject obj) throws ClusterStorageException {
String path = ClusterStorage.getPath(obj);
ArrayList<ClusterStorage> writers = findStorages(ClusterStorage.getClusterType(path), true);
for (ClusterStorage thisWriter : writers) {
try {
Logger.msg(7, "ClusterStorageManager.put() - writing "+path+" to "+thisWriter.getName());
- thisWriter.put(sysKeyIntObj, obj);
+ thisWriter.put(itemPath, obj);
} catch (ClusterStorageException e) {
Logger.error("ClusterStorageManager.put() - writer " + thisWriter.getName() + " could not store " +
- sysKeyIntObj + "/" + path + ": " + e.getMessage());
+ itemPath + "/" + path + ": " + e.getMessage());
throw e;
}
}
// put in mem cache if that worked
Map<String, C2KLocalObject> sysKeyMemCache;
- if (memoryCache.containsKey(sysKeyIntObj))
- sysKeyMemCache = memoryCache.get(sysKeyIntObj);
+ if (memoryCache.containsKey(itemPath))
+ sysKeyMemCache = memoryCache.get(itemPath);
else {
boolean useWeak = Gateway.getProperties().getBoolean("Storage.useWeakCache", false);
- Logger.msg(7,"ClusterStorageManager.put() - Creating "+(useWeak?"Weak":"Strong")+" cache for entity "+sysKeyIntObj);
+ Logger.msg(7,"ClusterStorageManager.put() - Creating "+(useWeak?"Weak":"Strong")+" cache for entity "+itemPath);
sysKeyMemCache = useWeak?new WeakCache<String, C2KLocalObject>():new SoftCache<String, C2KLocalObject>(0);
synchronized (memoryCache) {
- memoryCache.put(sysKeyIntObj, sysKeyMemCache);
+ memoryCache.put(itemPath, sysKeyMemCache);
}
}
@@ -306,45 +293,45 @@ public class ClusterStorageManager { if (Logger.doLog(9)) dumpCacheContents(9);
// transmit proxy event
- Gateway.getProxyServer().sendProxyEvent( new ProxyMessage(sysKeyIntObj.intValue(), path, ProxyMessage.ADDED));
+ Gateway.getProxyServer().sendProxyEvent( new ProxyMessage(itemPath, path, ProxyMessage.ADDED));
}
/** Deletes a cluster from all writers */
- public void remove(Integer sysKeyIntObj, String path) throws ClusterStorageException {
+ public void remove(ItemPath itemPath, String path) throws ClusterStorageException {
ArrayList<ClusterStorage> writers = findStorages(ClusterStorage.getClusterType(path), true);
for (ClusterStorage thisWriter : writers) {
try {
Logger.msg(7, "ClusterStorageManager.delete() - removing "+path+" from "+thisWriter.getName());
- thisWriter.delete(sysKeyIntObj, path);
+ thisWriter.delete(itemPath, path);
} catch (ClusterStorageException e) {
- Logger.error("ClusterStorageManager.delete() - writer " + thisWriter.getName() + " could not delete " + sysKeyIntObj +
+ Logger.error("ClusterStorageManager.delete() - writer " + thisWriter.getName() + " could not delete " + itemPath +
"/" + path + ": " + e.getMessage());
throw e;
}
}
- if (memoryCache.containsKey(sysKeyIntObj)) {
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
- synchronized (sysKeyMemCache) {
- sysKeyMemCache.remove(path);
+ if (memoryCache.containsKey(itemPath)) {
+ Map<String, C2KLocalObject> itemMemCache = memoryCache.get(itemPath);
+ synchronized (itemMemCache) {
+ itemMemCache.remove(path);
}
}
// transmit proxy event
- Gateway.getProxyServer().sendProxyEvent( new ProxyMessage(sysKeyIntObj.intValue(), path, ProxyMessage.DELETED));
+ Gateway.getProxyServer().sendProxyEvent( new ProxyMessage(itemPath, path, ProxyMessage.DELETED));
}
- public void clearCache(Integer sysKeyIntObj, String path) {
- Logger.msg(7, "CSM.clearCache() - removing "+sysKeyIntObj+"/"+path);
+ public void clearCache(ItemPath itemPath, String path) {
+ Logger.msg(7, "CSM.clearCache() - removing "+itemPath+"/"+path);
- if (memoryCache.containsKey(sysKeyIntObj)) {
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
+ if (memoryCache.containsKey(itemPath)) {
+ Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
synchronized(sysKeyMemCache) {
for (Iterator<String> iter = sysKeyMemCache.keySet().iterator(); iter.hasNext();) {
String thisPath = iter.next();
if (thisPath.startsWith(path)) {
- Logger.msg(7, "CSM.clearCache() - removing "+sysKeyIntObj+"/"+thisPath);
+ Logger.msg(7, "CSM.clearCache() - removing "+itemPath+"/"+thisPath);
iter.remove();
}
}
@@ -352,18 +339,18 @@ public class ClusterStorageManager { }
}
- public void clearCache(Integer sysKeyIntObj) {
+ public void clearCache(ItemPath itemPath) {
- Logger.msg(5, "CSM.clearCache() - removing entire cache of "+sysKeyIntObj);
+ Logger.msg(5, "CSM.clearCache() - removing entire cache of "+itemPath);
- if (memoryCache.containsKey(sysKeyIntObj)) {
+ if (memoryCache.containsKey(itemPath)) {
synchronized (memoryCache) {
if (Logger.doLog(6)) {
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKeyIntObj);
+ Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
int size = sysKeyMemCache.size();
Logger.msg(6, "CSM.clearCache() - "+size+" objects to remove.");
}
- memoryCache.remove(sysKeyIntObj);
+ memoryCache.remove(itemPath);
}
}
else
@@ -380,9 +367,9 @@ public class ClusterStorageManager { public void dumpCacheContents(int logLevel) {
if (!Logger.doLog(logLevel)) return;
synchronized(memoryCache) {
- for (Integer sysKey : memoryCache.keySet()) {
- Logger.msg(logLevel, "Cached Objects of Entity "+sysKey);
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKey);
+ for (ItemPath itemPath : memoryCache.keySet()) {
+ Logger.msg(logLevel, "Cached Objects of Entity "+itemPath);
+ Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
try {
synchronized(sysKeyMemCache) {
for (Object name : sysKeyMemCache.keySet()) {
diff --git a/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java b/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java index cd5d122..dccf2af 100644 --- a/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java +++ b/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java @@ -6,17 +6,18 @@ import java.util.HashMap; import java.util.Map;
import com.c2kernel.entity.C2KLocalObject;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.utils.Logger;
public class MemoryOnlyClusterStorage extends ClusterStorage {
- HashMap<Integer, Map<String, C2KLocalObject>> memoryCache = new HashMap<Integer, Map<String, C2KLocalObject>>();
+ HashMap<ItemPath, Map<String, C2KLocalObject>> memoryCache = new HashMap<ItemPath, Map<String, C2KLocalObject>>();
/**
*
*/
public MemoryOnlyClusterStorage() {
- memoryCache = new HashMap<Integer, Map<String,C2KLocalObject>>();
+ memoryCache = new HashMap<ItemPath, Map<String,C2KLocalObject>>();
}
@Override
@@ -44,26 +45,26 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { }
@Override
- public C2KLocalObject get(Integer sysKey, String path)
+ public C2KLocalObject get(ItemPath thisItem, String path)
throws ClusterStorageException {
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKey);
+ Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(thisItem);
if (sysKeyMemCache != null)
return sysKeyMemCache.get(path);
return null;
}
@Override
- public void put(Integer sysKey, C2KLocalObject obj)
+ public void put(ItemPath thisItem, C2KLocalObject obj)
throws ClusterStorageException {
// create item cache if not present
Map<String, C2KLocalObject> sysKeyMemCache;
synchronized (memoryCache) {
- if (memoryCache.containsKey(sysKey))
- sysKeyMemCache = memoryCache.get(sysKey);
+ if (memoryCache.containsKey(thisItem))
+ sysKeyMemCache = memoryCache.get(thisItem);
else {
sysKeyMemCache = new HashMap<String, C2KLocalObject>();
- memoryCache.put(sysKey, sysKeyMemCache);
+ memoryCache.put(thisItem, sysKeyMemCache);
}
}
@@ -76,16 +77,16 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { }
@Override
- public void delete(Integer sysKey, String path)
+ public void delete(ItemPath thisItem, String path)
throws ClusterStorageException {
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKey);
+ Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(thisItem);
if (sysKeyMemCache != null) {
synchronized (sysKeyMemCache) {
if (sysKeyMemCache.containsKey(path)) {
sysKeyMemCache.remove(path);
if (sysKeyMemCache.isEmpty()) {
synchronized (memoryCache) {
- memoryCache.remove(sysKey);
+ memoryCache.remove(thisItem);
}
}
}
@@ -94,9 +95,9 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { }
@Override
- public String[] getClusterContents(Integer sysKey, String path)
+ public String[] getClusterContents(ItemPath thisItem, String path)
throws ClusterStorageException {
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKey);
+ Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(thisItem);
ArrayList<String> result = new ArrayList<String>();
if (sysKeyMemCache != null) {
while (path.endsWith("/"))
@@ -114,10 +115,10 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { return result.toArray(new String[result.size()]);
}
- public void dumpContents(int sysKey) {
+ public void dumpContents(ItemPath thisItem) {
synchronized(memoryCache) {
- Logger.msg(0, "Cached Objects of Entity "+sysKey);
- Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(sysKey);
+ Logger.msg(0, "Cached Objects of Entity "+thisItem);
+ Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(thisItem);
if (sysKeyMemCache == null) {
Logger.msg(0, "No cache found");
return;
diff --git a/src/main/java/com/c2kernel/persistency/NextKeyManager.java b/src/main/java/com/c2kernel/persistency/NextKeyManager.java deleted file mode 100644 index 1352405..0000000 --- a/src/main/java/com/c2kernel/persistency/NextKeyManager.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.c2kernel.persistency;
-
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.process.auth.Authenticator;
-
-/**
- * @author abranson
- *
- */
-public interface NextKeyManager {
-
-
- public void open(Authenticator auth);
- /**
- *
- * @return
- * @throws ObjectCannotBeUpdated
- * @throws ObjectNotFoundException
- */
- public ItemPath generateNextEntityKey()
- throws ObjectCannotBeUpdated, ObjectNotFoundException;
-
- /**
- * @return
- * @throws ObjectCannotBeUpdated
- * @throws ObjectNotFoundException
- */
- public AgentPath generateNextAgentKey()
- throws ObjectCannotBeUpdated, ObjectNotFoundException;
-
- /**
- * @param sysKey
- * @throws ObjectCannotBeUpdated
- * @throws ObjectNotFoundException
- */
- public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException;
-
- /**
- * @return
- * @throws ObjectNotFoundException
- */
- public ItemPath getLastEntityPath() throws ObjectNotFoundException;
-
- /**
- * Shuts down the next key manager
- */
- public void close();
-}
diff --git a/src/main/java/com/c2kernel/persistency/ProxyLoader.java b/src/main/java/com/c2kernel/persistency/ProxyLoader.java index 57b91af..9a7f7bd 100644 --- a/src/main/java/com/c2kernel/persistency/ProxyLoader.java +++ b/src/main/java/com/c2kernel/persistency/ProxyLoader.java @@ -19,7 +19,7 @@ import com.c2kernel.utils.Logger; */
public class ProxyLoader extends ClusterStorage {
- HashMap<Integer, Item> entities = new HashMap<Integer, Item>();
+ HashMap<ItemPath, Item> entities = new HashMap<ItemPath, Item>();
Lookup lookup;
@Override
@@ -48,14 +48,14 @@ public class ProxyLoader extends ClusterStorage { // retrieve object by path
@Override
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
+ public C2KLocalObject get(ItemPath thisItem, String path) throws ClusterStorageException {
try {
- Item thisEntity = getIOR(sysKey);
+ Item thisEntity = getIOR(thisItem);
String type = getClusterType(path);
// fetch the xml from the item
String queryData = thisEntity.queryData(path);
- if (Logger.doLog(6)) Logger.msg(6, "ProxyLoader - "+sysKey+":"+path+" = "+queryData);
+ if (Logger.doLog(6)) Logger.msg(6, "ProxyLoader - "+thisItem+":"+path+" = "+queryData);
if (queryData != null) {
if (type.equals(OUTCOME))
@@ -74,13 +74,13 @@ public class ProxyLoader extends ClusterStorage { // store object by path
@Override
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
+ public void put(ItemPath thisItem, C2KLocalObject obj) throws ClusterStorageException {
// not supported
throw new ClusterStorageException("Cannot write to items through the ProxyLoader");
}
// delete cluster
@Override
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
+ public void delete(ItemPath thisItem, String path) throws ClusterStorageException {
// not supported
throw new ClusterStorageException("Cannot write to items through the ProxyLoader");
}
@@ -89,9 +89,9 @@ public class ProxyLoader extends ClusterStorage { // directory listing
@Override
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
+ public String[] getClusterContents(ItemPath thisItem, String path) throws ClusterStorageException {
try {
- Item thisEntity = getIOR(sysKey);
+ Item thisEntity = getIOR(thisItem);
String contents = thisEntity.queryData(path+"/all");
StringTokenizer tok = new StringTokenizer(contents, ",");
String[] result = new String[tok.countTokens()];
@@ -105,16 +105,16 @@ public class ProxyLoader extends ClusterStorage { }
}
- private Item getIOR(Integer sysKey) throws ClusterStorageException {
- if (entities.containsKey(sysKey)) {
+ private Item getIOR(ItemPath thisPath) throws ClusterStorageException {
+ if (entities.containsKey(thisPath)) {
// check the cache
- Logger.msg(7, "ProxyLoader.getIOR() - "+sysKey+" cached.");
- return entities.get(sysKey);
+ Logger.msg(7, "ProxyLoader.getIOR() - "+thisPath+" cached.");
+ return entities.get(thisPath);
}
try {
- Logger.msg(7, "ProxyLoader.getIOR() - Resolving "+sysKey+".");
- org.omg.CORBA.Object ior = lookup.resolve(new ItemPath(sysKey.intValue()));
+ Logger.msg(7, "ProxyLoader.getIOR() - Resolving "+thisPath+".");
+ org.omg.CORBA.Object ior = lookup.resolve(thisPath);
Item thisItem = null;
try {
@@ -123,15 +123,15 @@ public class ProxyLoader extends ClusterStorage { try {
thisItem = AgentHelper.narrow(ior);
} catch (org.omg.CORBA.BAD_PARAM ex2) {
- throw new ClusterStorageException ("Could not narrow "+sysKey+" as a known Entity type");
+ throw new ClusterStorageException ("Could not narrow "+thisItem+" as a known Entity type");
}
}
- Logger.msg(7, "ProxyLoader.getIOR() - Found "+sysKey+".");
- entities.put(sysKey, thisItem);
+ Logger.msg(7, "ProxyLoader.getIOR() - Found "+thisItem+".");
+ entities.put(thisPath, thisItem);
return thisItem;
} catch (Exception e) {
- throw new ClusterStorageException("Error narrowing "+sysKey+": "+e.getMessage());
+ throw new ClusterStorageException("Error narrowing "+thisPath+": "+e.getMessage());
}
}
}
diff --git a/src/main/java/com/c2kernel/persistency/RemoteMap.java b/src/main/java/com/c2kernel/persistency/RemoteMap.java index 9f1d8a3..48ed220 100644 --- a/src/main/java/com/c2kernel/persistency/RemoteMap.java +++ b/src/main/java/com/c2kernel/persistency/RemoteMap.java @@ -30,7 +30,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl private int mID=-1;
private String mName;
- protected int mSysKey;
+ protected ItemPath mItemPath;
private String mPath = "";
Object keyLock = null;
TransactionManager storage;
@@ -39,7 +39,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl ItemProxy source;
Object mLocker; // if this remote map will participate in a transaction
- public RemoteMap(int sysKey, String path, Object locker) {
+ public RemoteMap(ItemPath itemPath, String path, Object locker) {
super(new Comparator<String>() {
@Override
@@ -54,7 +54,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl }
});
- mSysKey = sysKey;
+ mItemPath = itemPath;
mLocker = locker;
// split the path into path/name
@@ -88,7 +88,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl };
try {
- source = Gateway.getProxyManager().getProxy(new ItemPath(sysKey));
+ source = Gateway.getProxyManager().getProxy(mItemPath);
source.subscribe(new MemberSubscription<V>(listener, path, false));
} catch (Exception ex) {
Logger.error("Error subscribing to remote map. Changes will not be received");
@@ -103,7 +103,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl synchronized(this) {
String[] keys;
try {
- keys = storage.getClusterContents(mSysKey, mPath+mName);
+ keys = storage.getClusterContents(mItemPath, mPath+mName);
for (String key : keys) super.put(key, null);
} catch (ClusterStorageException e) {
Logger.error(e);
@@ -198,7 +198,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl try {
V value = super.get(key);
if (value == null) {
- value = (V)storage.get(mSysKey, mPath+mName+"/"+key, mLocker);
+ value = (V)storage.get(mItemPath, mPath+mName+"/"+key, mLocker);
super.put(key, value);
}
return value;
@@ -238,7 +238,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl public synchronized V put(String key, V value) {
try {
synchronized(this) {
- storage.put(mSysKey, value, mLocker);
+ storage.put(mItemPath, value, mLocker);
return putLocal(key, value);
}
} catch (ClusterStorageException e) {
@@ -259,7 +259,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl loadKeys();
if (containsKey(key)) try {
synchronized(keyLock) {
- storage.remove(mSysKey, mPath+mName+"/"+key, mLocker);
+ storage.remove(mItemPath, mPath+mName+"/"+key, mLocker);
return super.remove(key);
}
} catch (ClusterStorageException e) {
diff --git a/src/main/java/com/c2kernel/persistency/TransactionManager.java b/src/main/java/com/c2kernel/persistency/TransactionManager.java index 7362ae1..b28a440 100644 --- a/src/main/java/com/c2kernel/persistency/TransactionManager.java +++ b/src/main/java/com/c2kernel/persistency/TransactionManager.java @@ -7,18 +7,19 @@ 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.ItemPath;
import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.utils.Logger;
public class TransactionManager {
- HashMap<Integer, Object> locks;
+ HashMap<ItemPath, Object> locks;
HashMap<Object, ArrayList<TransactionEntry>> pendingTransactions;
ClusterStorageManager storage;
public TransactionManager(Authenticator auth) throws ClusterStorageException {
storage = new ClusterStorageManager(auth);
- locks = new HashMap<Integer, Object>();
+ locks = new HashMap<ItemPath, Object>();
pendingTransactions = new HashMap<Object, ArrayList<TransactionEntry>>();
}
@@ -40,16 +41,16 @@ public class TransactionManager { storage.close();
}
- public String[] getClusterContents(int sysKey, String path) throws ClusterStorageException {
+ public String[] getClusterContents(ItemPath itemPath, String path) throws ClusterStorageException {
if (path.startsWith("/") && path.length() > 1) path = path.substring(1);
- return storage.getClusterContents(new Integer(sysKey), path);
+ return storage.getClusterContents(itemPath, 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)
+ public C2KLocalObject get(ItemPath itemPath, String path, Object locker)
throws ClusterStorageException,
ObjectNotFoundException {
if (path.startsWith("/") && path.length() > 1) path = path.substring(1);
@@ -57,56 +58,54 @@ public class TransactionManager { // deal out top level remote maps, if transactions aren't needed
if (path.indexOf('/') == -1) {
if (path.equals(ClusterStorage.HISTORY) && locker != null)
- return new History(sysKey, locker);
+ return new History(itemPath, locker);
if (path.equals(ClusterStorage.JOB) && locker != null)
- return new JobList(sysKey, locker);
+ return new JobList(itemPath, locker);
}
- Integer sysKeyIntObj = new Integer(sysKey);
// check to see if the locker has been modifying this cluster
- if (locks.containsKey(sysKeyIntObj) && locks.get(sysKeyIntObj).equals(locker)) {
+ if (locks.containsKey(itemPath) && locks.get(itemPath).equals(locker)) {
ArrayList<TransactionEntry> lockerTransaction = pendingTransactions.get(locker);
for (TransactionEntry thisEntry : lockerTransaction) {
- if (sysKey == thisEntry.sysKey.intValue() && path.equals(thisEntry.getPath())) {
+ if (itemPath.equals(thisEntry.itemPath) && path.equals(thisEntry.path)) {
if (thisEntry.obj == null)
- throw new ClusterStorageException("ClusterStorageManager.get() - Cluster " + path + " has been deleted in " + sysKey +
+ throw new ClusterStorageException("ClusterStorageManager.get() - Cluster " + path + " has been deleted in " + itemPath +
" but not yet committed");
return thisEntry.obj;
}
}
}
- return storage.get(sysKeyIntObj, path);
+ return storage.get(itemPath, path);
}
/**
* Public put method. Manages the transaction table keyed by the object 'locker'.
* If this object is null, transaction support is bypassed (so long as no lock exists on that object).
*/
- public void put(int sysKey, C2KLocalObject obj, Object locker) throws ClusterStorageException {
- Integer sysKeyIntObj = new Integer(sysKey);
+ public void put(ItemPath itemPath, C2KLocalObject obj, Object locker) throws ClusterStorageException {
Object tempLocker = null;
ArrayList<TransactionEntry> lockerTransaction;
String path = ClusterStorage.getPath(obj);
synchronized(locks) {
// look to see if this object is already locked
- if (locks.containsKey(sysKeyIntObj)) {
+ if (locks.containsKey(itemPath)) {
// if it's this locker, get the transaction list
- Object thisLocker = locks.get(sysKeyIntObj);
+ Object thisLocker = locks.get(itemPath);
if (thisLocker.equals(locker)) // retrieve the transaction list
lockerTransaction = pendingTransactions.get(locker);
else // locked by someone else
- throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + sysKeyIntObj +
+ throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + itemPath +
" has been locked for writing by " + thisLocker);
}
else { // no locks for this item
if (locker == null) { // lock the item until the non-transactional put is complete :/
tempLocker = new Object();
- locks.put(sysKeyIntObj, tempLocker);
+ locks.put(itemPath, tempLocker);
lockerTransaction = null;
}
else { // initialise the transaction
- locks.put(sysKeyIntObj, locker);
+ locks.put(itemPath, locker);
lockerTransaction = new ArrayList<TransactionEntry>();
pendingTransactions.put(locker, lockerTransaction);
}
@@ -114,13 +113,13 @@ public class TransactionManager { }
if (tempLocker != null) { // non-locking put/delete
- storage.put(sysKeyIntObj, obj);
- locks.remove(sysKeyIntObj);
+ storage.put(itemPath, obj);
+ locks.remove(itemPath);
return;
}
// create the new entry in the transaction table
- TransactionEntry newEntry = new TransactionEntry(sysKeyIntObj, path, obj);
+ TransactionEntry newEntry = new TransactionEntry(itemPath, obj);
/* equals() in TransactionEntry only compares sysKey and path, so we can use
* contains() in ArrayList to looks for preexisting entries for this cluster
* and overwrite them.
@@ -132,29 +131,28 @@ public class TransactionManager { /** Public delete method. Uses the put method, with null as the object value.
*/
- public void remove(int sysKey, String path, Object locker) throws ClusterStorageException {
- Integer sysKeyIntObj = new Integer(sysKey);
+ public void remove(ItemPath itemPath, String path, Object locker) throws ClusterStorageException {
ArrayList<TransactionEntry> lockerTransaction;
Object tempLocker = null;
synchronized(locks) {
// look to see if this object is already locked
- if (locks.containsKey(sysKeyIntObj)) {
+ if (locks.containsKey(itemPath)) {
// if it's this locker, get the transaction list
- Object thisLocker = locks.get(sysKeyIntObj);
+ Object thisLocker = locks.get(itemPath);
if (thisLocker.equals(locker)) // retrieve the transaction list
lockerTransaction = pendingTransactions.get(locker);
else // locked by someone else
- throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + sysKeyIntObj +
+ throw new ClusterStorageException("ClusterStorageManager.get() - Access denied: Object " + itemPath +
" has been locked for writing by " + thisLocker);
}
else { // either we are the locker, or there is no locker
if (locker == null) { // non-locking put/delete
tempLocker = new Object();
- locks.put(sysKeyIntObj, tempLocker);
+ locks.put(itemPath, tempLocker);
lockerTransaction = null;
}
else {// initialise the transaction
- locks.put(sysKeyIntObj, locker);
+ locks.put(itemPath, locker);
lockerTransaction = new ArrayList<TransactionEntry>();
pendingTransactions.put(locker, lockerTransaction);
}
@@ -162,13 +160,13 @@ public class TransactionManager { }
if (tempLocker != null) {
- storage.remove(sysKeyIntObj, path);
- locks.remove(sysKeyIntObj);
+ storage.remove(itemPath, path);
+ locks.remove(itemPath);
return;
}
// create the new entry in the transaction table
- TransactionEntry newEntry = new TransactionEntry(sysKeyIntObj, path, null);
+ TransactionEntry newEntry = new TransactionEntry(itemPath, path);
/* equals() in TransactionEntry only compares sysKey and path, so we can use
* contains() in ArrayList to looks for preexisting entries for this cluster
* and overwrite them.
@@ -188,13 +186,13 @@ public class TransactionManager { *
* @throws ClusterStorageException - when deleting fails
*/
- public void removeCluster(int sysKey, String path, Object locker) throws ClusterStorageException {
+ public void removeCluster(ItemPath itemPath, String path, Object locker) throws ClusterStorageException {
- String[] children = getClusterContents(sysKey, path);
+ String[] children = getClusterContents(itemPath, path);
for (String element : children)
- removeCluster(sysKey, path+(path.length()>0?"/":"")+element, locker);
+ removeCluster(itemPath, path+(path.length()>0?"/":"")+element, locker);
if (children.length==0 && path.indexOf("/") > -1)
- remove(sysKey, path, locker);
+ remove(itemPath, path, locker);
}
/**
@@ -209,10 +207,10 @@ public class TransactionManager { for (TransactionEntry thisEntry : lockerTransactions) {
try {
if (thisEntry.obj == null)
- storage.remove(thisEntry.sysKey, thisEntry.path);
+ storage.remove(thisEntry.itemPath, thisEntry.path);
else
- storage.put(thisEntry.sysKey, thisEntry.obj);
- locks.remove(thisEntry.sysKey);
+ storage.put(thisEntry.itemPath, thisEntry.obj);
+ locks.remove(thisEntry.itemPath);
} catch (Exception e) {
exceptions.put(thisEntry, e);
}
@@ -238,22 +236,22 @@ public class TransactionManager { public void abort(Object locker) {
synchronized(locks) {
if (locks.containsValue(locker)) {
- for (Integer thisKey : locks.keySet()) {
- if (locks.get(thisKey).equals(locker))
- locks.remove(thisKey);
+ for (ItemPath thisPath : locks.keySet()) {
+ if (locks.get(thisPath).equals(locker))
+ locks.remove(thisPath);
}
}
pendingTransactions.remove(locker);
}
}
- public void clearCache(int sysKey, String path) {
- if (sysKey == -1)
+ public void clearCache(ItemPath itemPath, String path) {
+ if (itemPath == null)
storage.clearCache();
else if (path == null)
- storage.clearCache(new Integer(sysKey));
+ storage.clearCache(itemPath);
else
- storage.clearCache(new Integer(sysKey), path);
+ storage.clearCache(itemPath, path);
}
@@ -264,9 +262,9 @@ public class TransactionManager { if (locks.size() == 0)
Logger.msg(logLevel, " None");
else
- for (Integer thisKey : locks.keySet()) {
- Object locker = locks.get(thisKey);
- Logger.msg(logLevel, " "+thisKey+" locked by "+locker);
+ for (ItemPath thisPath : locks.keySet()) {
+ Object locker = locks.get(thisPath);
+ Logger.msg(logLevel, " "+thisPath+" locked by "+locker);
}
Logger.msg(logLevel, "Open transactions:");
@@ -285,17 +283,19 @@ public class TransactionManager { /** Used in the transaction table to store details of a put until commit
*/
class TransactionEntry {
- public Integer sysKey;
+ public ItemPath itemPath;
public String path;
public C2KLocalObject obj;
- public TransactionEntry(Integer sysKey, String path, C2KLocalObject obj) {
- this.sysKey = sysKey;
- this.path = path;
+ public TransactionEntry(ItemPath itemPath, C2KLocalObject obj) {
+ this.itemPath = itemPath;
+ this.path = ClusterStorage.getPath(obj);
this.obj = obj;
}
-
- public String getPath() {
- return ClusterStorage.getPath(obj);
+
+ public TransactionEntry(ItemPath itemPath, String path) {
+ this.itemPath = itemPath;
+ this.path = path;
+ this.obj = null;
}
@Override
@@ -305,7 +305,7 @@ public class TransactionManager { report.append("Delete");
else
report.append("Put "+obj.getClass().getName());
- report.append(" at ").append(path).append(" in ").append(sysKey);
+ report.append(" at ").append(path).append(" in ").append(itemPath);
return report.toString();
}
@@ -314,7 +314,7 @@ public class TransactionManager { */
@Override
public int hashCode() {
- return sysKey.hashCode()*getPath().hashCode();
+ return itemPath.hashCode()*path.hashCode();
}
/**
diff --git a/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java b/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java index e6c6e9f..8f01d8e 100644 --- a/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java +++ b/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java @@ -57,10 +57,10 @@ public class XMLClusterStorage extends ClusterStorage { // retrieve object by path
@Override
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
+ public C2KLocalObject get(ItemPath itemPath, String path) throws ClusterStorageException {
try {
String type = ClusterStorage.getClusterType(path);
- String filePath = getFilePath(sysKey, path)+".xml";
+ String filePath = getFilePath(itemPath, path)+".xml";
String objString = FileStringUtility.file2String(filePath);
if (objString.length() == 0) return null;
Logger.debug(9, objString);
@@ -72,16 +72,16 @@ public class XMLClusterStorage extends ClusterStorage { }
} catch (Exception e) {
- Logger.msg(3,"XMLClusterStorage.get() - The path "+path+" from "+sysKey+" does not exist.: "+e.getMessage());
+ Logger.msg(3,"XMLClusterStorage.get() - The path "+path+" from "+itemPath+" does not exist.: "+e.getMessage());
}
return null;
}
// store object by path
@Override
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
+ public void put(ItemPath itemPath, C2KLocalObject obj) throws ClusterStorageException {
try {
- String filePath = getFilePath(sysKey, getPath(obj)+".xml");
+ String filePath = getFilePath(itemPath, getPath(obj)+".xml");
Logger.msg(7, "Writing "+filePath);
String data = Gateway.getMarshaller().marshall(obj);
@@ -93,32 +93,32 @@ public class XMLClusterStorage extends ClusterStorage { FileStringUtility.string2File(filePath, data);
} catch (Exception e) {
Logger.error(e);
- throw new ClusterStorageException("XMLClusterStorage.put() - Could not write "+getPath(obj)+" to "+sysKey);
+ throw new ClusterStorageException("XMLClusterStorage.put() - Could not write "+getPath(obj)+" to "+itemPath);
}
}
// delete cluster
@Override
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
+ public void delete(ItemPath itemPath, String path) throws ClusterStorageException {
try {
- String filePath = getFilePath(sysKey, path+".xml");
+ String filePath = getFilePath(itemPath, path+".xml");
boolean success = FileStringUtility.deleteDir(filePath, true, true);
if (success) return;
- filePath = getFilePath(sysKey, path);
+ filePath = getFilePath(itemPath, path);
success = FileStringUtility.deleteDir(filePath, true, true);
if (success) return;
} catch(Exception e) { }
- throw new ClusterStorageException("XMLClusterStorage.delete() - Failure deleting path "+path+" in "+sysKey);
+ throw new ClusterStorageException("XMLClusterStorage.delete() - Failure deleting path "+path+" in "+itemPath);
}
/* navigation */
// directory listing
@Override
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
+ public String[] getClusterContents(ItemPath itemPath, String path) throws ClusterStorageException {
String[] result = new String[0];
try {
- String filePath = getFilePath(sysKey, path);
+ String filePath = getFilePath(itemPath, path);
ArrayList<String> paths = FileStringUtility.listDir( filePath, true, false );
if (paths == null) return result; // dir doesn't exist yet
ArrayList<String> contents = new ArrayList<String>();
@@ -142,14 +142,13 @@ public class XMLClusterStorage extends ClusterStorage { return result;
} catch (Exception e) {
Logger.error(e);
- throw new ClusterStorageException("XMLClusterStorage.getClusterContents() - Could not get contents of "+path+" from "+sysKey+": "+e.getMessage());
+ throw new ClusterStorageException("XMLClusterStorage.getClusterContents() - Could not get contents of "+path+" from "+itemPath+": "+e.getMessage());
}
}
- protected String getFilePath(Integer sysKey, String path) throws InvalidItemPathException {
- ItemPath thisEntity = new ItemPath(sysKey.intValue());
+ protected String getFilePath(ItemPath itemPath, String path) throws InvalidItemPathException {
if (path.length() == 0 || path.charAt(0) != '/') path = "/"+path;
- String filePath = rootDir+thisEntity.toString()+path;
+ String filePath = rootDir+itemPath.toString()+path;
Logger.msg(8, "XMLClusterStorage.getFilePath() - "+filePath);
return filePath;
}
diff --git a/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java b/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java index a3fe283..db7e8d7 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java +++ b/src/main/java/com/c2kernel/persistency/outcome/Viewpoint.java @@ -1,10 +1,12 @@ package com.c2kernel.persistency.outcome;
+import java.util.UUID;
+
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.events.Event;
-import com.c2kernel.lookup.Path;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
@@ -26,7 +28,7 @@ public class Viewpoint implements C2KLocalObject { int ID = -1; // not really used in this
// db fields
- int sysKey;
+ ItemPath itemPath;
String schemaName;
String name;
int schemaVersion;
@@ -35,14 +37,14 @@ public class Viewpoint implements C2KLocalObject { public Viewpoint() {
eventId = NONE;
- sysKey = Path.INVALID;
+ itemPath = null;
schemaVersion = NONE;
schemaName = null;
name = null;
}
- public Viewpoint(int sysKey, String schemaName, String name, int schemaVersion, int eventId) {
- this.sysKey = sysKey;
+ public Viewpoint(ItemPath itemPath, String schemaName, String name, int schemaVersion, int eventId) {
+ this.itemPath = itemPath;
this.schemaName = schemaName;
this.name = name;
this.schemaVersion = schemaVersion;
@@ -51,7 +53,7 @@ public class Viewpoint implements C2KLocalObject { public Outcome getOutcome() throws ObjectNotFoundException, ClusterStorageException {
if (eventId == NONE) throw new ObjectNotFoundException("No last eventId defined", "");
- Outcome retVal = (Outcome)Gateway.getStorage().get(sysKey, ClusterStorage.OUTCOME+"/"+schemaName+"/"+schemaVersion+"/"+eventId, null);
+ Outcome retVal = (Outcome)Gateway.getStorage().get(itemPath, ClusterStorage.OUTCOME+"/"+schemaName+"/"+schemaVersion+"/"+eventId, null);
return retVal;
}
@@ -106,8 +108,8 @@ public class Viewpoint implements C2KLocalObject { * Returns the sysKey.
* @return int
*/
- public int getSysKey() {
- return sysKey;
+ public ItemPath getItemPath() {
+ return itemPath;
}
/**
@@ -155,9 +157,18 @@ public class Viewpoint implements C2KLocalObject { * Sets the sysKey.
* @param sysKey The sysKey to set
*/
- public void setSysKey(int sysKey) {
- this.sysKey = sysKey;
+ public void setItemPath(ItemPath itemPath) {
+ this.itemPath = itemPath;
}
+
+ public void setItemUUID( String uuid )
+ {
+ setItemPath(new ItemPath(UUID.fromString(uuid)));
+ }
+
+ public String getItemUUID() {
+ return getItemPath().getUUID().toString();
+ }
/**
* Method getEvent.
@@ -169,7 +180,7 @@ public class Viewpoint implements C2KLocalObject { if (eventId == NONE)
throw new InvalidDataException("No last eventId defined", "");
- return (Event)Gateway.getStorage().get(sysKey, ClusterStorage.HISTORY+"/"+eventId, null);
+ return (Event)Gateway.getStorage().get(itemPath, ClusterStorage.HISTORY+"/"+eventId, null);
}
@Override
|
