Author: doogie
Date: Thu Apr 1 04:31:37 2010 New Revision: 929813 URL: http://svn.apache.org/viewvc?rev=929813&view=rev Log: getMaxSize didn't actually do anything useful, and overlapped with getMaxInMemory. Deprecate getMaxSize(it continues to call setLru underneath everything), and provide a new getSizeLimit method. This latter method still does nothing, but at least it no longer overlaps. Also remove the maxSize parameter in webtools FindUtilCache page, instead displaying and altering the maxInMemory setting. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/UtilCacheEvents.java ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/EditUtilCache.groovy ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCache.groovy ofbiz/trunk/framework/webtools/webapp/webtools/cache/editUtilCache.ftl ofbiz/trunk/framework/webtools/webapp/webtools/cache/findUtilCache.ftl 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=929813&r1=929812&r2=929813&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:31:37 2010 @@ -84,7 +84,7 @@ public class UtilCache<K, V> implements /** The maximum number of elements in the cache. * If set to 0, there will be no limit on the number of elements in the cache. */ - protected int maxSize = 0; + protected int sizeLimit = 0; protected int maxInMemory = 0; /** Specifies the amount of time since initial loading before an element will be reported as expired. @@ -102,16 +102,16 @@ public class UtilCache<K, V> implements /** The set of listeners to receive notifcations when items are modidfied(either delibrately or because they were expired). */ protected Set<CacheListener<K, V>> listeners = new CopyOnWriteArraySet<CacheListener<K, V>>(); - /** Constructor which specifies the cacheName as well as the maxSize, expireTime and useSoftReference. - * The passed maxSize, expireTime and useSoftReference will be overridden by values from cache.properties if found. - * @param maxSize The maxSize member is set to this value + /** Constructor which specifies the cacheName as well as the sizeLimit, expireTime and useSoftReference. + * The passed sizeLimit, expireTime and useSoftReference will be overridden by values from cache.properties if found. + * @param sizeLimit The sizeLimit member is set to this value * @param expireTime The expireTime member is set to this value * @param cacheName The name of the cache. * @param useSoftReference Specifies whether or not to use soft references for this cache. */ - private UtilCache(String cacheName, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String propName, String... propNames) { + private UtilCache(String cacheName, int sizeLimit, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String propName, String... propNames) { this.name = cacheName; - this.maxSize = maxSize; + this.sizeLimit = sizeLimit; this.maxInMemory = maxInMemory; this.expireTime = expireTime; this.useSoftReference = useSoftReference; @@ -119,7 +119,7 @@ public class UtilCache<K, V> implements setPropertiesParams(propName); setPropertiesParams(propNames); int maxMemSize = this.maxInMemory; - if (maxMemSize == 0) maxMemSize = maxSize; + if (maxMemSize == 0) maxMemSize = sizeLimit; this.cacheLineTable = new CacheLineTable<K, V>(this.fileStore, this.name, this.useFileSystemStore, maxMemSize); } @@ -166,7 +166,7 @@ public class UtilCache<K, V> implements try { String value = getPropertyParam(res, propNames, "maxSize"); if (UtilValidate.isNotEmpty(value)) { - this.maxSize = Integer.parseInt(value); + this.sizeLimit = Integer.parseInt(value); } } catch (Exception e) { Debug.logWarning(e, "Error getting maxSize value from cache.properties file for propNames: " + propNames, module); @@ -438,23 +438,37 @@ public class UtilCache<K, V> implements /** Sets the maximum number of elements in the cache. * If 0, there is no maximum. * @param maxSize The maximum number of elements in the cache + * @deprecated Use setMaxInMemory */ public void setMaxSize(int maxSize) { - cacheLineTable.setLru(maxSize); - this.maxSize = maxSize; + setMaxInMemory(maxSize); } /** Returns the current maximum number of elements in the cache * @return The maximum number of elements in the cache + * @deprecated Use getMaxInMemory */ public int getMaxSize() { - return maxSize; + return getMaxInMemory(); + } + + public void setMaxInMemory(int newMaxInMemory) { + cacheLineTable.setLru(newMaxInMemory); + this.maxInMemory = newMaxInMemory; } public int getMaxInMemory() { return maxInMemory; } + public void setSizeLimit(int newSizeLimit) { + this.sizeLimit = sizeLimit; + } + + public int getSizeLimit() { + return sizeLimit; + } + /** Sets the expire time for the cache elements. * If 0, elements never expire. * @param expireTime The expire time for the cache elements @@ -629,11 +643,11 @@ public class UtilCache<K, V> implements } @SuppressWarnings("unchecked") - public static <K, V> UtilCache<K, V> getOrCreateUtilCache(String name, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String... names) { + public static <K, V> UtilCache<K, V> getOrCreateUtilCache(String name, int sizeLimit, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String... names) { UtilCache<K, V> existingCache = (UtilCache<K, V>) utilCacheTable.get(name); if (existingCache != null) return existingCache; String cacheName = name + getNextDefaultIndex(name); - UtilCache<K, V> newCache = new UtilCache<K, V>(cacheName, maxSize, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name, names); + UtilCache<K, V> newCache = new UtilCache<K, V>(cacheName, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name, names); UtilCache<K, V> oldCache = (UtilCache<K, V>) utilCacheTable.putIfAbsent(name, newCache); if (oldCache == null) { return newCache; @@ -642,29 +656,29 @@ public class UtilCache<K, V> implements } } - public static <K, V> UtilCache<K, V> createUtilCache(String name, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String... names) { + public static <K, V> UtilCache<K, V> createUtilCache(String name, int sizeLimit, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String... names) { String cacheName = name + getNextDefaultIndex(name); - return storeCache(new UtilCache<K, V>(cacheName, maxSize, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name, names)); + return storeCache(new UtilCache<K, V>(cacheName, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name, names)); } - public static <K, V> UtilCache<K, V> createUtilCache(String name, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore) { + public static <K, V> UtilCache<K, V> createUtilCache(String name, int sizeLimit, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore) { String cacheName = name + getNextDefaultIndex(name); - return storeCache(new UtilCache<K, V>(cacheName, maxSize, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name)); + return storeCache(new UtilCache<K, V>(cacheName, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name)); } - public static <K,V> UtilCache<K, V> createUtilCache(String name, int maxSize, long expireTime, boolean useSoftReference) { + public static <K,V> UtilCache<K, V> createUtilCache(String name, int sizeLimit, long expireTime, boolean useSoftReference) { String cacheName = name + getNextDefaultIndex(name); - return storeCache(new UtilCache<K, V>(cacheName, maxSize, maxSize, expireTime, useSoftReference, false, name)); + return storeCache(new UtilCache<K, V>(cacheName, sizeLimit, sizeLimit, expireTime, useSoftReference, false, name)); } - public static <K,V> UtilCache<K, V> createUtilCache(String name, int maxSize, long expireTime) { + public static <K,V> UtilCache<K, V> createUtilCache(String name, int sizeLimit, long expireTime) { String cacheName = name + getNextDefaultIndex(name); - return storeCache(new UtilCache<K, V>(cacheName, maxSize, maxSize, expireTime, false, false, name)); + return storeCache(new UtilCache<K, V>(cacheName, sizeLimit, sizeLimit, expireTime, false, false, name)); } - public static <K,V> UtilCache<K, V> createUtilCache(int maxSize, long expireTime) { + public static <K,V> UtilCache<K, V> createUtilCache(int sizeLimit, long expireTime) { String cacheName = "specified" + getNextDefaultIndex("specified"); - return storeCache(new UtilCache<K, V>(cacheName, maxSize, maxSize, expireTime, false, false, "specified")); + return storeCache(new UtilCache<K, V>(cacheName, sizeLimit, sizeLimit, expireTime, false, false, "specified")); } public static <K,V> UtilCache<K, V> createUtilCache(String name, boolean useSoftReference) { Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java?rev=929813&r1=929812&r2=929813&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java Thu Apr 1 04:31:37 2010 @@ -157,13 +157,13 @@ public class UtilCacheTests extends Gene super(name); } - private <K, V> UtilCache<K, V> createUtilCache(int maxSize, int maxInMemory, long ttl, boolean useSoftReference, boolean useFileSystemStore) { - return UtilCache.createUtilCache(getClass().getName() + "." + getName(), maxSize, maxInMemory, ttl, useSoftReference, useFileSystemStore); + private <K, V> UtilCache<K, V> createUtilCache(int sizeLimit, int maxInMemory, long ttl, boolean useSoftReference, boolean useFileSystemStore) { + return UtilCache.createUtilCache(getClass().getName() + "." + getName(), sizeLimit, maxInMemory, ttl, useSoftReference, useFileSystemStore); } - private static <K, V> void assertUtilCacheSettings(UtilCache<K, V> cache, Integer maxSize, Integer maxInMemory, Long expireTime, Boolean useSoftReference, Boolean useFileSystemStore) { - if (maxSize != null) { - assertEquals(cache.getName() + ":maxSize", maxSize.intValue(), cache.getMaxSize()); + private static <K, V> void assertUtilCacheSettings(UtilCache<K, V> cache, Integer sizeLimit, Integer maxInMemory, Long expireTime, Boolean useSoftReference, Boolean useFileSystemStore) { + if (sizeLimit != null) { + assertEquals(cache.getName() + ":sizeLimit", sizeLimit.intValue(), cache.getSizeLimit()); } if (maxInMemory != null) { assertEquals(cache.getName() + ":maxInMemory", maxInMemory.intValue(), cache.getMaxInMemory()); @@ -246,7 +246,7 @@ public class UtilCacheTests extends Gene for (int i = 0; i < 2; i++) { assertTrue("UtilCacheTable.keySet", UtilCache.getUtilCacheTableKeySet().contains(cache.getName())); assertSame("UtilCache.findCache", cache, UtilCache.findCache(cache.getName())); - assertSame("UtilCache.getOrCreateUtilCache", cache, UtilCache.getOrCreateUtilCache(cache.getName(), cache.getMaxSize(), cache.getMaxInMemory(), cache.getExpireTime(), cache.getUseSoftReference(), cache.getUseFileSystemStore())); + assertSame("UtilCache.getOrCreateUtilCache", cache, UtilCache.getOrCreateUtilCache(cache.getName(), cache.getSizeLimit(), cache.getMaxInMemory(), cache.getExpireTime(), cache.getUseSoftReference(), cache.getUseFileSystemStore())); assertNoSingleKey(cache, "one"); long origByteSize = cache.getSizeInBytes(); @@ -322,7 +322,7 @@ public class UtilCacheTests extends Gene basicTest(cache); } - public void testChangeSize() throws Exception { + public void testChangeMemSize() throws Exception { int size = 5; long ttl = 2000; UtilCache<String, Serializable> cache = createUtilCache(size, size, ttl, false, false); @@ -331,7 +331,7 @@ public class UtilCacheTests extends Gene String s = Integer.toString(i); assertKey(s, cache, s, new String(s), new String(":" + s), i + 1, map); } - cache.setMaxSize(2); + cache.setMaxInMemory(2); for (int i = 0; i < size - 2; i++) { String s = Integer.toString(i); map.remove(s); Modified: ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml?rev=929813&r1=929812&r2=929813&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml (original) +++ ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml Thu Apr 1 04:31:37 2010 @@ -2116,6 +2116,9 @@ <value xml:lang="th">à¸à¸à¸²à¸à¸ªà¸¹à¸à¸ªà¸¸à¸</value> <value xml:lang="zh">æ大大å°</value> </property> + <property key="WebtoolsMaxInMemory"> + <value xml:lang="en">Max In Memory</value> + </property> <property key="WebtoolsMemory"> <value xml:lang="de">Speicher</value> <value xml:lang="en">Memory</value> 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=929813&r1=929812&r2=929813&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:31:37 2010 @@ -79,7 +79,7 @@ public class UtilCacheEvents { if (utilCache != null) { Object key = null; - if (utilCache.getMaxSize() > 0) { + if (utilCache.getMaxInMemory() > 0) { try { key = utilCache.getCacheLineTable().getKeyFromMemory(number); } catch (Exception e) {} @@ -220,15 +220,15 @@ public class UtilCacheEvents { request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } - String maxSizeStr = request.getParameter("UTIL_CACHE_MAX_SIZE"); + String maxInMemoryStr = request.getParameter("UTIL_CACHE_MAX_IN_MEMORY"); String expireTimeStr = request.getParameter("UTIL_CACHE_EXPIRE_TIME"); String useSoftReferenceStr = request.getParameter("UTIL_CACHE_USE_SOFT_REFERENCE"); - Integer maxSize = null; + Integer maxInMemory = null; Long expireTime = null; try { - maxSize = Integer.valueOf(maxSizeStr); + maxInMemory = Integer.valueOf(maxInMemoryStr); } catch (Exception e) {} try { expireTime = Long.valueOf(expireTimeStr); @@ -237,8 +237,8 @@ public class UtilCacheEvents { UtilCache<?, ?> utilCache = UtilCache.findCache(name); if (utilCache != null) { - if (maxSize != null) - utilCache.setMaxSize(maxSize.intValue()); + if (maxInMemory != null) + utilCache.setMaxInMemory(maxInMemory.intValue()); if (expireTime != null) utilCache.setExpireTime(expireTime.longValue()); if (useSoftReferenceStr != null) { Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/EditUtilCache.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/EditUtilCache.groovy?rev=929813&r1=929812&r2=929813&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/EditUtilCache.groovy (original) +++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/EditUtilCache.groovy Thu Apr 1 04:31:37 2010 @@ -38,7 +38,7 @@ if (cacheName) { cache.missCountSoftRef = UtilFormatOut.formatQuantity(utilCache.getMissCountSoftRef()); cache.removeHitCount = UtilFormatOut.formatQuantity(utilCache.getRemoveHitCount()); cache.removeMissCount = UtilFormatOut.formatQuantity(utilCache.getRemoveMissCount()); - cache.maxSize = UtilFormatOut.formatQuantity(utilCache.getMaxSize()); + cache.maxInMemory = UtilFormatOut.formatQuantity(utilCache.getMaxInMemory()); cache.expireTime = UtilFormatOut.formatQuantity(utilCache.getExpireTime()); cache.useSoftReference = utilCache.getUseSoftReference().toString(); cache.useFileSystemStore = utilCache.getUseFileSystemStore().toString(); Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCache.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCache.groovy?rev=929813&r1=929812&r2=929813&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCache.groovy (original) +++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/cache/FindUtilCache.groovy Thu Apr 1 04:31:37 2010 @@ -43,7 +43,7 @@ names.each { cacheName -> cache.missCountSoftRef = UtilFormatOut.formatQuantity(utilCache.getMissCountSoftRef()); cache.removeHitCount = UtilFormatOut.formatQuantity(utilCache.getRemoveHitCount()); cache.removeMissCount = UtilFormatOut.formatQuantity(utilCache.getRemoveMissCount()); - cache.maxSize = UtilFormatOut.formatQuantity(utilCache.getMaxSize()); + cache.maxInMemory = UtilFormatOut.formatQuantity(utilCache.getMaxInMemory()); cache.expireTime = UtilFormatOut.formatQuantity(utilCache.getExpireTime()); cache.useSoftReference = utilCache.getUseSoftReference().toString(); cache.useFileSystemStore = utilCache.getUseFileSystemStore().toString(); Modified: ofbiz/trunk/framework/webtools/webapp/webtools/cache/editUtilCache.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/cache/editUtilCache.ftl?rev=929813&r1=929812&r2=929813&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/webapp/webtools/cache/editUtilCache.ftl (original) +++ ofbiz/trunk/framework/webtools/webapp/webtools/cache/editUtilCache.ftl Thu Apr 1 04:31:37 2010 @@ -74,9 +74,9 @@ under the License. <td colspan="2">${cache.removeMissCount?if_exists}</td> </tr> <tr> - <td class="label">${uiLabelMap.WebtoolsMaxSize}</td> - <td>${cache.maxSize?if_exists}</td> - <td><input type="text" size="15" maxlength="15" name="UTIL_CACHE_MAX_SIZE" value="${cache.maxSize?if_exists}"/></td> + <td class="label">${uiLabelMap.WebtoolsMaxInMemory}</td> + <td>${cache.maxInMemory?if_exists}</td> + <td><input type="text" size="15" maxlength="15" name="UTIL_CACHE_MAX_IN_MEMORY" value="${cache.maxInMemory?if_exists}"/></td> </tr> <tr> <td class="label">${uiLabelMap.WebtoolsExpireTime}</td> Modified: ofbiz/trunk/framework/webtools/webapp/webtools/cache/findUtilCache.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/cache/findUtilCache.ftl?rev=929813&r1=929812&r2=929813&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/webapp/webtools/cache/findUtilCache.ftl (original) +++ ofbiz/trunk/framework/webtools/webapp/webtools/cache/findUtilCache.ftl Thu Apr 1 04:31:37 2010 @@ -53,7 +53,7 @@ under the License. <td>${uiLabelMap.WebtoolsHits}</td> <td>${uiLabelMap.WebtoolsMisses}</td> <td>${uiLabelMap.WebtoolsRemoves}</td> - <td>${uiLabelMap.WebtoolsMaxSize}</td> + <td>${uiLabelMap.WebtoolsMaxInMemory}</td> <td>${uiLabelMap.WebtoolsExpireTime}</td> <td align="center">${uiLabelMap.WebtoolsUseSoftRef}</td> <td align="center">${uiLabelMap.WebtoolsUseFileStore}</td> @@ -67,7 +67,7 @@ under the License. <td>${cache.hitCount?if_exists}</td> <td>${cache.missCountTot?if_exists}/${cache.missCountNotFound?if_exists}/${cache.missCountExpired?if_exists}/${cache.missCountSoftRef?if_exists}</td> <td>${cache.removeHitCount?if_exists}/${cache.removeMissCount?if_exists}</td> - <td>${cache.maxSize?if_exists}</td> + <td>${cache.maxInMemory?if_exists}</td> <td>${cache.expireTime?if_exists}</td> <td align="center">${cache.useSoftReference?if_exists}</td> <td align="center">${cache.useFileSystemStore?if_exists}</td> |
Free forum by Nabble | Edit this page |