Package org.infinispan.persistence.async
Class AsyncCacheWriter
- java.lang.Object
-
- org.infinispan.persistence.support.DelegatingCacheWriter
-
- org.infinispan.persistence.async.AsyncCacheWriter
-
- All Implemented Interfaces:
Lifecycle,CacheWriter
- Direct Known Subclasses:
AdvancedAsyncCacheWriter
public class AsyncCacheWriter extends DelegatingCacheWriter
The AsyncCacheWriter is a delegating CacheStore that buffers changes and writes them asynchronously to the underlying CacheStore. Read operations are done synchronously, taking into account the current state of buffered changes. There is no provision for exception handling for problems encountered with the underlying store during a write operation, and the exception is just logged. When configuring the loader, use the following element:<async enabled="true" />to define whether cache loader operations are to be asynchronous. If not specified, a cache loader operation is assumed synchronous and this decorator is not applied. Write operations affecting same key are now coalesced so that only the final state is actually stored.- Since:
- 4.0
- Author:
- Manik Surtani, Galder ZamarreƱo, Sanne Grinovero, Karsten Blees, Mircea Markus
-
-
Field Summary
Fields Modifier and Type Field Description protected AsyncStoreConfigurationasyncConfigurationprotected AtomicReference<State>stateprotected org.infinispan.persistence.async.BufferLockstateLock-
Fields inherited from class org.infinispan.persistence.support.DelegatingCacheWriter
actual, ctx
-
-
Constructor Summary
Constructors Constructor Description AsyncCacheWriter(CacheWriter delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapplyModificationsSync(List<Modification> mods)protected voidclearStore()booleandelete(Object key)voiddeleteBatch(Iterable keys)Remove all provided keys from the store in a single batch operation.AtomicReference<State>getState()voidinit(InitializationContext ctx)Used to initialize a cache loader.booleanisAvailable()protected StatenewState(boolean clear, State next)voidstart()Invoked on component startvoidstop()Invoked on component stopvoidwrite(MarshalledEntry entry)Persists the entry to the storage.voidwriteBatch(Iterable entries)Persist all provided entries to the store in a single batch update.-
Methods inherited from class org.infinispan.persistence.support.DelegatingCacheWriter
undelegate
-
-
-
-
Field Detail
-
stateLock
protected org.infinispan.persistence.async.BufferLock stateLock
-
state
protected final AtomicReference<State> state
-
asyncConfiguration
protected AsyncStoreConfiguration asyncConfiguration
-
-
Constructor Detail
-
AsyncCacheWriter
public AsyncCacheWriter(CacheWriter delegate)
-
-
Method Detail
-
init
public void init(InitializationContext ctx)
Description copied from interface:CacheWriterUsed to initialize a cache loader. Typically invoked by thePersistenceManagerwhen setting up cache loaders.- Specified by:
initin interfaceCacheWriter- Overrides:
initin classDelegatingCacheWriter
-
start
public void start()
Description copied from interface:LifecycleInvoked on component start- Specified by:
startin interfaceLifecycle- Overrides:
startin classDelegatingCacheWriter
-
stop
public void stop()
Description copied from interface:LifecycleInvoked on component stop- Specified by:
stopin interfaceLifecycle- Overrides:
stopin classDelegatingCacheWriter
-
isAvailable
public boolean isAvailable()
- Returns:
- true if the writer can be connected to, otherwise false
-
write
public void write(MarshalledEntry entry)
Description copied from interface:CacheWriterPersists the entry to the storage.- Specified by:
writein interfaceCacheWriter- Overrides:
writein classDelegatingCacheWriter- See Also:
MarshalledEntry
-
writeBatch
public void writeBatch(Iterable entries)
Description copied from interface:CacheWriterPersist all provided entries to the store in a single batch update. If this is not supported by the underlying store, then entries are written to the store individually viaCacheWriter.write(MarshalledEntry).- Parameters:
entries- an Iterable of MarshalledEntry to be written to the store.
-
deleteBatch
public void deleteBatch(Iterable keys)
Description copied from interface:CacheWriterRemove all provided keys from the store in a single batch operation. If this is not supported by the underlying store, then keys are removed from the store individually viaCacheWriter.delete(Object).- Parameters:
keys- an Iterable of entry Keys to be removed from the store.
-
delete
public boolean delete(Object key)
- Specified by:
deletein interfaceCacheWriter- Overrides:
deletein classDelegatingCacheWriter- Returns:
- true if the entry existed in the persistent store and it was deleted.
-
applyModificationsSync
protected void applyModificationsSync(List<Modification> mods) throws PersistenceException
- Throws:
PersistenceException
-
getState
public AtomicReference<State> getState()
-
clearStore
protected void clearStore()
-
-