Class 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
    • 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()
        Specified by:
        getExecutor in interface org.cache2k.io.AsyncCacheLoader.Context<K,​V>
      • executor

        protected abstract Executor executor()
      • loader

        protected org.cache2k.io.AdvancedCacheLoader<K,​V> loader()
        Provide the cache loader, if present.
      • asyncLoader

        protected org.cache2k.io.AsyncCacheLoader<K,​V> asyncLoader()
      • writer

        protected org.cache2k.io.CacheWriter<K,​V> writer()
        Provide the writer, default null.
      • 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()
      • timing

        protected abstract Timing<K,​V> timing()
      • setBulkMode

        public void setBulkMode​(boolean v)
      • isBulkMode

        public boolean isBulkMode()
      • getKey

        public K getKey()
        Specified by:
        getKey in interface org.cache2k.io.AsyncCacheLoader.Context<K,​V>
      • getStartTime

        public long getStartTime()
        Specified by:
        getStartTime in interface org.cache2k.io.AsyncCacheLoader.Context<K,​V>
      • isRefreshAhead

        public boolean isRefreshAhead()
        Specified by:
        isRefreshAhead in interface org.cache2k.io.AsyncCacheLoader.Context<K,​V>
      • 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 interface Progress<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.
        Specified by:
        getCurrentEntry in interface org.cache2k.io.AsyncCacheLoader.Context<K,​V>
      • isLoaderPresent

        public boolean isLoaderPresent()
        Description copied from interface: Progress
        A loader is present and the cache operates in read through.
        Specified by:
        isLoaderPresent in interface Progress<K,​V,​R>
      • wasLoaded

        public boolean wasLoaded()
        Description copied from interface: Progress
        Value was loaded before as part of this operation.
        Specified by:
        wasLoaded in interface Progress<K,​V,​R>
      • 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 interface Progress<K,​V,​R>
      • hasFreshData

        protected boolean hasFreshData()
        Same as Entry.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 interface Progress<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 interface Progress<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 interface Progress<K,​V,​R>
      • run

        public void run()
        Specified by:
        run in interface Runnable
      • start

        public void start()
        Entry point to execute this action.
      • retrieveDataFromHeap

        public void retrieveDataFromHeap()
      • heapMiss

        public void heapMiss()
      • heapHit

        public void heapHit​(Entry<K,​V> e)
      • 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 interface Progress<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 interface Progress<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.
        Specified by:
        refresh in interface Progress<K,​V,​R>
      • 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 in Semantic.Base
        Specified by:
        load in interface Progress<K,​V,​R>
      • reviveRefreshedEntry

        public void reviveRefreshedEntry​(long nrt)
      • onLoadSuccess

        public void onLoadSuccess​(V v)
        Specified by:
        onLoadSuccess in interface org.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 interface org.cache2k.io.AsyncCacheLoader.Callback<K>
      • loadCompleted

        public void loadCompleted()
      • result

        public void result​(R r)
        Description copied from interface: Progress
        Sets the operation result.
        Specified by:
        result in interface Progress<K,​V,​R>
      • resultOrWrapper

        public void resultOrWrapper​(Object r)
        Description copied from interface: Progress
        Sets the result or a wrapper
        Specified by:
        resultOrWrapper in interface Progress<K,​V,​R>
      • 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 interface Progress<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.
        Specified by:
        put in interface Progress<K,​V,​R>
      • remove

        public void remove()
        Description copied from interface: Progress
        The entry will be removed. Last command of semantic method.
        Specified by:
        remove in interface Progress<K,​V,​R>
      • expire

        public void expire​(long expiryTime)
        Description copied from interface: Progress
        Reset expiry to the specified value. Don't change the value.
        Specified by:
        expire in interface Progress<K,​V,​R>
      • 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 interface Progress<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 to mutationMayStore()
      • mutationCallWriter

        public void mutationCallWriter()
      • 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.
        Specified by:
        getCache in interface org.cache2k.io.AsyncCacheLoader.Context<K,​V>
        See Also:
        AsyncCacheLoader.Context.getCache()
      • 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()
      • examinationAbort

        public void examinationAbort​(org.cache2k.CustomizationException 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 access nextAction 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 Object 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.