Package org.infinispan.expiration.impl
Class ExpirationManagerImpl<K,V>
- java.lang.Object
-
- org.infinispan.expiration.impl.ExpirationManagerImpl<K,V>
-
- All Implemented Interfaces:
ExpirationManager<K,V>,InternalExpirationManager<K,V>
- Direct Known Subclasses:
ClusterExpirationManager
@ThreadSafe public class ExpirationManagerImpl<K,V> extends Object implements InternalExpirationManager<K,V>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.expiration.impl.InternalExpirationManager
InternalExpirationManager.ExpirationConsumer<T,U>
-
-
Field Summary
Fields Modifier and Type Field Description protected StringcacheNameprotected CacheNotifier<K,V>cacheNotifierprotected ComponentRef<CommandsFactory>cfprotected ComponentRef<InvocationContextFactory>cfRefprotected ComponentRegistrycomponentRegistryprotected Configurationconfigurationprotected ComponentRef<InternalDataContainer<K,V>>dataContainerprotected booleanenabledprotected ScheduledExecutorServiceexecutorprotected ScheduledFuture<?>expirationTaskprotected ConcurrentMap<K,CompletableFuture<Boolean>>expiringThis map is used for performance reasons.protected ComponentRef<AsyncInterceptorChain>invokerRefprotected KeyPartitionerkeyPartitionerprotected PersistenceManagerpersistenceManagerprotected org.infinispan.commons.time.TimeServicetimeService
-
Constructor Summary
Constructors Constructor Description ExpirationManagerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddInternalListener(InternalExpirationManager.ExpirationConsumer<K,V> consumer)Adds anInternalExpirationManager.ExpirationConsumerto be invoked when an entry is expired.protected CompletionStage<Boolean>checkExpiredMaxIdle(InternalCacheEntry entry, int segment)Response is whether the value should be treated as expired.CompletableFuture<Boolean>entryExpiredInMemory(InternalCacheEntry<K,V> entry, long currentTime, boolean hasLock)This should be invoked passing in an entry that is now expired.booleanentryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry, long currentTime)This method is very similar toInternalExpirationManager.entryExpiredInMemory(InternalCacheEntry, long, boolean)except that it does the bare minimum when an entry expired to guarantee if the entry is valid or not.voidhandleInMemoryExpiration(InternalCacheEntry<K,V> entry, long currentTime)This should be invoked passing in an entry that is now expired.CompletionStage<Void>handleInStoreExpirationInternal(K key)This is to be invoked when a store entry expires.CompletionStage<Void>handleInStoreExpirationInternal(MarshallableEntry<K,V> marshalledEntry)This is to be invoked when a store entry expires and the value and/or metadata is available to be used.CompletionStage<Boolean>handlePossibleExpiration(InternalCacheEntry<K,V> ice, int segment, boolean isWrite)Handles processing for an entry that may be expired.booleanisEnabled()voidprocessExpiration()Processes the expiration event queue.voidremoveInternalListener(Object listener)Removes a previous registeredInternalExpirationManager.ExpirationConsumer.voidstart()voidstop()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.expiration.ExpirationManager
registerWriteIncoming, unregisterWrite
-
Methods inherited from interface org.infinispan.expiration.impl.InternalExpirationManager
handleInStoreExpiration, handleInStoreExpiration
-
-
-
-
Field Detail
-
executor
protected ScheduledExecutorService executor
-
configuration
protected Configuration configuration
-
persistenceManager
protected PersistenceManager persistenceManager
-
dataContainer
protected ComponentRef<InternalDataContainer<K,V>> dataContainer
-
cacheNotifier
protected CacheNotifier<K,V> cacheNotifier
-
timeService
protected org.infinispan.commons.time.TimeService timeService
-
keyPartitioner
protected KeyPartitioner keyPartitioner
-
cf
protected ComponentRef<CommandsFactory> cf
-
invokerRef
protected ComponentRef<AsyncInterceptorChain> invokerRef
-
cfRef
protected ComponentRef<InvocationContextFactory> cfRef
-
componentRegistry
protected ComponentRegistry componentRegistry
-
enabled
protected boolean enabled
-
cacheName
protected String cacheName
-
expiring
protected ConcurrentMap<K,CompletableFuture<Boolean>> expiring
This map is used for performance reasons. Essentially when an expiration event should not be raised this map should be populated first. The main examples are if an expiration is about to occur for that key or the key will be removed or updated. In the latter case we don't want to send an expiration event and then a remove event when we could do just the removal.
-
expirationTask
protected ScheduledFuture<?> expirationTask
-
-
Method Detail
-
start
public void start()
-
processExpiration
public void processExpiration()
Description copied from interface:ExpirationManagerProcesses the expiration event queue.- Specified by:
processExpirationin interfaceExpirationManager<K,V>
-
isEnabled
public boolean isEnabled()
- Specified by:
isEnabledin interfaceExpirationManager<K,V>- Returns:
- true if expiration reaper thread is enabled, false otherwise
-
entryExpiredInMemory
public CompletableFuture<Boolean> entryExpiredInMemory(InternalCacheEntry<K,V> entry, long currentTime, boolean hasLock)
Description copied from interface:InternalExpirationManagerThis should be invoked passing in an entry that is now expired. This method may attempt to lock this key to preserve atomicity. This method should be invoked when an entry was read via get but found to be expired.This method returns true if the entry was removed due to expiration or false if the entry was not removed due to expiration
If hasLock is true, this method assumes that the caller has the lock for the key and it must allow the expiration to occur, ie. returned CompletableFuture has completed, before the lock is released. Failure to do so may cause inconsistency in data.
- Specified by:
entryExpiredInMemoryin interfaceInternalExpirationManager<K,V>- Parameters:
entry- the entry that has expiredcurrentTime- the current time when it expiredhasLock- if the expiration was found during a write operation- Returns:
- if this entry actually expired or not
-
entryExpiredInMemoryFromIteration
public boolean entryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry, long currentTime)
Description copied from interface:InternalExpirationManagerThis method is very similar toInternalExpirationManager.entryExpiredInMemory(InternalCacheEntry, long, boolean)except that it does the bare minimum when an entry expired to guarantee if the entry is valid or not. This is important to reduce time spent per entry when iterating. This method may not actually remove the entry and may just return immediately if it is safe to do so.- Specified by:
entryExpiredInMemoryFromIterationin interfaceInternalExpirationManager<K,V>- Parameters:
entry- the entry that has expiredcurrentTime- the current time when it expired- Returns:
- if this entry actually expired or not
-
handleInMemoryExpiration
public void handleInMemoryExpiration(InternalCacheEntry<K,V> entry, long currentTime)
Description copied from interface:ExpirationManagerThis should be invoked passing in an entry that is now expired. This method may attempt to lock this key to preserve atomicity.- Specified by:
handleInMemoryExpirationin interfaceExpirationManager<K,V>- Parameters:
entry- entry that is now expiredcurrentTime- the current time in milliseconds
-
handleInStoreExpirationInternal
public CompletionStage<Void> handleInStoreExpirationInternal(K key)
Description copied from interface:InternalExpirationManagerThis is to be invoked when a store entry expires. This method may attempt to lock this key to preserve atomicity.Note this method doesn't currently take a
InternalCacheEntryand this is due to a limitation in the cache store API. This may cause some values to be removed if they were updated at the same time.- Specified by:
handleInStoreExpirationInternalin interfaceInternalExpirationManager<K,V>- Parameters:
key- the key of the expired entry This method will be renamed to handleInStoreExpiration when the method can be removed fromExpirationManager
-
handleInStoreExpirationInternal
public CompletionStage<Void> handleInStoreExpirationInternal(MarshallableEntry<K,V> marshalledEntry)
Description copied from interface:InternalExpirationManagerThis is to be invoked when a store entry expires and the value and/or metadata is available to be used. This method is preferred overExpirationManager.handleInStoreExpiration(Object)as it allows for more specific expiration to possibly occur.- Specified by:
handleInStoreExpirationInternalin interfaceInternalExpirationManager<K,V>- Parameters:
marshalledEntry- the entry that can be unmarshalled as needed This method will be renamed to handleInStoreExpiration when the method can be removed fromExpirationManager
-
handlePossibleExpiration
public CompletionStage<Boolean> handlePossibleExpiration(InternalCacheEntry<K,V> ice, int segment, boolean isWrite)
Description copied from interface:InternalExpirationManagerHandles processing for an entry that may be expired. This will remove the entry if it is expired, otherwise may touch if it uses max idle.- Specified by:
handlePossibleExpirationin interfaceInternalExpirationManager<K,V>- Parameters:
ice- entry that may be expiredsegment- the segment of the entryisWrite- whether the command that saw the expired value was a write or not- Returns:
- a stage that will complete with
trueif the entry was expired andfalseotherwise
-
checkExpiredMaxIdle
protected CompletionStage<Boolean> checkExpiredMaxIdle(InternalCacheEntry entry, int segment)
Response is whether the value should be treated as expired. This is determined by if a value as able to be touched or not, that is if it couldn't be touched - we assumed expired (as it was removed in some way).- Parameters:
entry- the entry to check expiration and touchsegment- the segment the entry maps to- Returns:
- whether the entry was expired or not
-
stop
public void stop()
-
addInternalListener
public void addInternalListener(InternalExpirationManager.ExpirationConsumer<K,V> consumer)
Description copied from interface:InternalExpirationManagerAdds anInternalExpirationManager.ExpirationConsumerto be invoked when an entry is expired.It exposes the
PrivateMetadata- Specified by:
addInternalListenerin interfaceInternalExpirationManager<K,V>- Parameters:
consumer- The instance to invoke.
-
removeInternalListener
public void removeInternalListener(Object listener)
Description copied from interface:InternalExpirationManagerRemoves a previous registeredInternalExpirationManager.ExpirationConsumer.- Specified by:
removeInternalListenerin interfaceInternalExpirationManager<K,V>- Parameters:
listener- The instance to remove.
-
-