@ThreadSafe public class ExpirationManagerImpl<K,V> extends Object implements InternalExpirationManager<K,V>
InternalExpirationManager.ExpirationConsumer<T,U>
Modifier and Type | Field and Description |
---|---|
protected String |
cacheName |
protected CacheNotifier<K,V> |
cacheNotifier |
protected ComponentRef<CommandsFactory> |
cf |
protected ComponentRef<InvocationContextFactory> |
cfRef |
protected ComponentRegistry |
componentRegistry |
protected Configuration |
configuration |
protected ComponentRef<InternalDataContainer<K,V>> |
dataContainer |
protected boolean |
enabled |
protected ScheduledExecutorService |
executor |
protected ScheduledFuture<?> |
expirationTask |
protected ConcurrentMap<K,CompletableFuture<Boolean>> |
expiring
This map is used for performance reasons.
|
protected ComponentRef<AsyncInterceptorChain> |
invokerRef |
protected KeyPartitioner |
keyPartitioner |
protected PersistenceManager |
persistenceManager |
protected TimeService |
timeService |
Constructor and Description |
---|
ExpirationManagerImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addInternalListener(InternalExpirationManager.ExpirationConsumer<K,V> consumer)
Adds an
InternalExpirationManager.ExpirationConsumer to 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.
|
boolean |
entryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry,
long currentTime)
This method is very similar to
InternalExpirationManager.entryExpiredInMemory(InternalCacheEntry, long, boolean) 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.
|
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.
|
boolean |
isEnabled() |
void |
processExpiration()
Processes the expiration event queue.
|
void |
removeInternalListener(Object listener)
Removes a previous registered
InternalExpirationManager.ExpirationConsumer . |
void |
start() |
void |
stop() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handleInStoreExpiration, handleInStoreExpiration
registerWriteIncoming, unregisterWrite
protected ScheduledExecutorService executor
protected Configuration configuration
protected PersistenceManager persistenceManager
protected ComponentRef<InternalDataContainer<K,V>> dataContainer
protected CacheNotifier<K,V> cacheNotifier
protected TimeService timeService
protected KeyPartitioner keyPartitioner
protected ComponentRef<CommandsFactory> cf
protected ComponentRef<AsyncInterceptorChain> invokerRef
protected ComponentRef<InvocationContextFactory> cfRef
protected ComponentRegistry componentRegistry
protected boolean enabled
protected String cacheName
protected ConcurrentMap<K,CompletableFuture<Boolean>> expiring
protected ScheduledFuture<?> expirationTask
public void start()
public void processExpiration()
ExpirationManager
processExpiration
in interface ExpirationManager<K,V>
public boolean isEnabled()
isEnabled
in interface ExpirationManager<K,V>
public CompletableFuture<Boolean> entryExpiredInMemory(InternalCacheEntry<K,V> entry, long currentTime, boolean hasLock)
InternalExpirationManager
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.
entryExpiredInMemory
in interface InternalExpirationManager<K,V>
entry
- the entry that has expiredcurrentTime
- the current time when it expiredhasLock
- if the expiration was found during a write operationpublic boolean entryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry, long currentTime)
InternalExpirationManager
InternalExpirationManager.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.entryExpiredInMemoryFromIteration
in interface InternalExpirationManager<K,V>
entry
- the entry that has expiredcurrentTime
- the current time when it expiredpublic void handleInMemoryExpiration(InternalCacheEntry<K,V> entry, long currentTime)
ExpirationManager
handleInMemoryExpiration
in interface ExpirationManager<K,V>
entry
- entry that is now expiredcurrentTime
- the current time in millisecondspublic CompletionStage<Void> handleInStoreExpirationInternal(K key)
InternalExpirationManager
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.
handleInStoreExpirationInternal
in interface InternalExpirationManager<K,V>
key
- the key of the expired entry
This method will be renamed to handleInStoreExpiration when the method can be removed from ExpirationManager
public CompletionStage<Void> handleInStoreExpirationInternal(MarshallableEntry<K,V> marshalledEntry)
InternalExpirationManager
ExpirationManager.handleInStoreExpiration(Object)
as it allows for more
specific expiration to possibly occur.handleInStoreExpirationInternal
in interface InternalExpirationManager<K,V>
marshalledEntry
- the entry that can be unmarshalled as needed
This method will be renamed to handleInStoreExpiration when the method can be removed from ExpirationManager
public CompletionStage<Boolean> handlePossibleExpiration(InternalCacheEntry<K,V> ice, int segment, boolean isWrite)
InternalExpirationManager
handlePossibleExpiration
in interface InternalExpirationManager<K,V>
ice
- entry that may be expiredsegment
- the segment of the entryisWrite
- whether the command that saw the expired value was a write or nottrue
if the entry was expired and false
otherwiseprotected CompletionStage<Boolean> checkExpiredMaxIdle(InternalCacheEntry entry, int segment)
entry
- the entry to check expiration and touchsegment
- the segment the entry maps topublic void stop()
public void addInternalListener(InternalExpirationManager.ExpirationConsumer<K,V> consumer)
InternalExpirationManager
InternalExpirationManager.ExpirationConsumer
to be invoked when an entry is expired.
It exposes the PrivateMetadata
addInternalListener
in interface InternalExpirationManager<K,V>
consumer
- The instance to invoke.public void removeInternalListener(Object listener)
InternalExpirationManager
InternalExpirationManager.ExpirationConsumer
.removeInternalListener
in interface InternalExpirationManager<K,V>
listener
- The instance to remove.Copyright © 2021 JBoss by Red Hat. All rights reserved.