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>
-
-
Field Summary
Fields Modifier and Type Field Description protected String
cacheName
protected CacheNotifier<K,V>
cacheNotifier
protected Configuration
configuration
protected InternalDataContainer<K,V>
dataContainer
protected boolean
enabled
protected ScheduledExecutorService
executor
protected ScheduledFuture<?>
expirationTask
protected ConcurrentMap<K,Object>
expiring
This map is used for performance reasons.protected PersistenceManager
persistenceManager
protected TimeService
timeService
-
Constructor Summary
Constructors Constructor Description ExpirationManagerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Boolean>
entryExpiredInMemory(InternalCacheEntry<K,V> entry, long currentTime)
This should be invoked passing in an entry that is now expired.CompletableFuture<Boolean>
entryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry, long currentTime)
This method is very similar toInternalExpirationManager.entryExpiredInMemory(InternalCacheEntry, long)
except that it does the bare minimum when an entry expired to guarantee if the entry is valid or not.void
handleInMemoryExpiration(InternalCacheEntry<K,V> entry, long currentTime)
This should be invoked passing in an entry that is now expired.void
handleInStoreExpiration(K key)
This is to be invoked when a store entry expires.void
handleInStoreExpiration(MarshalledEntry<K,V> marshalledEntry)
This is to be invoked when a store entry expires and the value and/or metadata is available to be used.boolean
isEnabled()
protected Long
localLastAccess(Object key, Object value, int segment)
void
processExpiration()
Processes the expiration event queue.CompletableFuture<Long>
retrieveLastAccess(Object key, Object value, int segment)
Retrieves the last access time for the given key in the data container if it is using max idle.void
start()
void
stop()
-
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
-
-
-
-
Field Detail
-
executor
protected ScheduledExecutorService executor
-
configuration
protected Configuration configuration
-
persistenceManager
protected PersistenceManager persistenceManager
-
dataContainer
protected InternalDataContainer<K,V> dataContainer
-
cacheNotifier
protected CacheNotifier<K,V> cacheNotifier
-
timeService
protected TimeService timeService
-
enabled
protected boolean enabled
-
cacheName
protected String cacheName
-
expiring
protected ConcurrentMap<K,Object> 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:ExpirationManager
Processes the expiration event queue.- Specified by:
processExpiration
in interfaceExpirationManager<K,V>
-
isEnabled
public boolean isEnabled()
- Specified by:
isEnabled
in interfaceExpirationManager<K,V>
- Returns:
- true if expiration reaper thread is enabled, false otherwise
-
entryExpiredInMemory
public CompletableFuture<Boolean> entryExpiredInMemory(InternalCacheEntry<K,V> entry, long currentTime)
Description copied from interface:InternalExpirationManager
This 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
- Specified by:
entryExpiredInMemory
in interfaceInternalExpirationManager<K,V>
- Parameters:
entry
- the entry that has expiredcurrentTime
- the current time when it expired- Returns:
- if this entry actually expired or not
-
entryExpiredInMemoryFromIteration
public CompletableFuture<Boolean> entryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry, long currentTime)
Description copied from interface:InternalExpirationManager
This method is very similar toInternalExpirationManager.entryExpiredInMemory(InternalCacheEntry, long)
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:
entryExpiredInMemoryFromIteration
in 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:ExpirationManager
This should be invoked passing in an entry that is now expired. This method may attempt to lock this key to preserve atomicity.- Specified by:
handleInMemoryExpiration
in interfaceExpirationManager<K,V>
- Parameters:
entry
- entry that is now expiredcurrentTime
- the current time in milliseconds
-
handleInStoreExpiration
public void handleInStoreExpiration(K key)
Description copied from interface:InternalExpirationManager
This 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
InternalCacheEntry
and 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:
handleInStoreExpiration
in interfaceExpirationManager<K,V>
- Specified by:
handleInStoreExpiration
in interfaceInternalExpirationManager<K,V>
- Parameters:
key
- the key of the expired entry
-
handleInStoreExpiration
public void handleInStoreExpiration(MarshalledEntry<K,V> marshalledEntry)
Description copied from interface:InternalExpirationManager
This 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:
handleInStoreExpiration
in interfaceExpirationManager<K,V>
- Specified by:
handleInStoreExpiration
in interfaceInternalExpirationManager<K,V>
- Parameters:
marshalledEntry
- the entry that can be unmarshalled as needed
-
retrieveLastAccess
public CompletableFuture<Long> retrieveLastAccess(Object key, Object value, int segment)
Description copied from interface:InternalExpirationManager
Retrieves the last access time for the given key in the data container if it is using max idle. If the entry is not in the container or it is expired it will return null. If the entry is present but cannot expire via max idle, it will return -1 If the entry is present and can expire via max idle but hasn't it will return a number > 0- Specified by:
retrieveLastAccess
in interfaceExpirationManager<K,V>
- Specified by:
retrieveLastAccess
in interfaceInternalExpirationManager<K,V>
- Parameters:
key
- the key to retrieve the access time forvalue
- the value to match if desired (this can be null)segment
- the segment for the given key- Returns:
- the last access time if available
-
stop
public void stop()
-
-