Package org.apache.openjpa.datacache
Class ConcurrentQueryCache
- java.lang.Object
-
- org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
-
- org.apache.openjpa.datacache.AbstractQueryCache
-
- org.apache.openjpa.datacache.ConcurrentQueryCache
-
- All Implemented Interfaces:
java.io.Serializable,QueryCache,TypesChangedListener,RemoteCommitListener,Configurable,Closeable,EventManager
public class ConcurrentQueryCache extends AbstractQueryCache implements RemoteCommitListener
AQueryCacheimplementation that is optimized for concurrent access. When the cache fill up, values to remove from the cache are chosen randomly. Due to race conditions, it is possible that a get call might not retur a cached instance if that instance is being transferred between internal datastructures.- Since:
- 0.4.1
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.openjpa.datacache.AbstractQueryCache
AbstractQueryCache.Default<T>, AbstractQueryCache.EvictPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_lru-
Fields inherited from class org.apache.openjpa.datacache.AbstractQueryCache
conf, entityTimestampMap, evictPolicy, log
-
Fields inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
_listeners
-
-
Constructor Summary
Constructors Constructor Description ConcurrentQueryCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclearInternal()Clear the cache.CacheMapgetCacheMap()Returns the underlyingCacheMapthat this cache is using.intgetCacheSize()Returns the maximum number of unpinned objects to keep hard references to.AbstractQueryCache.EvictPolicygetEvictPolicy()Returns the eviction policy of the query cacheprotected QueryResultgetInternal(QueryKey qk)Return the list for the given key.booleangetLru()intgetSoftReferenceSize()Returns the maximum number of unpinned objects to keep soft references to.voidinitialize(DataCacheManager mgr)Initialize any resources associated with the givenDataCacheManager.protected java.util.CollectionkeySet()Return a threadsafe view of the keys in this cache.protected CacheMapnewCacheMap()Return the map to use as an internal cache.protected booleanpinInternal(QueryKey qk)Pin an object to the cache.protected QueryResultputInternal(QueryKey qk, QueryResult result)Add the given result to the cache, returning the old result under the given key.protected QueryResultremoveInternal(QueryKey qk)Remove the result under the given key from the cache.voidsetCacheSize(int size)Sets the maximum number of unpinned objects to keep hard references to.voidsetLru(boolean l)voidsetSoftReferenceSize(int size)Sets the maximum number of unpinned objects to keep soft references to.protected booleanunpinInternal(QueryKey qk)Unpin an object from the cache.voidwriteLock()Obtain a write lock on the cache.voidwriteUnlock()Release the write lock on the cache.-
Methods inherited from class org.apache.openjpa.datacache.AbstractQueryCache
addTypesChangedListener, afterCommit, clear, close, close, count, endConfiguration, fireEvent, get, getAllEntityTimestamp, getEnableStatistics, getName, getStatistics, isClosed, newListenerCollection, onTypesChanged, pin, put, remove, removeAllInternal, removeTypesChangedListener, setConfiguration, setEnableStatistics, setEvictPolicy, setName, startConfiguration, unpin, updateEntityTimestamp
-
Methods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, removeListener, setFailFast
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.openjpa.event.RemoteCommitListener
afterCommit, close
-
-
-
-
Method Detail
-
getCacheMap
public CacheMap getCacheMap()
Returns the underlyingCacheMapthat this cache is using. This is not an unmodifiable view on the map, so care should be taken with this reference. Implementations should probably not modify the contents of the cache, but should only use this reference to obtain cache metrics. Additionally, this map may contain expired data. Removal of timed-out data is done in a lazy fashion, so the actual size of the map may be greater than the number of non-expired query results in cache.
-
getCacheSize
public int getCacheSize()
Returns the maximum number of unpinned objects to keep hard references to.
-
setCacheSize
public void setCacheSize(int size)
Sets the maximum number of unpinned objects to keep hard references to. If the map contains more unpinned objects thansize, then this method will result in the cache flushing old values.
-
getSoftReferenceSize
public int getSoftReferenceSize()
Returns the maximum number of unpinned objects to keep soft references to. Defaults to-1.
-
setSoftReferenceSize
public void setSoftReferenceSize(int size)
Sets the maximum number of unpinned objects to keep soft references to. If the map contains more soft references thansize, then this method will result in the cache flushing values.
-
initialize
public void initialize(DataCacheManager mgr)
Description copied from interface:QueryCacheInitialize any resources associated with the givenDataCacheManager.- Specified by:
initializein interfaceQueryCache- Overrides:
initializein classAbstractQueryCache
-
writeLock
public void writeLock()
Description copied from interface:QueryCacheObtain a write lock on the cache.- Specified by:
writeLockin interfaceQueryCache
-
writeUnlock
public void writeUnlock()
Description copied from interface:QueryCacheRelease the write lock on the cache.- Specified by:
writeUnlockin interfaceQueryCache
-
newCacheMap
protected CacheMap newCacheMap()
Return the map to use as an internal cache.
-
getInternal
protected QueryResult getInternal(QueryKey qk)
Description copied from class:AbstractQueryCacheReturn the list for the given key.- Specified by:
getInternalin classAbstractQueryCache
-
putInternal
protected QueryResult putInternal(QueryKey qk, QueryResult result)
Description copied from class:AbstractQueryCacheAdd the given result to the cache, returning the old result under the given key.- Specified by:
putInternalin classAbstractQueryCache
-
removeInternal
protected QueryResult removeInternal(QueryKey qk)
Description copied from class:AbstractQueryCacheRemove the result under the given key from the cache.- Specified by:
removeInternalin classAbstractQueryCache
-
clearInternal
protected void clearInternal()
Description copied from class:AbstractQueryCacheClear the cache.- Specified by:
clearInternalin classAbstractQueryCache
-
pinInternal
protected boolean pinInternal(QueryKey qk)
Description copied from class:AbstractQueryCachePin an object to the cache.- Specified by:
pinInternalin classAbstractQueryCache
-
unpinInternal
protected boolean unpinInternal(QueryKey qk)
Description copied from class:AbstractQueryCacheUnpin an object from the cache.- Specified by:
unpinInternalin classAbstractQueryCache
-
keySet
protected java.util.Collection keySet()
Description copied from class:AbstractQueryCacheReturn a threadsafe view of the keys in this cache. This collection must be iterable without risk of concurrent modification exceptions. It does not have to implement contains() efficiently or use set semantics.- Specified by:
keySetin classAbstractQueryCache
-
getEvictPolicy
public AbstractQueryCache.EvictPolicy getEvictPolicy()
Returns the eviction policy of the query cache- Overrides:
getEvictPolicyin classAbstractQueryCache- Returns:
- -- returns a String value of evictPolicy attribute
-
setLru
public void setLru(boolean l)
-
getLru
public boolean getLru()
-
-