Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java Tue Dec 23 05:04:35 2014 @@ -18,40 +18,7 @@ *******************************************************************************/ package org.ofbiz.base.util.cache; -import java.io.IOException; -import java.io.NotSerializableException; -import java.io.Serializable; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -import jdbm.helper.FastIterator; -import jdbm.htree.HTree; - -import org.ofbiz.base.concurrent.ExecutionPool; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.ObjectType; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilObject; -import org.ofbiz.base.util.UtilValidate; - -import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; -import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder; -import com.googlecode.concurrentlinkedhashmap.EvictionListener; /** * Generalized caching utility. Provides a number of caching features: @@ -65,914 +32,19 @@ import com.googlecode.concurrentlinkedha * */ @SuppressWarnings("serial") -public class UtilCache<K, V> implements Serializable, EvictionListener<Object, CacheLine<V>> { +public class UtilCache<K, V> { public static final String module = UtilCache.class.getName(); - /** A static Map to keep track of all of the UtilCache instances. */ - private static final ConcurrentHashMap<String, UtilCache<?, ?>> utilCacheTable = new ConcurrentHashMap<String, UtilCache<?, ?>>(); - - /** An index number appended to utilCacheTable names when there are conflicts. */ - private final static ConcurrentHashMap<String, AtomicInteger> defaultIndices = new ConcurrentHashMap<String, AtomicInteger>(); - - /** The name of the UtilCache instance, is also the key for the instance in utilCacheTable. */ - private final String name; - - /** A count of the number of cache hits */ - protected AtomicLong hitCount = new AtomicLong(0); - - /** A count of the number of cache misses because it is not found in the cache */ - protected AtomicLong missCountNotFound = new AtomicLong(0); - /** A count of the number of cache misses because it expired */ - protected AtomicLong missCountExpired = new AtomicLong(0); - /** A count of the number of cache misses because it was cleared from the Soft Reference (ie garbage collection, etc) */ - protected AtomicLong missCountSoftRef = new AtomicLong(0); - - /** A count of the number of cache hits on removes */ - protected AtomicLong removeHitCount = new AtomicLong(0); - /** A count of the number of cache misses on removes */ - protected AtomicLong removeMissCount = new AtomicLong(0); - - /** 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 sizeLimit = 0; - protected int maxInMemory = 0; - - /** Specifies the amount of time since initial loading before an element will be reported as expired. - * If set to 0, elements will never expire. - */ - protected long expireTimeNanos = 0; - - /** Specifies whether or not to use soft references for this cache, defaults to false */ - protected boolean useSoftReference = false; - - /** Specifies whether or not to use file base stored for this cache, defaults to false */ - protected boolean useFileSystemStore = false; - private String fileStore = "runtime/data/utilcache"; - - /** The set of listeners to receive notifications when items are modified (either deliberately or because they were expired). */ - protected Set<CacheListener<K, V>> listeners = new CopyOnWriteArraySet<CacheListener<K, V>>(); - - protected transient HTree<Object, V> fileTable = null; - protected ConcurrentMap<Object, CacheLine<V>> memoryTable = null; - - protected JdbmRecordManager jdbmMgr; - - // weak ref on this - private static final ConcurrentMap<String, JdbmRecordManager> fileManagers = new ConcurrentHashMap<String, JdbmRecordManager>(); - - /** 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 sizeLimit, int maxInMemory, long expireTimeMillis, boolean useSoftReference, boolean useFileSystemStore, String propName, String... propNames) { - this.name = cacheName; - this.sizeLimit = sizeLimit; - this.maxInMemory = maxInMemory; - this.expireTimeNanos = TimeUnit.NANOSECONDS.convert(expireTimeMillis, TimeUnit.MILLISECONDS); - this.useSoftReference = useSoftReference; - this.useFileSystemStore = useFileSystemStore; - setPropertiesParams(propName); - setPropertiesParams(propNames); - int maxMemSize = this.maxInMemory; - if (maxMemSize == 0) maxMemSize = sizeLimit; - if (maxMemSize == 0) { - memoryTable = new ConcurrentHashMap<Object, CacheLine<V>>(); - } else { - memoryTable = new Builder<Object, CacheLine<V>>() - .maximumWeightedCapacity(maxMemSize) - .listener(this) - .build(); - } - if (this.useFileSystemStore) { - // create the manager the first time it is needed - jdbmMgr = fileManagers.get(fileStore); - if (jdbmMgr == null) { - Debug.logImportant("Creating file system cache store for cache with name: " + cacheName, module); - try { - String ofbizHome = System.getProperty("ofbiz.home"); - if (ofbizHome == null) { - Debug.logError("No ofbiz.home property set in environment", module); - } else { - jdbmMgr = new JdbmRecordManager(ofbizHome + "/" + fileStore); - } - } catch (IOException e) { - Debug.logError(e, "Error creating file system cache store for cache with name: " + cacheName, module); - } - fileManagers.putIfAbsent(fileStore, jdbmMgr); - } - jdbmMgr = fileManagers.get(fileStore); - if (jdbmMgr != null) { - try { - this.fileTable = HTree.createInstance(jdbmMgr); - jdbmMgr.setNamedObject(cacheName, this.fileTable.getRecid()); - jdbmMgr.commit(); - } catch (IOException e) { - Debug.logError(e, module); - } - } - } - } - - private static String getNextDefaultIndex(String cacheName) { - AtomicInteger curInd = defaultIndices.get(cacheName); - if (curInd == null) { - defaultIndices.putIfAbsent(cacheName, new AtomicInteger(0)); - curInd = defaultIndices.get(cacheName); - } - int i = curInd.getAndIncrement(); - return i == 0 ? "" : Integer.toString(i); - } - - public static String getPropertyParam(ResourceBundle res, String[] propNames, String parameter) { - try { - for (String propName : propNames) { - String key = propName.concat(".").concat(parameter); - if (res.containsKey(key)) { - try { - return res.getString(key); - } catch (MissingResourceException e) { - } - } - } - } catch (Exception e) { - Debug.logWarning(e, "Error getting " + parameter + " value from ResourceBundle for propNames: " + propNames, module); - } - return null; - } - - protected void setPropertiesParams(String cacheName) { - setPropertiesParams(new String[] {cacheName}); - } - - public void setPropertiesParams(String[] propNames) { - setPropertiesParams("cache", propNames); - } - - public void setPropertiesParams(String settingsResourceName, String[] propNames) { - ResourceBundle res = ResourceBundle.getBundle(settingsResourceName); - - if (res != null) { - String value = getPropertyParam(res, propNames, "maxSize"); - if (UtilValidate.isNotEmpty(value)) { - this.sizeLimit = Integer.parseInt(value); - } - value = getPropertyParam(res, propNames, "maxInMemory"); - if (UtilValidate.isNotEmpty(value)) { - this.maxInMemory = Integer.parseInt(value); - } - value = getPropertyParam(res, propNames, "expireTime"); - if (UtilValidate.isNotEmpty(value)) { - this.expireTimeNanos = TimeUnit.NANOSECONDS.convert(Long.parseLong(value), TimeUnit.MILLISECONDS); - } - value = getPropertyParam(res, propNames, "useSoftReference"); - if (value != null) { - useSoftReference = "true".equals(value); - } - value = getPropertyParam(res, propNames, "useFileSystemStore"); - if (value != null) { - useFileSystemStore = "true".equals(value); - } - value = getPropertyParam(res, new String[0], "cache.file.store"); - if (value != null) { - fileStore = value; - } - } - } - - private Object fromKey(Object key) { - return key == null ? ObjectType.NULL : key; - } - - @SuppressWarnings("unchecked") - private K toKey(Object key) { - return key == ObjectType.NULL ? null : (K) key; - } - - private void addAllFileTableKeys(Set<Object> keys) throws IOException { - FastIterator<Object> iter = fileTable.keys(); - Object key = null; - while ((key = iter.next()) != null) { - keys.add(key); - } - } - - public Object getCacheLineTable() { - throw new UnsupportedOperationException(); - } - - public boolean isEmpty() { - if (fileTable != null) { - try { - synchronized (this) { - return fileTable.keys().next() == null; - } - } catch (IOException e) { - Debug.logError(e, module); - return false; - } - } else { - return memoryTable.isEmpty(); - } - } - - /** Puts or loads the passed element into the cache - * @param key The key for the element, used to reference it in the hashtables and LRU linked list - * @param value The value of the element - */ - public V put(K key, V value) { - return putInternal(key, value, expireTimeNanos); - } - - public V putIfAbsent(K key, V value) { - return putIfAbsentInternal(key, value, expireTimeNanos); - } - - public V putIfAbsentAndGet(K key, V value) { - V cachedValue = putIfAbsent(key, value); - return (cachedValue != null? cachedValue: value); - } - - CacheLine<V> createSoftRefCacheLine(final Object key, V value, long loadTimeNanos, long expireTimeNanos) { - return tryRegister(loadTimeNanos, new SoftRefCacheLine<V>(value, loadTimeNanos, expireTimeNanos) { - @Override - CacheLine<V> changeLine(boolean useSoftReference, long expireTimeNanos) { - if (useSoftReference) { - if (differentExpireTime(expireTimeNanos)) { - return this; - } else { - return createSoftRefCacheLine(key, getValue(), loadTimeNanos, expireTimeNanos); - } - } else { - return createHardRefCacheLine(key, getValue(), loadTimeNanos, expireTimeNanos); - } - } - - @Override - void remove() { - removeInternal(key, this); - } - }); - } - - CacheLine<V> createHardRefCacheLine(final Object key, V value, long loadTimeNanos, long expireTimeNanos) { - return tryRegister(loadTimeNanos, new HardRefCacheLine<V>(value, loadTimeNanos, expireTimeNanos) { - @Override - CacheLine<V> changeLine(boolean useSoftReference, long expireTimeNanos) { - if (useSoftReference) { - return createSoftRefCacheLine(key, getValue(), loadTimeNanos, expireTimeNanos); - } else { - if (differentExpireTime(expireTimeNanos)) { - return this; - } else { - return createHardRefCacheLine(key, getValue(), loadTimeNanos, expireTimeNanos); - } - } - } - - @Override - void remove() { - removeInternal(key, this); - } - }); - } - - private CacheLine<V> tryRegister(long loadTimeNanos, CacheLine<V> line) { - if (loadTimeNanos > 0) { - ExecutionPool.addPulse(line); - } - return line; - } - - private CacheLine<V> createCacheLine(K key, V value, long expireTimeNanos) { - long loadTimeNanos = expireTimeNanos > 0 ? System.nanoTime() : 0; - if (useSoftReference) { - return createSoftRefCacheLine(key, value, loadTimeNanos, expireTimeNanos); - } else { - return createHardRefCacheLine(key, value, loadTimeNanos, expireTimeNanos); - } - } - private V cancel(CacheLine<V> line) { - // FIXME: this is a race condition, the item could expire - // between the time it is replaced, and it is cancelled - V oldValue = line.getValue(); - ExecutionPool.removePulse(line); - line.cancel(); - return oldValue; - } - - /** Puts or loads the passed element into the cache - * @param key The key for the element, used to reference it in the hashtables and LRU linked list - * @param value The value of the element - * @param expireTimeMillis how long to keep this key in the cache - */ - public V put(K key, V value, long expireTimeMillis) { - return putInternal(key, value, TimeUnit.NANOSECONDS.convert(expireTimeMillis, TimeUnit.MILLISECONDS)); - } - - public V putIfAbsent(K key, V value, long expireTimeMillis) { - return putIfAbsentInternal(key, value, TimeUnit.NANOSECONDS.convert(expireTimeMillis, TimeUnit.MILLISECONDS)); - } - - V putInternal(K key, V value, long expireTimeNanos) { - Object nulledKey = fromKey(key); - CacheLine<V> oldCacheLine = memoryTable.put(nulledKey, createCacheLine(key, value, expireTimeNanos)); - V oldValue = oldCacheLine == null ? null : cancel(oldCacheLine); - if (fileTable != null) { - try { - synchronized (this) { - if (oldValue == null) oldValue = fileTable.get(nulledKey); - fileTable.put(nulledKey, value); - jdbmMgr.commit(); - } - } catch (IOException e) { - Debug.logError(e, module); - } - } - if (oldValue == null) { - noteAddition(key, value); - return null; - } else { - noteUpdate(key, value, oldValue); - return oldValue; - } - } - - V putIfAbsentInternal(K key, V value, long expireTimeNanos) { - Object nulledKey = fromKey(key); - V oldValue; - if (fileTable != null) { - try { - synchronized (this) { - oldValue = fileTable.get(nulledKey); - if (oldValue == null) { - memoryTable.put(nulledKey, createCacheLine(key, value, expireTimeNanos)); - fileTable.put(nulledKey, value); - jdbmMgr.commit(); - } - } - } catch (IOException e) { - Debug.logError(e, module); - oldValue = null; - } - } else { - CacheLine<V> newCacheLine = createCacheLine(key, value, expireTimeNanos); - CacheLine<V> oldCacheLine = memoryTable.putIfAbsent(nulledKey, newCacheLine); - if (oldCacheLine == null) { - oldValue = null; - } else { - oldValue = oldCacheLine.getValue(); - cancel(newCacheLine); - } - } - if (oldValue == null) { - noteAddition(key, value); - return null; - } else { - return oldValue; - } - } - - /** Gets an element from the cache according to the specified key. - * @param key The key for the element, used to reference it in the hashtables and LRU linked list - * @return The value of the element specified by the key - */ - public V get(Object key) { - boolean countGet = true; - Object nulledKey = fromKey(key); - CacheLine<V> line = memoryTable.get(nulledKey); - if (line == null) { - if (fileTable != null) { - V value; - try { - synchronized (this) { - value = fileTable.get(nulledKey); - } - } catch (IOException e) { - Debug.logError(e, module); - value = null; - } - if (value == null) { - missCountNotFound.incrementAndGet(); - return null; - } else { - hitCount.incrementAndGet(); - } - memoryTable.put(nulledKey, createCacheLine(UtilGenerics.<K>cast(key), value, expireTimeNanos)); - return value; - } else { - missCountNotFound.incrementAndGet(); - } - } else { - if (countGet) hitCount.incrementAndGet(); - } - return line != null ? line.getValue() : null; - } - - public Collection<V> values() { - if (fileTable != null) { - List<V> values = new LinkedList<V>(); - try { - synchronized (this) { - FastIterator<V> iter = fileTable.values(); - V value = iter.next(); - while (value != null) { - values.add(value); - value = iter.next(); - } - } - } catch (IOException e) { - Debug.logError(e, module); - } - return values; - } else { - List<V> valuesList = new LinkedList<V>(); - for (CacheLine<V> line: memoryTable.values()) { - valuesList.add(line.getValue()); - } - return valuesList; - } - } - - private long findSizeInBytes(Object o) { - try { - if (o == null) { - if (Debug.infoOn()) Debug.logInfo("Found null object in cache: " + getName(), module); - return 0; - } - if (o instanceof Serializable) { - return UtilObject.getByteCount(o); - } else { - if (Debug.infoOn()) Debug.logInfo("Unable to compute memory size for non serializable object; returning 0 byte size for object of " + o.getClass(), module); - return 0; - } - } catch (NotSerializableException e) { - // this happens when we try to get the byte count for an object which itself is - // serializable, but fails to be serialized, such as a map holding unserializable objects - if (Debug.warningOn()) { - Debug.logWarning("NotSerializableException while computing memory size; returning 0 byte size for object of " + e.getMessage(), module); - } - return 0; - } catch (Exception e) { - Debug.logWarning(e, "Unable to compute memory size for object of " + o.getClass(), module); - return 0; - } - } - - public long getSizeInBytes() { - long totalSize = 0; - if (fileTable != null) { - try { - synchronized (this) { - FastIterator<V> iter = fileTable.values(); - V value = iter.next(); - while (value != null) { - totalSize += findSizeInBytes(value); - value = iter.next(); - } - } - } catch (IOException e) { - Debug.logError(e, module); - return 0; - } - } else { - for (CacheLine<V> line: memoryTable.values()) { - totalSize += findSizeInBytes(line.getValue()); - } - } - return totalSize; - } - - /** Removes an element from the cache according to the specified key - * @param key The key for the element, used to reference it in the hashtables and LRU linked list - * @return The value of the removed element specified by the key - */ - public V remove(Object key) { - return this.removeInternal(key, true); - } - - /** This is used for internal remove calls because we only want to count external calls */ - @SuppressWarnings("unchecked") - protected synchronized V removeInternal(Object key, boolean countRemove) { - if (key == null) { - if (Debug.verboseOn()) Debug.logVerbose("In UtilCache tried to remove with null key, using NullObject" + this.name, module); - } - Object nulledKey = fromKey(key); - CacheLine<V> oldCacheLine; - V oldValue; - if (fileTable != null) { - try { - synchronized (this) { - try { - oldValue = fileTable.get(nulledKey); - } catch (IOException e) { - oldValue = null; - throw e; - } - fileTable.remove(nulledKey); - jdbmMgr.commit(); - } - } catch (IOException e) { - oldValue = null; - Debug.logError(e, module); - } - oldCacheLine = memoryTable.remove(nulledKey); - } else { - oldCacheLine = memoryTable.remove(nulledKey); - oldValue = oldCacheLine != null ? oldCacheLine.getValue() : null; - } - if (oldCacheLine != null) { - cancel(oldCacheLine); - } - if (oldValue != null) { - noteRemoval((K) key, oldValue); - if (countRemove) removeHitCount.incrementAndGet(); - return oldValue; - } else { - if (countRemove) removeMissCount.incrementAndGet(); - return null; - } - } - - protected synchronized void removeInternal(Object key, CacheLine<V> existingCacheLine) { - Object nulledKey = fromKey(key); - cancel(existingCacheLine); - if (!memoryTable.remove(nulledKey, existingCacheLine)) { - return; - } - if (fileTable != null) { - try { - synchronized (this) { - fileTable.remove(nulledKey); - jdbmMgr.commit(); - } - } catch (IOException e) { - Debug.logError(e, module); - } - } - noteRemoval(UtilGenerics.<K>cast(key), existingCacheLine.getValue()); - } - - /** Removes all elements from this cache */ - public synchronized void erase() { - if (fileTable != null) { - // FIXME: erase from memory too - synchronized (this) { - Set<Object> keys = new HashSet<Object>(); - try { - addAllFileTableKeys(keys); - } catch (IOException e) { - Debug.logError(e, module); - } - for (Object key: keys) { - try { - V value = fileTable.get(key); - noteRemoval(toKey(key), value); - removeHitCount.incrementAndGet(); - fileTable.remove(key); - jdbmMgr.commit(); - } catch (IOException e) { - Debug.logError(e, module); - } - } - } - memoryTable.clear(); - } else { - Iterator<Map.Entry<Object, CacheLine<V>>> it = memoryTable.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry<Object, CacheLine<V>> entry = it.next(); - noteRemoval(toKey(entry.getKey()), entry.getValue().getValue()); - removeHitCount.incrementAndGet(); - it.remove(); - } - } - } - - public void clear() { - erase(); - clearCounters(); - } - - /** Removes all elements from this cache */ - public static void clearAllCaches() { - // We make a copy since clear may take time - for (UtilCache<?,?> cache : utilCacheTable.values()) { - cache.clear(); - } - } + private static final OFBizCacheManager cacheManager = new OFBizCacheManager("cache"); public static Set<String> getUtilCacheTableKeySet() { - Set<String> set = new HashSet<String>(utilCacheTable.size()); - set.addAll(utilCacheTable.keySet()); - return set; - } - - /** Getter for the name of the UtilCache instance. - * @return The name of the instance - */ - public String getName() { - return this.name; - } - - /** Returns the number of successful hits on the cache - * @return The number of successful cache hits - */ - public long getHitCount() { - return this.hitCount.get(); - } - - /** Returns the number of cache misses from entries that are not found in the cache - * @return The number of cache misses - */ - public long getMissCountNotFound() { - return this.missCountNotFound.get(); - } - - /** Returns the number of cache misses from entries that are expired - * @return The number of cache misses - */ - public long getMissCountExpired() { - return this.missCountExpired.get(); - } - - /** Returns the number of cache misses from entries that are have had the soft reference cleared out (by garbage collector and such) - * @return The number of cache misses - */ - public long getMissCountSoftRef() { - return this.missCountSoftRef.get(); - } - - /** Returns the number of cache misses caused by any reason - * @return The number of cache misses - */ - public long getMissCountTotal() { - return getMissCountSoftRef() + getMissCountNotFound() + getMissCountExpired(); - } - - public long getRemoveHitCount() { - return this.removeHitCount.get(); - } - - public long getRemoveMissCount() { - return this.removeMissCount.get(); - } - - /** Clears the hit and miss counters - */ - public void clearCounters() { - this.hitCount.set(0); - this.missCountNotFound.set(0); - this.missCountExpired.set(0); - this.missCountSoftRef.set(0); - this.removeHitCount.set(0); - this.removeMissCount.set(0); - } - - public void setMaxInMemory(int newInMemory) { - this.maxInMemory = newInMemory; - Map<Object, CacheLine<V>> oldmap = this.memoryTable; - - if (newInMemory > 0) { - if (this.memoryTable instanceof ConcurrentLinkedHashMap<?, ?>) { - ((ConcurrentLinkedHashMap<?, ?>) this.memoryTable).setCapacity(newInMemory); - return; - } else { - this.memoryTable =new Builder<Object, CacheLine<V>>() - .maximumWeightedCapacity(newInMemory) - .build(); - } - } else { - this.memoryTable = new ConcurrentHashMap<Object, CacheLine<V>>(); - } - - this.memoryTable.putAll(oldmap); - } - - public int getMaxInMemory() { - return maxInMemory; - } - - public void setSizeLimit(int newSizeLimit) { - this.sizeLimit = newSizeLimit; - } - - public int getSizeLimit() { - return sizeLimit; - } - - /** Sets the expire time for the cache elements. - * If 0, elements never expire. - * @param expireTimeMillis The expire time for the cache elements - */ - public void setExpireTime(long expireTimeMillis) { - // if expire time was <= 0 and is now greater, fill expire table now - if (expireTimeMillis > 0) { - this.expireTimeNanos = TimeUnit.NANOSECONDS.convert(expireTimeMillis, TimeUnit.MILLISECONDS); - for (Map.Entry<?, CacheLine<V>> entry: memoryTable.entrySet()) { - entry.setValue(entry.getValue().changeLine(useSoftReference, expireTimeNanos)); - } - } else { - this.expireTimeNanos = 0; - // if expire time was > 0 and is now <=, do nothing, just leave the load times in place, won't hurt anything... - } - } - - /** return the current expire time for the cache elements - * @return The expire time for the cache elements - */ - public long getExpireTime() { - return TimeUnit.MILLISECONDS.convert(expireTimeNanos, TimeUnit.NANOSECONDS); - } - - /** Set whether or not the cache lines should use a soft reference to the data */ - public void setUseSoftReference(boolean useSoftReference) { - if (this.useSoftReference != useSoftReference) { - this.useSoftReference = useSoftReference; - for (Map.Entry<?, CacheLine<V>> entry: memoryTable.entrySet()) { - entry.setValue(entry.getValue().changeLine(useSoftReference, expireTimeNanos)); - } - } - } - - /** Return whether or not the cache lines should use a soft reference to the data */ - public boolean getUseSoftReference() { - return this.useSoftReference; - } - - public boolean getUseFileSystemStore() { - return this.useFileSystemStore; - } - - /** Returns the number of elements currently in the cache - * @return The number of elements currently in the cache - */ - public int size() { - if (fileTable != null) { - int size = 0; - try { - synchronized (this) { - FastIterator<Object> iter = fileTable.keys(); - while (iter.next() != null) { - size++; - } - } - } catch (IOException e) { - Debug.logError(e, module); - } - return size; - } else { - return memoryTable.size(); - } - } - - /** Returns a boolean specifying whether or not an element with the specified key is in the cache. - * @param key The key for the element, used to reference it in the hashtables and LRU linked list - * @return True is the cache contains an element corresponding to the specified key, otherwise false - */ - public boolean containsKey(Object key) { - Object nulledKey = fromKey(key); - CacheLine<V> line = memoryTable.get(nulledKey); - if (line == null) { - if (fileTable != null) { - try { - synchronized (this) { - FastIterator<Object> iter = fileTable.keys(); - Object checkKey = null; - while ((checkKey = iter.next()) != null) { - if (nulledKey.equals(checkKey)) { - return true; - } - } - } - } catch (IOException e) { - Debug.logError(e, module); - } - } - return false; - } else { - return true; - } - } - - /** - * NOTE: this returns an unmodifiable copy of the keySet, so removing from here won't have an effect, - * and calling a remove while iterating through the set will not cause a concurrent modification exception. - * This behavior is necessary for now for the persisted cache feature. - */ - public Set<? extends K> getCacheLineKeys() { - // note that this must be a HashSet and not a FastSet in order to have a null value - Set<Object> keys; - - if (fileTable != null) { - keys = new HashSet<Object>(); - try { - synchronized (this) { - addAllFileTableKeys(keys); - } - } catch (IOException e) { - Debug.logError(e, module); - } - if (keys.remove(ObjectType.NULL)) { - keys.add(null); - } - } else { - if (memoryTable.containsKey(ObjectType.NULL)) { - keys = new HashSet<Object>(memoryTable.keySet()); - keys.remove(ObjectType.NULL); - keys.add(null); - } else { - keys = memoryTable.keySet(); - } - } - return Collections.unmodifiableSet(UtilGenerics.<Set<? extends K>>cast(keys)); - } - - public Collection<? extends CacheLine<V>> getCacheLineValues() { - throw new UnsupportedOperationException(); - } - - private Map<String, Object> createLineInfo(int keyNum, K key, CacheLine<V> line) { - Map<String, Object> lineInfo = new HashMap<String, Object>(); - lineInfo.put("elementKey", key); - - if (line.getLoadTimeNanos() > 0) { - lineInfo.put("expireTimeMillis", TimeUnit.MILLISECONDS.convert(line.getExpireTimeNanos() - System.nanoTime(), TimeUnit.NANOSECONDS)); - } - lineInfo.put("lineSize", findSizeInBytes(line.getValue())); - lineInfo.put("keyNum", keyNum); - return lineInfo; - } - - private Map<String, Object> createLineInfo(int keyNum, K key, V value) { - Map<String, Object> lineInfo = new HashMap<String, Object>(); - lineInfo.put("elementKey", key); - lineInfo.put("lineSize", findSizeInBytes(value)); - lineInfo.put("keyNum", keyNum); - return lineInfo; - } - - public Collection<? extends Map<String, Object>> getLineInfos() { - List<Map<String, Object>> lineInfos = new LinkedList<Map<String, Object>>(); - int keyIndex = 0; - for (K key: getCacheLineKeys()) { - Object nulledKey = fromKey(key); - if (fileTable != null) { - try { - synchronized (this) { - lineInfos.add(createLineInfo(keyIndex, key, fileTable.get(nulledKey))); - } - } catch (IOException e) { - Debug.logError(e, module); - } - } else { - CacheLine<V> line = memoryTable.get(nulledKey); - if (line != null) { - lineInfos.add(createLineInfo(keyIndex, key, line)); - } - } - keyIndex++; - } - return lineInfos; - } - - /** Send a key addition event to all registered listeners */ - protected void noteAddition(K key, V newValue) { - for (CacheListener<K, V> listener: listeners) { - listener.noteKeyAddition(this, key, newValue); - } - } - - /** Send a key removal event to all registered listeners */ - protected void noteRemoval(K key, V oldValue) { - for (CacheListener<K, V> listener: listeners) { - listener.noteKeyRemoval(this, key, oldValue); - } - } - - /** Send a key update event to all registered listeners */ - protected void noteUpdate(K key, V newValue, V oldValue) { - for (CacheListener<K, V> listener: listeners) { - listener.noteKeyUpdate(this, key, newValue, oldValue); - } - } - - /** Adds an event listener for key removals */ - public void addListener(CacheListener<K, V> listener) { - listeners.add(listener); - } - - /** Removes an event listener for key removals */ - public void removeListener(CacheListener<K, V> listener) { - listeners.remove(listener); + return cacheManager.getUtilCacheTableKeySet(); } /** Checks for a non-expired key in a specific cache */ public static boolean validKey(String cacheName, Object key) { - UtilCache<?, ?> cache = findCache(cacheName); + OFBizCache<?, ?> cache = findCache(cacheName); if (cache != null) { if (cache.containsKey(key)) return true; @@ -980,84 +52,57 @@ public class UtilCache<K, V> implements return false; } - public static void clearCachesThatStartWith(String startsWith) { - for (Map.Entry<String, UtilCache<?, ?>> entry: utilCacheTable.entrySet()) { - String name = entry.getKey(); - if (name.startsWith(startsWith)) { - UtilCache<?, ?> cache = entry.getValue(); - cache.clear(); - } - } + /** Removes all elements from this cache */ + public static void clearAllCaches() { + cacheManager.clearAllCaches(); } public static void clearCache(String cacheName) { - UtilCache<?, ?> cache = findCache(cacheName); - if (cache == null) return; - cache.clear(); + cacheManager.clearCache(cacheName); } - @SuppressWarnings("unchecked") - 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, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name, names); - utilCacheTable.putIfAbsent(name, newCache); - return (UtilCache<K, V>) utilCacheTable.get(name); + public static void clearCachesThatStartWith(String startsWith) { + cacheManager.clearCachesThatStartWith(startsWith); } - 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, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name, names)); + public static <K, V> OFBizCache<K, V> getOrCreateUtilCache(String name, int sizeLimit, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String... names) { + return cacheManager.getOrCreateUtilCache(name, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, names); } - 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, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, name)); + public static <K, V> OFBizCache<K, V> createUtilCache(String name, int sizeLimit, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore, String... names) { + return cacheManager.createUtilCache(name, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore, names); } - 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, sizeLimit, sizeLimit, expireTime, useSoftReference, false, name)); + public static <K, V> OFBizCache<K, V> createUtilCache(String name, int sizeLimit, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore) { + return cacheManager.createUtilCache(name, sizeLimit, maxInMemory, expireTime, useSoftReference, useFileSystemStore); } - 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, sizeLimit, sizeLimit, expireTime, false, false, name)); + public static <K,V> OFBizCache<K, V> createUtilCache(String name, int sizeLimit, long expireTime, boolean useSoftReference) { + return cacheManager.createUtilCache(name, sizeLimit, expireTime, useSoftReference); } - public static <K,V> UtilCache<K, V> createUtilCache(int sizeLimit, long expireTime) { - String cacheName = "specified" + getNextDefaultIndex("specified"); - return storeCache(new UtilCache<K, V>(cacheName, sizeLimit, sizeLimit, expireTime, false, false, "specified")); + public static <K,V> OFBizCache<K, V> createUtilCache(String name, int sizeLimit, long expireTime) { + return cacheManager.createUtilCache(name, sizeLimit, expireTime); } - public static <K,V> UtilCache<K, V> createUtilCache(String name, boolean useSoftReference) { - String cacheName = name + getNextDefaultIndex(name); - return storeCache(new UtilCache<K, V>(cacheName, 0, 0, 0, useSoftReference, false, "default", name)); + public static <K,V> OFBizCache<K, V> createUtilCache(int sizeLimit, long expireTime) { + return cacheManager.createUtilCache(sizeLimit, expireTime); } - public static <K,V> UtilCache<K, V> createUtilCache(String name) { - String cacheName = name + getNextDefaultIndex(name); - return storeCache(new UtilCache<K, V>(cacheName, 0, 0, 0, false, false, "default", name)); + public static <K,V> OFBizCache<K, V> createUtilCache(String name, boolean useSoftReference) { + return cacheManager.createUtilCache(name, useSoftReference); } - public static <K,V> UtilCache<K, V> createUtilCache() { - String cacheName = "default" + getNextDefaultIndex("default"); - return storeCache(new UtilCache<K, V>(cacheName, 0, 0, 0, false, false, "default")); + public static <K,V> OFBizCache<K, V> createUtilCache(String name) { + return cacheManager.createUtilCache(name); } - private static <K, V> UtilCache<K, V> storeCache(UtilCache<K, V> cache) { - utilCacheTable.put(cache.getName(), cache); - return cache; + public static <K,V> OFBizCache<K, V> createUtilCache() { + return cacheManager.createUtilCache(); } - @SuppressWarnings("unchecked") - public static <K, V> UtilCache<K, V> findCache(String cacheName) { - return (UtilCache<K, V>) UtilCache.utilCacheTable.get(cacheName); + public static <K, V> OFBizCache<K, V> findCache(String cacheName) { + return cacheManager.findCache(cacheName); } - @Override - public void onEviction(Object key, CacheLine<V> value) { - ExecutionPool.removePulse(value); - } } Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java Tue Dec 23 05:04:35 2014 @@ -32,6 +32,7 @@ import org.ofbiz.base.test.GenericTestCa import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilObject; import org.ofbiz.base.util.cache.CacheListener; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; @SuppressWarnings("serial") @@ -131,15 +132,15 @@ public class UtilCacheTests extends Gene changeSet.add(change); } - public synchronized void noteKeyRemoval(UtilCache<K, V> cache, K key, V oldValue) { + public synchronized void noteKeyRemoval(OFBizCache<K, V> cache, K key, V oldValue) { add(key, new Removal<V>(oldValue)); } - public synchronized void noteKeyAddition(UtilCache<K, V> cache, K key, V newValue) { + public synchronized void noteKeyAddition(OFBizCache<K, V> cache, K key, V newValue) { add(key, new Addition<V>(newValue)); } - public synchronized void noteKeyUpdate(UtilCache<K, V> cache, K key, V newValue, V oldValue) { + public synchronized void noteKeyUpdate(OFBizCache<K, V> cache, K key, V newValue, V oldValue) { add(key, new Update<V>(newValue, oldValue)); } @@ -150,7 +151,7 @@ public class UtilCacheTests extends Gene } } - private static <K, V> Listener<K, V> createListener(UtilCache<K, V> cache) { + private static <K, V> Listener<K, V> createListener(OFBizCache<K, V> cache) { Listener<K, V> listener = new Listener<K, V>(); cache.addListener(listener); return listener; @@ -160,11 +161,11 @@ public class UtilCacheTests extends Gene super(name); } - private <K, V> UtilCache<K, V> createUtilCache(int sizeLimit, int maxInMemory, long ttl, boolean useSoftReference, boolean useFileSystemStore) { + private <K, V> OFBizCache<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 sizeLimit, Integer maxInMemory, Long expireTime, Boolean useSoftReference, Boolean useFileSystemStore) { + private static <K, V> void assertUtilCacheSettings(OFBizCache<K, V> cache, Integer sizeLimit, Integer maxInMemory, Long expireTime, Boolean useSoftReference, Boolean useFileSystemStore) { if (sizeLimit != null) { assertEquals(cache.getName() + ":sizeLimit", sizeLimit.intValue(), cache.getSizeLimit()); } @@ -203,7 +204,7 @@ public class UtilCacheTests extends Gene assertUtilCacheSettings(UtilCache.createUtilCache(name, 12, 8, 22000, false, true, "c", "d"), 12, 8, 22000L, Boolean.FALSE, Boolean.TRUE); } - public static <K, V> void assertKey(String label, UtilCache<K, V> cache, K key, V value, V other, int size, Map<K, V> map) { + public static <K, V> void assertKey(String label, OFBizCache<K, V> cache, K key, V value, V other, int size, Map<K, V> map) { assertNull(label + ":get-empty", cache.get(key)); assertFalse(label + ":containsKey-empty", cache.containsKey(key)); V oldValue = cache.put(key, other); @@ -221,7 +222,7 @@ public class UtilCacheTests extends Gene assertEquals(label + ":map-values", map.values(), cache.values()); } - private static <K, V> void assertHasSingleKey(UtilCache<K, V> cache, K key, V value) { + private static <K, V> void assertHasSingleKey(OFBizCache<K, V> cache, K key, V value) { assertFalse("is-empty", cache.isEmpty()); assertEquals("size", 1, cache.size()); assertTrue("found", cache.containsKey(key)); @@ -232,7 +233,7 @@ public class UtilCacheTests extends Gene assertEquals("values", UtilMisc.toList(value), cache.values()); } - private static <K, V> void assertNoSingleKey(UtilCache<K, V> cache, K key) { + private static <K, V> void assertNoSingleKey(OFBizCache<K, V> cache, K key) { assertFalse("not-found", cache.containsKey(key)); assertFalse("validKey", UtilCache.validKey(cache.getName(), key)); assertNull("no-get", cache.get(key)); @@ -243,7 +244,7 @@ public class UtilCacheTests extends Gene assertEquals("values", Collections.emptyList(), cache.values()); } - private static void basicTest(UtilCache<String, String> cache) throws Exception { + private static void basicTest(OFBizCache<String, String> cache) throws Exception { Listener<String, String> gotListener = createListener(cache); Listener<String, String> wantedListener = new Listener<String, String>(); for (int i = 0; i < 2; i++) { @@ -317,17 +318,17 @@ public class UtilCacheTests extends Gene } public void testBasicDisk() throws Exception { - UtilCache<String, String> cache = createUtilCache(5, 0, 0, false, true); + OFBizCache<String, String> cache = createUtilCache(5, 0, 0, false, true); basicTest(cache); } public void testSimple() throws Exception { - UtilCache<String, String> cache = createUtilCache(5, 0, 0, false, false); + OFBizCache<String, String> cache = createUtilCache(5, 0, 0, false, false); basicTest(cache); } public void testPutIfAbsent() throws Exception { - UtilCache<String, String> cache = createUtilCache(5, 5, 2000, false, false); + OFBizCache<String, String> cache = createUtilCache(5, 5, 2000, false, false); Listener<String, String> gotListener = createListener(cache); Listener<String, String> wantedListener = new Listener<String, String>(); wantedListener.noteKeyAddition(cache, "two", "dos"); @@ -340,7 +341,7 @@ public class UtilCacheTests extends Gene } public void testPutIfAbsentAndGet() throws Exception { - UtilCache<String, String> cache = createUtilCache(5, 5, 2000, false, false); + OFBizCache<String, String> cache = createUtilCache(5, 5, 2000, false, false); Listener<String, String> gotListener = createListener(cache); Listener<String, String> wantedListener = new Listener<String, String>(); wantedListener.noteKeyAddition(cache, "key", "value"); @@ -366,7 +367,7 @@ public class UtilCacheTests extends Gene public void testChangeMemSize() throws Exception { int size = 5; long ttl = 2000; - UtilCache<String, Serializable> cache = createUtilCache(size, size, ttl, false, false); + OFBizCache<String, Serializable> cache = createUtilCache(size, size, ttl, false, false); Map<String, Serializable> map = new HashMap<String, Serializable>(); for (int i = 0; i < size; i++) { String s = Integer.toString(i); @@ -397,7 +398,7 @@ public class UtilCacheTests extends Gene assertEquals("map-values", map.values().size(), cache.values().size()); } - private void expireTest(UtilCache<String, Serializable> cache, int size, long ttl) throws Exception { + private void expireTest(OFBizCache<String, Serializable> cache, int size, long ttl) throws Exception { Map<String, Serializable> map = new HashMap<String, Serializable>(); for (int i = 0; i < size; i++) { String s = Integer.toString(i); @@ -420,7 +421,7 @@ public class UtilCacheTests extends Gene } public void testExpire() throws Exception { - UtilCache<String, Serializable> cache = createUtilCache(5, 5, 2000, false, false); + OFBizCache<String, Serializable> cache = createUtilCache(5, 5, 2000, false, false); expireTest(cache, 5, 2000); long start = System.currentTimeMillis(); useAllMemory(); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/collections/FlexibleMapAccessor.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/collections/FlexibleMapAccessor.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/collections/FlexibleMapAccessor.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/collections/FlexibleMapAccessor.java Tue Dec 23 05:04:35 2014 @@ -29,6 +29,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilObject; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.base.util.string.UelUtil; @@ -42,7 +43,7 @@ import org.ofbiz.base.util.string.UelUti @SuppressWarnings("serial") public final class FlexibleMapAccessor<T> implements Serializable, IsEmpty { public static final String module = FlexibleMapAccessor.class.getName(); - private static final UtilCache<String, FlexibleMapAccessor<?>> fmaCache = UtilCache.createUtilCache("flexibleMapAccessor.ExpressionCache"); + private static final OFBizCache<String, FlexibleMapAccessor<?>> fmaCache = UtilCache.createUtilCache("flexibleMapAccessor.ExpressionCache"); @SuppressWarnings("unchecked") private static final FlexibleMapAccessor nullFma = new FlexibleMapAccessor(""); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java Tue Dec 23 05:04:35 2014 @@ -38,6 +38,7 @@ import org.ofbiz.base.util.UtilFormatOut import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; /** Expands String values that contain Unified Expression Language (JSR 245) @@ -55,7 +56,7 @@ public abstract class FlexibleStringExpa public static final String module = FlexibleStringExpander.class.getName(); public static final String openBracket = "${"; public static final String closeBracket = "}"; - protected static final UtilCache<Key, FlexibleStringExpander> exprCache = UtilCache.createUtilCache("flexibleStringExpander.ExpressionCache"); + protected static final OFBizCache<Key, FlexibleStringExpander> exprCache = UtilCache.createUtilCache("flexibleStringExpander.ExpressionCache"); protected static final FlexibleStringExpander nullExpr = new ConstSimpleElem(new char[0]); /** Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/NodeELResolver.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/NodeELResolver.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/NodeELResolver.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/string/NodeELResolver.java Tue Dec 23 05:04:35 2014 @@ -35,6 +35,7 @@ import javax.xml.xpath.XPathFactory; import org.apache.xerces.dom.NodeImpl; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -51,7 +52,7 @@ import org.w3c.dom.NodeList; */ public class NodeELResolver extends ELResolver { private final XPath xpath; - private final UtilCache<String, XPathExpression> exprCache = UtilCache.createUtilCache("nodeElResolver.ExpressionCache"); + private final OFBizCache<String, XPathExpression> exprCache = UtilCache.createUtilCache("nodeElResolver.ExpressionCache"); private static final String module = NodeELResolver.class.getName(); /** Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java Tue Dec 23 05:04:35 2014 @@ -51,6 +51,7 @@ import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import freemarker.cache.TemplateLoader; @@ -79,7 +80,7 @@ public class FreeMarkerWorker { public static final Version version = new Version(2, 3, 21); // use soft references for this so that things from Content records don't kill all of our memory, or maybe not for performance reasons... hmmm, leave to config file... - private static final UtilCache<String, Template> cachedTemplates = UtilCache.createUtilCache("template.ftl.general", 0, 0, false); + private static final OFBizCache<String, Template> cachedTemplates = UtilCache.createUtilCache("template.ftl.general", 0, 0, false); private static final BeansWrapper defaultOfbizWrapper = new BeansWrapperBuilder(version).build(); private static final Configuration defaultOfbizConfig = makeConfiguration(defaultOfbizWrapper); @@ -328,7 +329,7 @@ public class FreeMarkerWorker { return getTemplate(templateLocation, cachedTemplates, defaultOfbizConfig); } - public static Template getTemplate(String templateLocation, UtilCache<String, Template> cache, Configuration config) throws TemplateException, IOException { + public static Template getTemplate(String templateLocation, OFBizCache<String, Template> cache, Configuration config) throws TemplateException, IOException { Template template = cache.get(templateLocation); if (template == null) { // only make the reader if we need it, and then close it right after! Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/XslTransform.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/XslTransform.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/XslTransform.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/base/src/org/ofbiz/base/util/template/XslTransform.java Tue Dec 23 05:04:35 2014 @@ -32,6 +32,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.URLConnector; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.base.location.FlexibleLocation; import org.ofbiz.base.util.GeneralException; @@ -56,7 +57,7 @@ import javax.xml.transform.stream.Stream public final class XslTransform { public static final String module = XslTransform.class.getName(); - private static final UtilCache<String, Templates> xslTemplatesCache = UtilCache.createUtilCache("XsltTemplates", 0, 0); + private static final OFBizCache<String, Templates> xslTemplatesCache = UtilCache.createUtilCache("XsltTemplates", 0, 0); /** * @param template the content or url of the xsl template Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/common/src/org/ofbiz/common/CommonEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/common/src/org/ofbiz/common/CommonEvents.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/common/src/org/ofbiz/common/CommonEvents.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/common/src/org/ofbiz/common/CommonEvents.java Tue Dec 23 05:04:35 2014 @@ -52,6 +52,7 @@ import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; @@ -81,7 +82,7 @@ public class CommonEvents { "thisRequestUri" }; - private static final UtilCache<String, Map<String, String>> appletSessions = UtilCache.createUtilCache("AppletSessions", 0, 600000, true); + private static final OFBizCache<String, Map<String, String>> appletSessions = UtilCache.createUtilCache("AppletSessions", 0, 600000, true); public static String checkAppletRequest(HttpServletRequest request, HttpServletResponse response) { Delegator delegator = (Delegator) request.getAttribute("delegator"); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java Tue Dec 23 05:04:35 2014 @@ -29,6 +29,7 @@ import java.util.Map; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -41,7 +42,7 @@ import org.w3c.dom.NodeList; public final class ModelDataFileReader { public static final String module = ModelDataFileReader.class.getName(); - private static final UtilCache<URL, ModelDataFileReader> readers = UtilCache.createUtilCache("ModelDataFile", true); + private static final OFBizCache<URL, ModelDataFileReader> readers = UtilCache.createUtilCache("ModelDataFile", true); public static ModelDataFileReader getModelDataFileReader(URL readerURL) throws DataFileException { ModelDataFileReader reader = readers.get(readerURL); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java Tue Dec 23 05:04:35 2014 @@ -18,6 +18,7 @@ *******************************************************************************/ package org.ofbiz.entity.cache; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.DelegatorFactory; @@ -70,11 +71,11 @@ public abstract class AbstractCache<K, V return names; } - protected UtilCache<K, V> getCache(String entityName) { + protected OFBizCache<K, V> getCache(String entityName) { return UtilCache.findCache(getCacheName(entityName)); } - protected UtilCache<K, V> getOrCreateCache(String entityName) { + protected OFBizCache<K, V> getOrCreateCache(String entityName) { String name = getCacheName(entityName); return UtilCache.getOrCreateUtilCache(name, 0, 0, 0, true, false, getCacheNames(entityName)); } Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java Tue Dec 23 05:04:35 2014 @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentMa import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericPK; @@ -75,7 +76,7 @@ public abstract class AbstractEntityCond } public void remove(String entityName, EntityCondition condition) { - UtilCache<EntityCondition, ConcurrentMap<K, V>> cache = getCache(entityName); + OFBizCache<EntityCondition, ConcurrentMap<K, V>> cache = getCache(entityName); if (cache == null) return; cache.remove(condition); } @@ -103,13 +104,13 @@ public abstract class AbstractEntityCond } protected ConcurrentMap<K, V> getConditionCache(String entityName, EntityCondition condition) { - UtilCache<EntityCondition, ConcurrentMap<K, V>> cache = getCache(entityName); + OFBizCache<EntityCondition, ConcurrentMap<K, V>> cache = getCache(entityName); if (cache == null) return null; return cache.get(getConditionKey(condition)); } protected Map<K, V> getOrCreateConditionCache(String entityName, EntityCondition condition) { - UtilCache<EntityCondition, ConcurrentMap<K, V>> utilCache = getOrCreateCache(entityName); + OFBizCache<EntityCondition, ConcurrentMap<K, V>> utilCache = getOrCreateCache(entityName); EntityCondition conditionKey = getConditionKey(condition); ConcurrentMap<K, V> conditionCache = utilCache.get(conditionKey); if (conditionCache == null) { @@ -182,7 +183,7 @@ public abstract class AbstractEntityCond } protected <T1 extends Map<String, Object>, T2 extends Map<String, Object>> void storeHook(String entityName, boolean isPK, List<T1> oldValues, List<T2> newValues) { - UtilCache<EntityCondition, Map<K, V>> entityCache = UtilCache.findCache(getCacheName(entityName)); + OFBizCache<EntityCondition, Map<K, V>> entityCache = UtilCache.findCache(getCacheName(entityName)); // for info about cache clearing if (UtilValidate.isEmpty(newValues) || newValues.get(0) == null) { //Debug.logInfo("In storeHook (cache clear) for entity name [" + entityName + "], got entity cache with name: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java Tue Dec 23 05:04:35 2014 @@ -21,6 +21,7 @@ package org.ofbiz.entity.cache; import java.util.Iterator; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericPK; import org.ofbiz.entity.GenericValue; @@ -35,7 +36,7 @@ public class EntityCache extends Abstrac } public GenericValue get(GenericPK pk) { - UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName()); + OFBizCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName()); if (entityCache == null) return null; return entityCache.get(pk); } @@ -57,12 +58,12 @@ public class EntityCache extends Abstrac // before going into the cache, make this value immutable entity.setImmutable(); } - UtilCache<GenericPK, GenericValue> entityCache = getOrCreateCache(pk.getEntityName()); + OFBizCache<GenericPK, GenericValue> entityCache = getOrCreateCache(pk.getEntityName()); return entityCache.put(pk, entity); } public void remove(String entityName, EntityCondition condition) { - UtilCache<GenericPK, GenericValue> entityCache = getCache(entityName); + OFBizCache<GenericPK, GenericValue> entityCache = getCache(entityName); if (entityCache == null) return; for (GenericPK pk: entityCache.getCacheLineKeys()) { GenericValue entity = entityCache.get(pk); @@ -76,7 +77,7 @@ public class EntityCache extends Abstrac } public GenericValue remove(GenericPK pk) { - UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName()); + OFBizCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName()); if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], will remove from this cache: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module); if (entityCache == null) return null; GenericValue retVal = entityCache.remove(pk); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelFieldTypeReader.java Tue Dec 23 05:04:35 2014 @@ -31,6 +31,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntityConfException; import org.ofbiz.entity.config.model.Datasource; @@ -47,7 +48,7 @@ import org.w3c.dom.Element; public class ModelFieldTypeReader implements Serializable { public static final String module = ModelFieldTypeReader.class.getName(); - protected static final UtilCache<String, ModelFieldTypeReader> readers = UtilCache.createUtilCache("entity.ModelFieldTypeReader", 0, 0); + protected static final OFBizCache<String, ModelFieldTypeReader> readers = UtilCache.createUtilCache("entity.ModelFieldTypeReader", 0, 0); protected static Map<String, ModelFieldType> createFieldTypeCache(Element docElement, String location) { docElement.normalize(); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java Tue Dec 23 05:04:35 2014 @@ -35,6 +35,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntityConfException; import org.ofbiz.entity.config.model.DelegatorElement; @@ -53,7 +54,7 @@ import org.w3c.dom.Node; public class ModelGroupReader implements Serializable { public static final String module = ModelGroupReader.class.getName(); - private static final UtilCache<String, ModelGroupReader> readers = UtilCache.createUtilCache("entity.ModelGroupReader", 0, 0); + private static final OFBizCache<String, ModelGroupReader> readers = UtilCache.createUtilCache("entity.ModelGroupReader", 0, 0); private Map<String, String> groupCache = null; private Set<String> groupNames = null; Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelReader.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelReader.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelReader.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entity/src/org/ofbiz/entity/model/ModelReader.java Tue Dec 23 05:04:35 2014 @@ -38,6 +38,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntityConfException; import org.ofbiz.entity.GenericEntityException; @@ -58,7 +59,7 @@ import org.w3c.dom.Node; public class ModelReader implements Serializable { public static final String module = ModelReader.class.getName(); - private static final UtilCache<String, ModelReader> readers = UtilCache.createUtilCache("entity.ModelReader", 0, 0); + private static final OFBizCache<String, ModelReader> readers = UtilCache.createUtilCache("entity.ModelReader", 0, 0); protected Map<String, ModelEntity> entityCache = null; Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java Tue Dec 23 05:04:35 2014 @@ -33,6 +33,7 @@ import org.ofbiz.base.config.MainResourc import org.ofbiz.base.config.ResourceHandler; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityConfException; @@ -49,7 +50,7 @@ public class EntityEcaUtil { public static final String module = EntityEcaUtil.class.getName(); - private static final UtilCache<String, Map<String, Map<String, List<EntityEcaRule>>>> entityEcaReaders = UtilCache.createUtilCache("entity.EcaReaders", 0, 0, false); + private static final OFBizCache<String, Map<String, Map<String, List<EntityEcaRule>>>> entityEcaReaders = UtilCache.createUtilCache("entity.EcaReaders", 0, 0, false); public static Map<String, Map<String, List<EntityEcaRule>>> getEntityEcaCache(String entityEcaReaderName) { Map<String, Map<String, List<EntityEcaRule>>> ecaCache = entityEcaReaders.get(entityEcaReaderName); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMapProcessor.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMapProcessor.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMapProcessor.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMapProcessor.java Tue Dec 23 05:04:35 2014 @@ -27,6 +27,7 @@ import java.util.Map; import org.ofbiz.base.location.FlexibleLocation; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.minilang.operation.MapProcessor; import org.w3c.dom.Document; @@ -37,8 +38,8 @@ import org.w3c.dom.Element; */ public class SimpleMapProcessor { - private static final UtilCache<String, Map<String, MapProcessor>> simpleMapProcessorsResourceCache = UtilCache.createUtilCache("minilang.SimpleMapProcessorsResource", 0, 0); - private static final UtilCache<URL, Map<String, MapProcessor>> simpleMapProcessorsURLCache = UtilCache.createUtilCache("minilang.SimpleMapProcessorsURL", 0, 0); + private static final OFBizCache<String, Map<String, MapProcessor>> simpleMapProcessorsResourceCache = UtilCache.createUtilCache("minilang.SimpleMapProcessorsResource", 0, 0); + private static final OFBizCache<URL, Map<String, MapProcessor>> simpleMapProcessorsURLCache = UtilCache.createUtilCache("minilang.SimpleMapProcessorsURL", 0, 0); protected static Map<String, MapProcessor> getAllProcessors(URL xmlURL) throws MiniLangException { Map<String, MapProcessor> mapProcessors = new HashMap<String, MapProcessor>(); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Tue Dec 23 05:04:35 2014 @@ -43,6 +43,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericValue; @@ -84,8 +85,8 @@ public final class SimpleMethod extends private static final String err_resource = "MiniLangErrorUiLabels"; private static final String[] DEPRECATED_ATTRIBUTES = {"parameter-map-name", "locale-name", "delegator-name", "security-name", "dispatcher-name", "user-login-name"}; private static final Map<String, MethodOperation.Factory<MethodOperation>> methodOperationFactories; - private static final UtilCache<String, Map<String, SimpleMethod>> simpleMethodsDirectCache = UtilCache.createUtilCache("minilang.SimpleMethodsDirect", 0, 0); - private static final UtilCache<String, SimpleMethod> simpleMethodsResourceCache = UtilCache.createUtilCache("minilang.SimpleMethodsResource", 0, 0); + private static final OFBizCache<String, Map<String, SimpleMethod>> simpleMethodsDirectCache = UtilCache.createUtilCache("minilang.SimpleMethodsDirect", 0, 0); + private static final OFBizCache<String, SimpleMethod> simpleMethodsResourceCache = UtilCache.createUtilCache("minilang.SimpleMethodsResource", 0, 0); static { Map<String, MethodOperation.Factory<MethodOperation>> mapFactories = new HashMap<String, MethodOperation.Factory<MethodOperation>>(); Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/security/src/org/ofbiz/security/SecurityFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/security/src/org/ofbiz/security/SecurityFactory.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/security/src/org/ofbiz/security/SecurityFactory.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/security/src/org/ofbiz/security/SecurityFactory.java Tue Dec 23 05:04:35 2014 @@ -30,6 +30,7 @@ import javax.servlet.http.HttpSession; import org.ofbiz.base.util.Assert; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; @@ -50,7 +51,7 @@ public final class SecurityFactory { // The default implementation stores a Delegator reference, so we will cache by delegator name. // The goal is to remove Delegator references in the Security interface, then we can use a singleton // and eliminate the cache. - private static final UtilCache<String, Security> authorizationCache = UtilCache.createUtilCache("security.AuthorizationCache"); + private static final OFBizCache<String, Security> authorizationCache = UtilCache.createUtilCache("security.AuthorizationCache"); /** * Returns a <code>Security</code> instance. The method uses Java's Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/ServiceDispatcher.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Tue Dec 23 05:04:35 2014 @@ -41,6 +41,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.DelegatorFactory; @@ -82,7 +83,7 @@ public class ServiceDispatcher { public static final int lruLogSize = 200; public static final int LOCK_RETRIES = 3; - private static final UtilCache<String, Map<String, ModelService>> modelServiceMapByModel = UtilCache.createUtilCache("service.ModelServiceMapByModel", 0, 0, false); + private static final OFBizCache<String, Map<String, ModelService>> modelServiceMapByModel = UtilCache.createUtilCache("service.ModelServiceMapByModel", 0, 0, false); protected static final Map<RunningService, ServiceDispatcher> runLog = new ConcurrentLinkedHashMap.Builder<RunningService, ServiceDispatcher>().maximumWeightedCapacity(lruLogSize).build(); protected static ConcurrentHashMap<String, ServiceDispatcher> dispatchers = new ConcurrentHashMap<String, ServiceDispatcher>(); // FIXME: These fields are not thread-safe. They are modified by EntityDataLoadContainer. Modified: ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java?rev=1647483&r1=1647482&r2=1647483&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java (original) +++ ofbiz/branches/OFBIZ-4098-make-cache-pluggable/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java Tue Dec 23 05:04:35 2014 @@ -27,6 +27,7 @@ import org.ofbiz.base.util.Assert; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilURL; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.OFBizCache; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.service.config.model.Engine; import org.ofbiz.service.config.model.ServiceConfig; @@ -49,7 +50,7 @@ public final class ServiceConfigUtil { public static final String engine = "default"; public static final String SERVICE_ENGINE_XML_FILENAME = "serviceengine.xml"; // Keep the ServiceConfig instance in a cache - so the configuration can be reloaded at run-time. There will be only one ServiceConfig instance in the cache. - private static final UtilCache<String, ServiceConfig> serviceConfigCache = UtilCache.createUtilCache("service.ServiceConfig", 0, 0, false); + private static final OFBizCache<String, ServiceConfig> serviceConfigCache = UtilCache.createUtilCache("service.ServiceConfig", 0, 0, false); private static final List<ServiceConfigListener> configListeners = new CopyOnWriteArrayList<ServiceConfigListener>(); /** |
Free forum by Nabble | Edit this page |