Package org.apache.openjpa.datacache
Class ConcurrentDataCache
- java.lang.Object
-
- org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
-
- org.apache.openjpa.datacache.AbstractDataCache
-
- org.apache.openjpa.datacache.ConcurrentDataCache
-
- All Implemented Interfaces:
Serializable,DataCache,RemoteCommitListener,Configurable,Clearable,Closeable,EventManager
- Direct Known Subclasses:
PartitionedDataCache
public class ConcurrentDataCache extends AbstractDataCache implements RemoteCommitListener
ADataCacheimplementation that is optimized for concurrent access. When the cache fills up, values to remove from cache are chosen randomly. Due to race conditions, it is possible that a get call might not return a cached instance if that instance is being transferred between internal datastructures.- Since:
- 0.4.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_lru-
Fields inherited from class org.apache.openjpa.datacache.AbstractDataCache
_evictOnBulkUpdate, _excludedTypes, _includedTypes, _stats, conf, log
-
Fields inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
_listeners
-
Fields inherited from interface org.apache.openjpa.datacache.DataCache
NAME_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description ConcurrentDataCache()
-
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.protected DataCachePCDatagetInternal(Object key)Return the object for the given oid.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 CacheMapnewCacheMap()Return the map to use as an internal cache; entry expirations must invokeAbstractDataCache.keyRemoved(java.lang.Object, boolean).protected booleanpinInternal(Object key)Pin an object to the cache.protected DataCachePCDataputInternal(Object key, DataCachePCData pc)Add the given object to the cache, returning the old object under the given oid.protected booleanrecacheUpdates()Returntrueif updates to data already in the cache (either inAbstractDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)or theAbstractDataCache.update(org.apache.openjpa.datacache.DataCachePCData)) should be put back into the cache.protected voidremoveAllInternal(Class<?> cls, boolean subs)Evict objects in cache by class.protected DataCachePCDataremoveInternal(Object key)Remove the object under the given oid 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.voidunpinAll(Class<?> cls, boolean subs)Unpin all oids associaed with the given type from the cache.protected booleanunpinInternal(Object key)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.AbstractDataCache
addExpirationListener, afterCommit, clear, close, close, commit, contains, containsAll, endConfiguration, fireEvent, get, getAll, getEnableStatistics, getEvictionSchedule, getEvictOnBulkUpdate, getExcludedTypes, getName, getPartition, getPartitionNames, getStatistics, getTypes, isClosed, isPartitioned, keyRemoved, pin, pinAll, pinAll, put, putAllInternal, remove, removeAll, removeAll, removeAllInternal, removeAllTypeNamesInternal, removeExpirationListener, selectCache, setConfiguration, setEnableStatistics, setEvictionSchedule, setEvictOnBulkUpdate, setExcludedTypes, setExcludedTypes, setName, setTypes, setTypes, startConfiguration, toString, unpin, unpinAll, update
-
Methods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, newListenerCollection, removeListener, setFailFast
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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.
-
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.
-
getCacheSize
public int getCacheSize()
Returns the maximum number of unpinned objects to keep hard references to.
-
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.
-
getSoftReferenceSize
public int getSoftReferenceSize()
Returns the maximum number of unpinned objects to keep soft references to. Defaults to-1.
-
initialize
public void initialize(DataCacheManager mgr)
Description copied from interface:DataCacheInitialize any resources associated with the givenDataCacheManager.- Specified by:
initializein interfaceDataCache- Overrides:
initializein classAbstractDataCache
-
unpinAll
public void unpinAll(Class<?> cls, boolean subs)
Description copied from interface:DataCacheUnpin all oids associaed with the given type from the cache.- Specified by:
unpinAllin interfaceDataCache- Overrides:
unpinAllin classAbstractDataCachesubs- Whether to include subclasses.
-
writeLock
public void writeLock()
Description copied from interface:DataCacheObtain a write lock on the cache.
-
writeUnlock
public void writeUnlock()
Description copied from interface:DataCacheRelease the write lock on the cache.- Specified by:
writeUnlockin interfaceDataCache
-
newCacheMap
protected CacheMap newCacheMap()
Return the map to use as an internal cache; entry expirations must invokeAbstractDataCache.keyRemoved(java.lang.Object, boolean).
-
getInternal
protected DataCachePCData getInternal(Object key)
Description copied from class:AbstractDataCacheReturn the object for the given oid.- Specified by:
getInternalin classAbstractDataCache
-
putInternal
protected DataCachePCData putInternal(Object key, DataCachePCData pc)
Description copied from class:AbstractDataCacheAdd the given object to the cache, returning the old object under the given oid.- Specified by:
putInternalin classAbstractDataCache
-
removeInternal
protected DataCachePCData removeInternal(Object key)
Description copied from class:AbstractDataCacheRemove the object under the given oid from the cache.- Specified by:
removeInternalin classAbstractDataCache
-
removeAllInternal
protected void removeAllInternal(Class<?> cls, boolean subs)
Description copied from class:AbstractDataCacheEvict objects in cache by class.- Specified by:
removeAllInternalin classAbstractDataCache
-
clearInternal
protected void clearInternal()
Description copied from class:AbstractDataCacheClear the cache.- Specified by:
clearInternalin classAbstractDataCache
-
pinInternal
protected boolean pinInternal(Object key)
Description copied from class:AbstractDataCachePin an object to the cache.- Specified by:
pinInternalin classAbstractDataCache
-
unpinInternal
protected boolean unpinInternal(Object key)
Description copied from class:AbstractDataCacheUnpin an object from the cache.- Specified by:
unpinInternalin classAbstractDataCache
-
recacheUpdates
protected boolean recacheUpdates()
Description copied from class:AbstractDataCacheReturntrueif updates to data already in the cache (either inAbstractDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)or theAbstractDataCache.update(org.apache.openjpa.datacache.DataCachePCData)) should be put back into the cache. Returns false by default.- Overrides:
recacheUpdatesin classAbstractDataCache
-
setLru
public void setLru(boolean l)
-
getLru
public boolean getLru()
-
-