From 45e0e3988f5efd6463727d3510022f3cbaa8170a Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 14 Apr 2014 14:54:57 +0200 Subject: getClusterContents fixed for subtrees. Still has problems. --- .../persistency/MemoryOnlyClusterStorage.java | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java b/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java index a895c32..4766d82 100644 --- a/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java +++ b/src/main/java/com/c2kernel/persistency/MemoryOnlyClusterStorage.java @@ -1,10 +1,12 @@ package com.c2kernel.persistency; import java.util.ArrayList; +import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.Map; import com.c2kernel.entity.C2KLocalObject; +import com.c2kernel.utils.Logger; public class MemoryOnlyClusterStorage extends ClusterStorage { @@ -96,18 +98,44 @@ public class MemoryOnlyClusterStorage extends ClusterStorage { Map sysKeyMemCache = memoryCache.get(sysKey); ArrayList result = new ArrayList(); if (sysKeyMemCache != null) { - if (path.endsWith("/")) + while (path.endsWith("/")) path = path.substring(0,path.length()-1); path = path+"/"; for (String thisPath : sysKeyMemCache.keySet()) { if (thisPath.startsWith(path)) { - int slash = path.indexOf('/'); - String suffix = slash>-1?path.substring(slash+1):path; + String end = thisPath.substring(path.length()); + int slash = end.indexOf('/'); + String suffix = slash>-1?end.substring(0, slash):end; if (!result.contains(suffix)) result.add(suffix); } } } return result.toArray(new String[result.size()]); } - + + public void dumpContents(int sysKey) { + synchronized(memoryCache) { + Logger.msg(0, "Cached Objects of Entity "+sysKey); + Map sysKeyMemCache = memoryCache.get(sysKey); + if (sysKeyMemCache == null) { + Logger.msg(0, "No cache found"); + return; + } + try { + synchronized(sysKeyMemCache) { + for (Object name : sysKeyMemCache.keySet()) { + String path = (String) name; + try { + Logger.msg(0, " Path "+path+": "+sysKeyMemCache.get(path).getClass().getName()); + } catch (NullPointerException e) { + Logger.msg(0, " Path "+path+": reaped"); + } + } + } + } catch (ConcurrentModificationException ex) { + Logger.msg(0, "Cache modified - aborting"); + } + } + Logger.msg(0, "Total number of cached entities: "+memoryCache.size()); + } } -- cgit v1.2.3