From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: Replaced int sysKey Item identifier with UUID, which is now portable. ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers. --- .../persistency/MemoryOnlyClusterStorage.java | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java') 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> memoryCache = new HashMap>(); + HashMap> memoryCache = new HashMap>(); /** * */ public MemoryOnlyClusterStorage() { - memoryCache = new HashMap>(); + memoryCache = new HashMap>(); } @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 sysKeyMemCache = memoryCache.get(sysKey); + Map 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 sysKeyMemCache; synchronized (memoryCache) { - if (memoryCache.containsKey(sysKey)) - sysKeyMemCache = memoryCache.get(sysKey); + if (memoryCache.containsKey(thisItem)) + sysKeyMemCache = memoryCache.get(thisItem); else { sysKeyMemCache = new HashMap(); - 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 sysKeyMemCache = memoryCache.get(sysKey); + Map 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 sysKeyMemCache = memoryCache.get(sysKey); + Map sysKeyMemCache = memoryCache.get(thisItem); ArrayList result = new ArrayList(); 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 sysKeyMemCache = memoryCache.get(sysKey); + Logger.msg(0, "Cached Objects of Entity "+thisItem); + Map sysKeyMemCache = memoryCache.get(thisItem); if (sysKeyMemCache == null) { Logger.msg(0, "No cache found"); return; -- cgit v1.2.3