Author: doogie
Date: Thu Apr 1 04:46:14 2010 New Revision: 929837 URL: http://svn.apache.org/viewvc?rev=929837&view=rev Log: Add a feature to request CacheLine metadata as a simple list of maps. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/UtilCacheEvents.java ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCacheElements.groovy Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java?rev=929837&r1=929836&r2=929837&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java Thu Apr 1 04:46:14 2010 @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.Serializable; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -198,6 +199,42 @@ public class CacheLineTable<K, V> implem return Collections.unmodifiableCollection(values); } + private Map<String, Object> createLineInfo(int keyNum, K key, CacheLine<V> line) { + Map<String, Object> lineInfo = FastMap.newInstance(); + lineInfo.put("elementKey", key); + if (line.loadTime > 0) { + lineInfo.put("expireTime", new Date(line.loadTime + line.expireTime)); + } + lineInfo.put("lineSize", line.getSizeInBytes()); + lineInfo.put("keyNum", keyNum); + return lineInfo; + } + + public Collection<? extends Map<String, Object>> getLineInfos() { + Set<? extends K> keys = keySet(); + List<Map<String, Object>> lineInfos = FastList.newInstance(); + int keyIndex = 0; + for (K key: keySet()) { + Object nulledKey = fromKey(key); + CacheLine<V> line; + if (fileTable != null) { + try { + line = fileTable.get(nulledKey); + } catch (IOException e) { + Debug.logError(e, module); + line = null; + } + } else { + line = memoryTable.get(nulledKey); + } + if (line != null) { + lineInfos.add(createLineInfo(keyIndex, key, line)); + } + keyIndex++; + } + return lineInfos; + } + public synchronized Iterator<Map.Entry<K, ? extends CacheLine<V>>> iterator() { // this is a list, instead of a set, as the fileTable or // memoryTable has already deduped keys for us, and this ends up Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java?rev=929837&r1=929836&r2=929837&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java Thu Apr 1 04:46:14 2010 @@ -514,6 +514,10 @@ public class UtilCache<K, V> implements return cacheLineTable.values(); } + public Collection<? extends Map<String, Object>> getLineInfos() { + return cacheLineTable.getLineInfos(); + } + /** Returns a boolean specifying whether or not the element corresponding to the key has expired. * Only returns true if element is in cache and has expired. Error conditions return false, if no expireTable entry, returns true. * Always returns false if expireTime <= 0. Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/UtilCacheEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/UtilCacheEvents.java?rev=929837&r1=929836&r2=929837&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/UtilCacheEvents.java (original) +++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/UtilCacheEvents.java Thu Apr 1 04:46:14 2010 @@ -79,24 +79,18 @@ public class UtilCacheEvents { if (utilCache != null) { Object key = null; - if (utilCache.getMaxInMemory() > 0) { - try { - key = utilCache.getCacheLineTable().getKeyFromMemory(number); - } catch (Exception e) {} - } else { - // no LRU, try looping through the keySet to see if we find the specified index... - Iterator<?> ksIter = utilCache.getCacheLineTable().keySet().iterator(); - int curNum = 0; - - while (ksIter.hasNext()) { - if (number == curNum) { - key = ksIter.next(); - break; - } else { - ksIter.next(); - } - curNum++; + // no LRU, try looping through the keySet to see if we find the specified index... + Iterator<?> ksIter = utilCache.getCacheLineTable().keySet().iterator(); + int curNum = 0; + + while (ksIter.hasNext()) { + if (number == curNum) { + key = ksIter.next(); + break; + } else { + ksIter.next(); } + curNum++; } if (key != null) { Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCacheElements.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCacheElements.groovy?rev=929837&r1=929836&r2=929837&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCacheElements.groovy (original) +++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCacheElements.groovy Thu Apr 1 04:46:14 2010 @@ -33,25 +33,13 @@ cacheElementsList = []; if (cacheName) { utilCache = UtilCache.findCache(cacheName); if (utilCache) { - int keyNum = 0; - utilCache.getCacheLineTable().keySet().each { key -> - cacheElement = [:]; - line = utilCache.getCacheLineTable().get(key); - expireTime = ""; - if (line?.loadTime > 0) { - expireTime = (new Date(line.loadTime + utilCache.getExpireTime())).toString(); + cacheElementsList = utilCache.getLineInfos() + cacheElementsList.each { + if (it.expireTime != null) { + it.expireTime = it.expireTime.toString(); } - lineSize = line.getSizeInBytes(); - totalSize += lineSize; - - cacheElement.elementKey = key; - cacheElement.expireTime = expireTime; - cacheElement.lineSize = UtilFormatOut.formatQuantity(lineSize); - cacheElement.keyNum = keyNum; - - cacheElementsList.add(cacheElement); - - keyNum++; + totalSize += it.lineSize; + it.lineSize = UtilFormatOut.formatQuantity(it.lineSize); } } } |
Free forum by Nabble | Edit this page |