Package org.cache2k.core
Class BulkAction<K,V,R>
- java.lang.Object
-
- org.cache2k.core.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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
bulkOperationCompleted()
protected abstract EntryAction<K,V,R>
createEntryAction(K key, BulkAction<K,V,R> self)
void
entryActionCompleted(EntryAction<K,V,R> ea)
Callback upon completion of an entry action.void
expectKey(K key)
Collection<EntryAction<K,V,R>>
getActions()
Throwable
getException()
Throwable
getExceptionToPropagate()
org.cache2k.io.CacheLoaderException
getLoaderException()
protected boolean
isSyncMode()
Processing is synchronous e.g.void
load(K key, org.cache2k.io.AsyncCacheLoader.Context<K,V> context, org.cache2k.io.AsyncCacheLoader.Callback<V> callback)
Load request for single value coming for entry action.void
onLoadFailure(Iterable<? extends K> keys, Throwable exception)
void
onLoadFailure(Throwable exception)
Fail all pending load requests.void
onLoadFailure(K key, Throwable exception)
void
onLoadSuccess(Map<? extends K,? extends V> data)
void
onLoadSuccess(K key, V value)
void
start()
-
-
-
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.
-
onLoadFailure
public void onLoadFailure(Throwable exception)
Fail all pending load requests. Do nothing when all requests are completed already.
-
expectKey
public void expectKey(K key)
-
entryActionCompleted
public void entryActionCompleted(EntryAction<K,V,R> ea)
Callback upon completion of an entry action. Either start more actions or complete processing.- Specified by:
entryActionCompleted
in interfaceEntryAction.CompletedCallback<K,V,R>
-
getException
public Throwable getException()
-
getExceptionToPropagate
public Throwable getExceptionToPropagate()
-
getLoaderException
public org.cache2k.io.CacheLoaderException getLoaderException()
-
getActions
public Collection<EntryAction<K,V,R>> getActions()
-
bulkOperationCompleted
protected void bulkOperationCompleted()
-
createEntryAction
protected abstract EntryAction<K,V,R> createEntryAction(K key, BulkAction<K,V,R> self)
-
isSyncMode
protected boolean isSyncMode()
Processing is synchronous e.g. forgetAll
no callback is called.
-
-