Class BulkAction<K,​V,​R>

  • All Implemented Interfaces:
    EntryAction.CompletedCallback<K,​V,​R>, org.cache2k.Customization, org.cache2k.DataAware<K,​V>, org.cache2k.DataAwareCustomization<K,​V>, org.cache2k.io.AsyncBulkCacheLoader.BulkCallback<K,​V>, org.cache2k.io.AsyncCacheLoader<K,​V>

    public abstract class BulkAction<K,​V,​R>
    extends Object
    implements org.cache2k.io.AsyncCacheLoader<K,​V>, org.cache2k.io.AsyncBulkCacheLoader.BulkCallback<K,​V>, EntryAction.CompletedCallback<K,​V,​R>
    Execute a set of entry actions in parallel to leverage bulk I/O. The basic idea is to collect I/O requests by implementing the callback interfaces and then issue a bulk I/O request on the corresponding bulk interface. This way the entry processing code can be used and it does not need to be aware of bulk operations. Theoretically, its also possible to process an inhomogeneous set of actions and try to do as much bulk I/O as possible.

    Since multiple entries are locked, we need to do precautions to avoid deadlocks. The strategy is to never hold a lock for one entry and wait for locking another entry.

    Author:
    Jens Wilke
    • Constructor Detail

      • BulkAction

        public BulkAction​(HeapCache<K,​V> heapCache,
                          InternalCache<K,​V> internalCache,
                          org.cache2k.io.AsyncCacheLoader<K,​V> loader,
                          Set<K> keys)
        Create object and start operation.
    • Method Detail

      • start

        public void start()
      • load

        public void load​(K key,
                         org.cache2k.io.AsyncCacheLoader.Context<K,​V> context,
                         org.cache2k.io.AsyncCacheLoader.Callback<V> callback)
                  throws Exception
        Load request for single value coming for entry action. If we execute in bulk we just collect. If not in bulk mode we execute straight away.
        Specified by:
        load in interface org.cache2k.io.AsyncCacheLoader<K,​V>
        Throws:
        Exception
      • onLoadSuccess

        public void onLoadSuccess​(Map<? extends K,​? extends V> data)
        Specified by:
        onLoadSuccess in interface org.cache2k.io.AsyncBulkCacheLoader.BulkCallback<K,​V>
      • onLoadSuccess

        public void onLoadSuccess​(K key,
                                  V value)
        Specified by:
        onLoadSuccess in interface org.cache2k.io.AsyncBulkCacheLoader.BulkCallback<K,​V>
      • onLoadFailure

        public void onLoadFailure​(Throwable exception)
        Fail all pending load requests. Do nothing when all requests are completed already.
        Specified by:
        onLoadFailure in interface org.cache2k.io.AsyncBulkCacheLoader.BulkCallback<K,​V>
      • onLoadFailure

        public void onLoadFailure​(Set<? extends K> keys,
                                  Throwable exception)
        Specified by:
        onLoadFailure in interface org.cache2k.io.AsyncBulkCacheLoader.BulkCallback<K,​V>
      • expectKey

        public void expectKey​(K key)
      • onLoadFailure

        public void onLoadFailure​(K key,
                                  Throwable exception)
        Specified by:
        onLoadFailure in interface org.cache2k.io.AsyncBulkCacheLoader.BulkCallback<K,​V>
      • getException

        public Throwable getException()
      • getExceptionToPropagate

        public Throwable getExceptionToPropagate()
      • getLoaderException

        public org.cache2k.io.CacheLoaderException getLoaderException()
      • bulkOperationCompleted

        protected void bulkOperationCompleted()
      • isSyncMode

        protected boolean isSyncMode()
        Processing is synchronous e.g. for getAll no callback is called.