Package org.cache2k.core
Class EntryAction<K,V,R>
- java.lang.Object
-
- org.cache2k.core.EntryAction<K,V,R>
-
- All Implemented Interfaces:
Runnable
,EventListener
,AsyncCacheWriter.Callback
,Progress<K,V,R>
,org.cache2k.DataAware<K,V>
,org.cache2k.io.AsyncCacheLoader.Callback<V>
,org.cache2k.io.AsyncCacheLoader.Context<K,V>
public abstract class EntryAction<K,V,R> extends Object implements Runnable, org.cache2k.io.AsyncCacheLoader.Context<K,V>, org.cache2k.io.AsyncCacheLoader.Callback<V>, AsyncCacheWriter.Callback, Progress<K,V,R>
This is a method object to perform an operation on an entry.- Author:
- Jens Wilke
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EntryAction.AbortWhenProcessingException
static interface
EntryAction.CompletedCallback<K,V,R>
static class
EntryAction.ListenerException
-
Field Summary
Fields Modifier and Type Field Description static Entry
NON_FRESH_DUMMY
-
Constructor Summary
Constructors Constructor Description EntryAction(HeapCache<K,V> heapCache, InternalCache<K,V> userCache, Semantic<K,V,R> op, K k, Entry<K,V> e)
EntryAction(HeapCache<K,V> heapCache, InternalCache<K,V> internalCache, Semantic<K,V,R> op, K k, Entry<K,V> e, EntryAction.CompletedCallback<K,V,R> cb)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
abort()
Abort, but check whether entry was locked before.void
abortFinalize()
void
abortReleaseLock()
Release the lock.protected org.cache2k.io.AsyncCacheLoader<K,V>
asyncLoader()
void
callListeners()
void
checkExpiryBeforeMutation()
Check whether we are executed on an expired entry before the timer event for the expiry was received.void
checkKeepOrRemove()
In case we have an expiry of 0, this means that the entry should not be cached.void
completeProcessCallbacks()
Execute any callback or other actions waiting for this one to complete.void
continueWithMutation()
void
enqueueToExecute(EntryAction v)
Called on the processing action to enqueue another action to be executed next.protected org.cache2k.event.CacheEntryCreatedListener<K,V>[]
entryCreatedListeners()
Provide the registered listeners for entry creation.protected org.cache2k.event.CacheEntryExpiredListener<K,V>[]
entryExpiredListeners()
protected org.cache2k.event.CacheEntryRemovedListener<K,V>[]
entryRemovedListeners()
Provide the registered listeners for entry removal.void
entryResult(ExaminationEntry<K,V> e)
Returns a cache entry as result.protected org.cache2k.event.CacheEntryUpdatedListener<K,V>[]
entryUpdatedListeners()
Provide the registered listeners for entry update.void
examinationAbort(org.cache2k.CustomizationException t)
void
examine()
protected abstract Executor
executor()
void
existingEntryExpiredBeforeMutationSendExpiryEvents()
The entry logically expired before the mutation.void
expire(long expiryTime)
Reset expiry to the specified value.void
expiredAtEndOfOperationStartOver()
Entry expired during progress of the action, reentry at a previous processing state to call listeners and update heap.void
expiredImmediatelyAndRemove()
void
expiredImmediatelyKeepData()
void
expiryCalculated()
void
expiryCalculationException(Throwable t)
void
failure(RuntimeException t)
Failure call on Progress from Semantic.org.cache2k.Cache<K,V>
getCache()
User facing cache interface instance.org.cache2k.CacheEntry<K,V>
getCurrentEntry()
Returns the heap entry directly.Throwable
getException()
RuntimeException
getExceptionToPropagate()
Exception that might have happened during processing.Executor
getExecutor()
K
getKey()
Throwable
getLoaderException()
long
getMutationStartTime()
The current time in millis or the value when it was first called.R
getResult()
long
getStartTime()
protected boolean
hasFreshData()
Same asEntry.hasFreshData(TimeReference)
but keep time identically once checked to ensure timing based decisions do not change during the the processing.void
heapHit(Entry<K,V> e)
void
heapMiss()
boolean
isBulkMode()
boolean
isDataFresh()
Entry has valid data in the cache and is not expired.boolean
isDataFreshOrMiss()
Entry has valid data in the cache and is not expired.boolean
isDataRefreshing()
True if the entry is refreshing or refreshed and in refresh probation.boolean
isExpiryTimeReachedOrInRefreshProbation()
Entry reached the expiry time and expiry event can be sent and entry state can be changed to expired.boolean
isLoaderPresent()
A loader is present and the cache operates in read through.boolean
isRefreshAhead()
boolean
isResultAvailable()
If false, the result is not set.void
load()
Request that the entry value gets loaded from loader.void
loadAndExpiryCalculatedExamineAgain()
void
loadAndRestart()
Request a load, and then call examine again to reevaluate.void
loadCompleted()
protected org.cache2k.io.AdvancedCacheLoader<K,V>
loader()
Provide the cache loader, if present.protected CommonMetrics.Updater
metrics()
Provide the standard metrics for updating.protected boolean
mightHaveListeners()
True if there is any listener defined.void
mutationAbort(RuntimeException t)
void
mutationCalculateExpiry()
void
mutationCallWriter()
void
mutationDone()
void
mutationMayCallWriter()
Entry mutation, call writer if needed or skip tomutationMayStore()
void
mutationMayStore()
Entry mutation, call storage if neededvoid
mutationReleaseLockAndStartTimer()
Mutate the entry and start timer for expiry.void
noExpiryListenersPresent()
void
noMutation()
No mutation is done.void
onLoadFailure(Throwable t)
The load failed, resilience and refreshing needs to be triggeredvoid
onLoadSuccess(V v)
void
onWriteFailure(Throwable t)
void
onWriteSuccess()
void
put(V value)
Update the entry with the new value.void
putAndSetExpiry(V value, long expiryTime, long refreshTime)
Set new value, skip expiry calculation and set expiry time directly.void
ready()
void
reexamineAfterLock()
Entry state may have changed between the first examination and obtaining the entry lock.void
refresh()
Same as load but counting statistics as refresh.void
remove()
The entry will be removed.void
result(R r)
Sets the operation result.void
retrieveDataFromHeap()
void
reviveRefreshedEntry(long nrt)
void
run()
void
setBulkMode(boolean v)
void
skipHeapAccessEntryPresent()
void
skipStore()
void
skipWritingForException()
void
skipWritingNoWriter()
void
start()
Entry point to execute this action.protected abstract Timing<K,V>
timing()
void
updateDidNotTriggerDifferentMutationStoreLoadedValue()
void
updateMutationStatistics()
void
wantData()
Requests that the cache content for an entry will be provided.void
wantMutation()
The entry gets locked for mutation.boolean
wasLoaded()
Value was loaded before as part of this operation.protected org.cache2k.io.CacheWriter<K,V>
writer()
Provide the writer, default null.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cache2k.core.operation.Progress
getExceptionPropagator
-
-
-
-
Field Detail
-
NON_FRESH_DUMMY
public static final Entry NON_FRESH_DUMMY
-
-
Method Detail
-
enqueueToExecute
public void enqueueToExecute(EntryAction v)
Called on the processing action to enqueue another action to be executed next. Insert at the tail of the double linked list. We are not part of the list.
-
getExecutor
public Executor getExecutor()
-
executor
protected abstract Executor executor()
-
loader
protected org.cache2k.io.AdvancedCacheLoader<K,V> loader()
Provide the cache loader, if present.
-
metrics
protected CommonMetrics.Updater metrics()
Provide the standard metrics for updating.
-
mightHaveListeners
protected boolean mightHaveListeners()
True if there is any listener defined. Default false.
-
entryCreatedListeners
protected org.cache2k.event.CacheEntryCreatedListener<K,V>[] entryCreatedListeners()
Provide the registered listeners for entry creation.
-
entryUpdatedListeners
protected org.cache2k.event.CacheEntryUpdatedListener<K,V>[] entryUpdatedListeners()
Provide the registered listeners for entry update.
-
entryRemovedListeners
protected org.cache2k.event.CacheEntryRemovedListener<K,V>[] entryRemovedListeners()
Provide the registered listeners for entry removal.
-
entryExpiredListeners
protected org.cache2k.event.CacheEntryExpiredListener<K,V>[] entryExpiredListeners()
-
setBulkMode
public void setBulkMode(boolean v)
-
isBulkMode
public boolean isBulkMode()
-
getKey
public K getKey()
-
getStartTime
public long getStartTime()
-
isRefreshAhead
public boolean isRefreshAhead()
-
getMutationStartTime
public long getMutationStartTime()
Description copied from interface:Progress
The current time in millis or the value when it was first called.- Specified by:
getMutationStartTime
in interfaceProgress<K,V,R>
-
getCurrentEntry
public org.cache2k.CacheEntry<K,V> getCurrentEntry()
Returns the heap entry directly. This is only consistent while the entry is blocked for processing.
-
isLoaderPresent
public boolean isLoaderPresent()
Description copied from interface:Progress
A loader is present and the cache operates in read through.- Specified by:
isLoaderPresent
in interfaceProgress<K,V,R>
-
wasLoaded
public boolean wasLoaded()
Description copied from interface:Progress
Value was loaded before as part of this operation.
-
isDataFresh
public boolean isDataFresh()
Description copied from interface:Progress
Entry has valid data in the cache and is not expired. This is used for operations that do not want to access the value. If needed this will check the clock.- Specified by:
isDataFresh
in interfaceProgress<K,V,R>
-
hasFreshData
protected boolean hasFreshData()
Same asEntry.hasFreshData(TimeReference)
but keep time identically once checked to ensure timing based decisions do not change during the the processing.
-
isExpiryTimeReachedOrInRefreshProbation
public boolean isExpiryTimeReachedOrInRefreshProbation()
Description copied from interface:Progress
Entry reached the expiry time and expiry event can be sent and entry state can be changed to expired.- Specified by:
isExpiryTimeReachedOrInRefreshProbation
in interfaceProgress<K,V,R>
-
isDataRefreshing
public boolean isDataRefreshing()
Description copied from interface:Progress
True if the entry is refreshing or refreshed and in refresh probation.- Specified by:
isDataRefreshing
in interfaceProgress<K,V,R>
-
isDataFreshOrMiss
public boolean isDataFreshOrMiss()
Description copied from interface:Progress
Entry has valid data in the cache and is not expired. Counts a miss, if no entry is available, this is used for operations that do want to access the value.- Specified by:
isDataFreshOrMiss
in interfaceProgress<K,V,R>
-
start
public void start()
Entry point to execute this action.
-
wantData
public void wantData()
Description copied from interface:Progress
Requests that the cache content for an entry will be provided. If the cache is tiered, the data will be read into the heap cache. Last command of semantic method. Calls back onSemantic.examine(Object, Progress, ExaminationEntry)
-
retrieveDataFromHeap
public void retrieveDataFromHeap()
-
heapMiss
public void heapMiss()
-
skipHeapAccessEntryPresent
public void skipHeapAccessEntryPresent()
-
examine
public void examine()
-
noMutation
public void noMutation()
Description copied from interface:Progress
No mutation is done. Last command of semantic method.- Specified by:
noMutation
in interfaceProgress<K,V,R>
-
wantMutation
public void wantMutation()
Description copied from interface:Progress
The entry gets locked for mutation. Last command of semantic method. CallsSemantic.examine(Object, Progress, ExaminationEntry)
again after lock is obtain to assess the the state again. Calls back onSemantic.mutate(Object, Progress, ExaminationEntry)
if lock is already taken.- Specified by:
wantMutation
in interfaceProgress<K,V,R>
-
reexamineAfterLock
public void reexamineAfterLock()
Entry state may have changed between the first examination and obtaining the entry lock. Examine again.
-
checkExpiryBeforeMutation
public void checkExpiryBeforeMutation()
Check whether we are executed on an expired entry before the timer event for the expiry was received. In case expiry listeners are present, we want to make sure that an expiry is sent before a mutation happens, which was eventually triggered by the fact that the entry expired. For example, a get() will trigger a load if the entry expired.
-
existingEntryExpiredBeforeMutationSendExpiryEvents
public void existingEntryExpiredBeforeMutationSendExpiryEvents()
The entry logically expired before the mutation. Send expiry event. Example: A get() triggers a load(). Also the expiry timer event sends out the events via this method.- See Also:
Operations.expireEvent
-
noExpiryListenersPresent
public void noExpiryListenersPresent()
-
continueWithMutation
public void continueWithMutation()
-
loadAndRestart
public void loadAndRestart()
Description copied from interface:Progress
Request a load, and then call examine again to reevaluate. Last command of semantic method.- Specified by:
loadAndRestart
in interfaceProgress<K,V,R>
-
refresh
public void refresh()
Description copied from interface:Progress
Same as load but counting statistics as refresh. Last command of semantic method.
-
load
public void load()
Description copied from interface:Progress
Request that the entry value gets loaded from loader. Last command of semantic method. By default the loaded value will be set as operation result. Defined inSemantic.Base
-
reviveRefreshedEntry
public void reviveRefreshedEntry(long nrt)
-
onLoadSuccess
public void onLoadSuccess(V v)
- Specified by:
onLoadSuccess
in interfaceorg.cache2k.io.AsyncCacheLoader.Callback<K>
-
onLoadFailure
public void onLoadFailure(Throwable t)
The load failed, resilience and refreshing needs to be triggered- Specified by:
onLoadFailure
in interfaceorg.cache2k.io.AsyncCacheLoader.Callback<K>
-
loadCompleted
public void loadCompleted()
-
result
public void result(R r)
Description copied from interface:Progress
Sets the operation result.
-
entryResult
public void entryResult(ExaminationEntry<K,V> e)
Description copied from interface:Progress
Returns a cache entry as result. The entry will be copied before returning.- Specified by:
entryResult
in interfaceProgress<K,V,R>
-
put
public void put(V value)
Description copied from interface:Progress
Update the entry with the new value. Last command of semantic method.
-
remove
public void remove()
Description copied from interface:Progress
The entry will be removed. Last command of semantic method.
-
expire
public void expire(long expiryTime)
Description copied from interface:Progress
Reset expiry to the specified value. Don't change the value.
-
putAndSetExpiry
public void putAndSetExpiry(V value, long expiryTime, long refreshTime)
Description copied from interface:Progress
Set new value, skip expiry calculation and set expiry time directly.- Specified by:
putAndSetExpiry
in interfaceProgress<K,V,R>
-
mutationCalculateExpiry
public void mutationCalculateExpiry()
-
expiryCalculationException
public void expiryCalculationException(Throwable t)
-
expiryCalculated
public void expiryCalculated()
-
loadAndExpiryCalculatedExamineAgain
public void loadAndExpiryCalculatedExamineAgain()
-
updateDidNotTriggerDifferentMutationStoreLoadedValue
public void updateDidNotTriggerDifferentMutationStoreLoadedValue()
-
mutationMayCallWriter
public void mutationMayCallWriter()
Entry mutation, call writer if needed or skip tomutationMayStore()
-
mutationCallWriter
public void mutationCallWriter()
-
onWriteSuccess
public void onWriteSuccess()
- Specified by:
onWriteSuccess
in interfaceAsyncCacheWriter.Callback
-
onWriteFailure
public void onWriteFailure(Throwable t)
- Specified by:
onWriteFailure
in interfaceAsyncCacheWriter.Callback
-
skipWritingForException
public void skipWritingForException()
-
skipWritingNoWriter
public void skipWritingNoWriter()
-
checkKeepOrRemove
public void checkKeepOrRemove()
In case we have an expiry of 0, this means that the entry should not be cached. If there is a valid entry, we remove it if we do not keep the data.
-
expiredImmediatelyKeepData
public void expiredImmediatelyKeepData()
-
expiredImmediatelyAndRemove
public void expiredImmediatelyAndRemove()
-
mutationMayStore
public void mutationMayStore()
Entry mutation, call storage if needed
-
skipStore
public void skipStore()
-
callListeners
public void callListeners()
-
getCache
public org.cache2k.Cache<K,V> getCache()
User facing cache interface instance. Part of async call context.
-
mutationReleaseLockAndStartTimer
public void mutationReleaseLockAndStartTimer()
Mutate the entry and start timer for expiry. Entry mutation and start of expiry has to be done atomically to avoid races.
-
expiredAtEndOfOperationStartOver
public void expiredAtEndOfOperationStartOver()
Entry expired during progress of the action, reentry at a previous processing state to call listeners and update heap.We could get rid of this path in case the timer would just execute immediately.
-
updateMutationStatistics
public void updateMutationStatistics()
-
failure
public void failure(RuntimeException t)
Failure call on Progress from Semantic.
-
examinationAbort
public void examinationAbort(org.cache2k.CustomizationException t)
-
mutationAbort
public void mutationAbort(RuntimeException t)
-
mutationDone
public void mutationDone()
-
abort
public void abort()
Abort, but check whether entry was locked before.
-
abortReleaseLock
public void abortReleaseLock()
Release the lock. Cleanup entry if it was inserted on behalf of this operation.
-
abortFinalize
public void abortFinalize()
-
completeProcessCallbacks
public void completeProcessCallbacks()
Execute any callback or other actions waiting for this one to complete. It is safe to accessnextAction
here, also we don't hold the entry lock since the entry does not point on this action any more.
-
ready
public void ready()
-
getExceptionToPropagate
public RuntimeException getExceptionToPropagate()
Exception that might have happened during processing. A processing exception takes precedence over a loader exception, because it is probably more severe. Loader exceptions will be delayed until the value is accessed. This exception will be propagated instantly.
-
getLoaderException
public Throwable getLoaderException()
-
getException
public Throwable getException()
-
getResult
public R getResult()
-
isResultAvailable
public boolean isResultAvailable()
If false, the result is not set. This deals with the fact if null values are not permitted a loaded null means remove or no mapping.
-
-