public abstract class AbstractDataCache extends AbstractConcurrentEventManager implements DataCache, Configurable
DataCache
implementation that provides various
statistics, logging, and timeout functionality common across cache
implementations.Modifier and Type | Field and Description |
---|---|
protected boolean |
_evictOnBulkUpdate |
protected Set<String> |
_excludedTypes |
protected Set<String> |
_includedTypes |
protected CacheStatisticsSPI |
_stats |
protected OpenJPAConfiguration |
conf
The configuration set by the system.
|
protected Log |
log
The log to use.
|
_listeners
NAME_DEFAULT
Constructor and Description |
---|
AbstractDataCache() |
Modifier and Type | Method and Description |
---|---|
void |
addExpirationListener(ExpirationListener listen)
Add a new expiration event listener to this cache.
|
void |
afterCommit(RemoteCommitEvent event)
This method is part of the
RemoteCommitListener interface. |
void |
clear()
Remove all data from this cache.
|
protected abstract void |
clearInternal()
Clear the cache.
|
void |
close()
Free the resources used by this cache.
|
protected void |
close(boolean clear) |
void |
commit(Collection<DataCachePCData> additions,
Collection<DataCachePCData> newUpdates,
Collection<DataCachePCData> existingUpdates,
Collection<Object> deletes)
Perform a batch update of the cache.
|
boolean |
contains(Object key)
Returns
true if this cache contains data
corresponding to oid ; otherwise returns
false . |
BitSet |
containsAll(Collection<Object> keys)
Returns the indexes of the oids in this cache.
|
void |
endConfiguration()
Invoked upon completion of bean property configuration for this object.
|
protected void |
fireEvent(Object event,
Object listener)
Implement this method to fire the given event to the given listener.
|
DataCachePCData |
get(Object key)
Return the cached object for the given oid.
|
Map<Object,DataCachePCData> |
getAll(List<Object> keys)
Returns the objects for the given key List.
|
void |
getEnableStatistics() |
String |
getEvictionSchedule() |
boolean |
getEvictOnBulkUpdate()
Returns whether the the cache needs to be updated when bulk updates as executed.
|
Set<String> |
getExcludedTypes() |
protected abstract DataCachePCData |
getInternal(Object oid)
Return the object for the given oid.
|
String |
getName()
Returns a string name that can be used by end-user-visible
code to identify this cache.
|
DataCache |
getPartition(String name,
boolean create)
Gets the named partition.
|
Set<String> |
getPartitionNames()
Gets the name of the known partitions.
|
CacheStatistics |
getStatistics()
Returns number of read/write request and cache hit ratio data.
|
Set<String> |
getTypes() |
void |
initialize(DataCacheManager manager)
Initialize any resources associated with the given
DataCacheManager . |
boolean |
isClosed() |
boolean |
isPartitioned()
Affirms if this cache maintains partitions.
|
protected void |
keyRemoved(Object key,
boolean expired)
Invoke when a key is removed from this cache.
|
boolean |
pin(Object key)
Pin the value stored under
oid into the cache. |
void |
pinAll(Class<?> cls,
boolean subs)
Pin all oids for the given type.
|
BitSet |
pinAll(Collection<Object> keys)
Pin all oids to the cache.
|
protected abstract boolean |
pinInternal(Object oid)
Pin an object to the cache.
|
DataCachePCData |
put(DataCachePCData data)
Set the cached value for the given instance.
|
protected void |
putAllInternal(Collection<DataCachePCData> pcs)
Add all of the given objects to the cache.
|
protected abstract DataCachePCData |
putInternal(Object oid,
DataCachePCData pc)
Add the given object to the cache, returning the old object under the
given oid.
|
protected boolean |
recacheUpdates()
Return
true if updates to data already in the
cache (either in 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 the update(org.apache.openjpa.datacache.DataCachePCData) )
should be put back into the cache. |
DataCachePCData |
remove(Object key)
Remove the value stored under the given oid.
|
void |
removeAll(Class<?> cls,
boolean subClasses)
Remove the objects of the given class from the cache.
|
BitSet |
removeAll(Collection<Object> keys)
Remove the values stored under the given oids.
|
protected abstract void |
removeAllInternal(Class<?> cls,
boolean subclasses)
Evict objects in cache by class.
|
protected void |
removeAllInternal(Collection<Object> oids)
Remove all objects under the given oids from the cache.
|
protected void |
removeAllTypeNamesInternal(Collection<String> classNames)
Remove all objects of the given class names from the cache.
|
boolean |
removeExpirationListener(ExpirationListener listen)
Remove an expiration event listener from this cache.
|
protected abstract DataCachePCData |
removeInternal(Object oid)
Remove the object under the given oid from the cache.
|
DataCache |
selectCache(OpenJPAStateManager sm) |
void |
setConfiguration(Configuration conf)
Invoked prior to setting bean properties.
|
void |
setEnableStatistics(boolean enable) |
void |
setEvictionSchedule(String s) |
void |
setEvictOnBulkUpdate(boolean b) |
void |
setExcludedTypes(Set<String> types) |
void |
setExcludedTypes(String types) |
void |
setName(String name)
Sets a string name to be used to identify this cache to end-user needs.
|
void |
setTypes(Set<String> types) |
void |
setTypes(String types) |
void |
startConfiguration()
Invoked before bean property configuration is begun on this object.
|
String |
toString() |
boolean |
unpin(Object key)
Unpin the value stored under
oid from the cache. |
void |
unpinAll(Class<?> cls,
boolean subs)
Unpin all oids associaed with the given type from the cache.
|
BitSet |
unpinAll(Collection<Object> keys)
Unpin all oids from the cache.
|
protected abstract boolean |
unpinInternal(Object oid)
Unpin an object from the cache.
|
void |
update(DataCachePCData data)
Update the cached value for the given instance.
|
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, newListenerCollection, removeListener, setFailFast
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
writeLock, writeUnlock
protected CacheStatisticsSPI _stats
protected OpenJPAConfiguration conf
protected Log log
protected boolean _evictOnBulkUpdate
public String getName()
DataCache
public void setName(String name)
DataCache
public void setEnableStatistics(boolean enable)
public void getEnableStatistics()
public String getEvictionSchedule()
public void setEvictionSchedule(String s)
public void initialize(DataCacheManager manager)
DataCache
DataCacheManager
.initialize
in interface DataCache
public void commit(Collection<DataCachePCData> additions, Collection<DataCachePCData> newUpdates, Collection<DataCachePCData> existingUpdates, Collection<Object> deletes)
DataCache
DataCachePCData
objects in additions
and in
newUpdates
, make the appropriate modifications to
all DataCachePCDatas in existingUpdates
, and delete all
OIDs in deletes
.
All changes made to cached data must be made via this
method. It is this method that is responsible for performing
any side-effects that should happen on meaningful cache changes.
Implementations should bear in mind that the
deletes
collection may contain oids that are also
in the additions
map. This is possible because it
is valid for a user to delete an object with a particular oid
and then add that object in the same batch.commit
in interface DataCache
additions
- A collection of DataCachePCData
objects.
These represent data that have been newly created,
and thus must be added to the cache.newUpdates
- A collection of DataCachePCData
objects.
These represent data that have been modified but
were not originally in the cache, and thus must be added to the cache.existingUpdates
- A collection of DataCachePCData
objects.
These represent data that have been modified and
were originally loaded from the cache. It is
up to the cache implementation to decide if
these values must be re-enlisted in the cache.
Some caches may return live data from DataCache.get(java.lang.Object)
invocations, in which case these values need not be re-enlisted.deletes
- A collection of object IDs that have been deleted
and must therefore be dropped from the cache.public boolean contains(Object key)
DataCache
true
if this cache contains data
corresponding to oid
; otherwise returns
false
.public BitSet containsAll(Collection<Object> keys)
DataCache
containsAll
in interface DataCache
public DataCachePCData get(Object key)
DataCache
DataCache.update(org.apache.openjpa.datacache.DataCachePCData)
method should be used to re-cache any changed objects.public Map<Object,DataCachePCData> getAll(List<Object> keys)
public DataCachePCData put(DataCachePCData data)
DataCache
DataCache.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>)
method.put
in interface DataCache
null
if
the value was not previously cached. See Map.put(K, V)
for more information.public void update(DataCachePCData data)
DataCache
DataCache.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>)
method.
A cache implementation may or may not return a live object
from DataCache.get(java.lang.Object)
invocations. If an object retrieved from a
DataCache.get(java.lang.Object)
operation needs to be updated, this method can be
invoked instead of invoking DataCache.put(org.apache.openjpa.datacache.DataCachePCData)
. The DataCache implementation
can then make optimizations based on how its DataCache.get(java.lang.Object)
method works.public DataCachePCData remove(Object key)
DataCache
DataCache.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>)
method.remove
in interface DataCache
null
if
the oid was not previously cached. See Map.remove(java.lang.Object)
for more information.public BitSet removeAll(Collection<Object> keys)
DataCache
removeAll
in interface DataCache
DataCache.remove(java.lang.Object)
public void removeAll(Class<?> cls, boolean subClasses)
public boolean pin(Object key)
DataCache
oid
into the cache.
This method guarantees that oid
's value will not
be dropped by the caching algorithm. This method does not
affect the behavior of DataCache.remove(java.lang.Object)
.public BitSet pinAll(Collection<Object> keys)
DataCache
pinAll
in interface DataCache
DataCache.pin(java.lang.Object)
public void pinAll(Class<?> cls, boolean subs)
DataCache
public boolean unpin(Object key)
DataCache
oid
from the cache.
This method reverses a previous invocation of DataCache.pin(java.lang.Object)
.
This method does not remove anything from the cache; it merely
makes oid
's value a candidate for flushing from the cache.public BitSet unpinAll(Collection<Object> keys)
DataCache
unpinAll
in interface DataCache
DataCache.unpin(java.lang.Object)
public void unpinAll(Class<?> cls, boolean subs)
DataCache
public void clear()
DataCache
DataCache.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>)
method.public void close()
DataCache
protected void close(boolean clear)
public boolean isClosed()
public void addExpirationListener(ExpirationListener listen)
DataCache
addExpirationListener
in interface DataCache
public boolean removeExpirationListener(ExpirationListener listen)
DataCache
removeExpirationListener
in interface DataCache
public void afterCommit(RemoteCommitEvent event)
RemoteCommitListener
interface. If
your cache subclass relies on OpenJPA for clustering support, make it
implement RemoteCommitListener
. This method will take
care of invalidating entries from remote commits.protected void keyRemoved(Object key, boolean expired)
protected boolean recacheUpdates()
true
if updates to data already in the
cache (either in 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 the update(org.apache.openjpa.datacache.DataCachePCData)
)
should be put back into the cache. Returns false by default.protected abstract DataCachePCData getInternal(Object oid)
protected abstract DataCachePCData putInternal(Object oid, DataCachePCData pc)
protected void putAllInternal(Collection<DataCachePCData> pcs)
protected abstract DataCachePCData removeInternal(Object oid)
protected abstract void removeAllInternal(Class<?> cls, boolean subclasses)
protected void removeAllInternal(Collection<Object> oids)
protected void removeAllTypeNamesInternal(Collection<String> classNames)
protected abstract void clearInternal()
protected abstract boolean pinInternal(Object oid)
protected abstract boolean unpinInternal(Object oid)
public DataCache getPartition(String name, boolean create)
DataCache
getPartition
in interface DataCache
name
- name of the given partition.create
- if true optionally create a new partition.public Set<String> getPartitionNames()
DataCache
getPartitionNames
in interface DataCache
public boolean isPartitioned()
DataCache
isPartitioned
in interface DataCache
public CacheStatistics getStatistics()
DataCache
getStatistics
in interface DataCache
public void setConfiguration(Configuration conf)
Configurable
setConfiguration
in interface Configurable
public void startConfiguration()
Configurable
startConfiguration
in interface Configurable
public void endConfiguration()
Configurable
endConfiguration
in interface Configurable
protected void fireEvent(Object event, Object listener)
AbstractConcurrentEventManager
fireEvent
in class AbstractConcurrentEventManager
public void setTypes(String types)
public void setExcludedTypes(String types)
public DataCache selectCache(OpenJPAStateManager sm)
public boolean getEvictOnBulkUpdate()
DataCache
getEvictOnBulkUpdate
in interface DataCache
public void setEvictOnBulkUpdate(boolean b)
Copyright © 2006–2020 Apache Software Foundation. All rights reserved.