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 AsyncStoreConfiguration
asyncConfiguration
protected AtomicReference<State>
state
protected org.infinispan.persistence.async.BufferLock
stateLock
-
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 void
applyModificationsSync(List<Modification> mods)
protected void
clearStore()
boolean
delete(Object key)
void
deleteBatch(Iterable keys)
Remove all provided keys from the store in a single batch operation.AtomicReference<State>
getState()
void
init(InitializationContext ctx)
Used to initialize a cache loader.boolean
isAvailable()
protected State
newState(boolean clear, State next)
void
start()
Invoked on component startvoid
stop()
Invoked on component stopvoid
write(MarshalledEntry entry)
Persists the entry to the storage.void
writeBatch(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:CacheWriter
Used to initialize a cache loader. Typically invoked by thePersistenceManager
when setting up cache loaders.- Specified by:
init
in interfaceCacheWriter
- Overrides:
init
in classDelegatingCacheWriter
-
start
public void start()
Description copied from interface:Lifecycle
Invoked on component start- Specified by:
start
in interfaceLifecycle
- Overrides:
start
in classDelegatingCacheWriter
-
stop
public void stop()
Description copied from interface:Lifecycle
Invoked on component stop- Specified by:
stop
in interfaceLifecycle
- Overrides:
stop
in 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:CacheWriter
Persists the entry to the storage.- Specified by:
write
in interfaceCacheWriter
- Overrides:
write
in classDelegatingCacheWriter
- See Also:
MarshalledEntry
-
writeBatch
public void writeBatch(Iterable entries)
Description copied from interface:CacheWriter
Persist 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:CacheWriter
Remove 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:
delete
in interfaceCacheWriter
- Overrides:
delete
in 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()
-
-