Class PersistenceManagerImpl
- java.lang.Object
-
- org.infinispan.persistence.manager.PersistenceManagerImpl
-
- All Implemented Interfaces:
Lifecycle
,PersistenceManager
public class PersistenceManagerImpl extends java.lang.Object implements PersistenceManager
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.persistence.manager.PersistenceManager
PersistenceManager.AccessMode
-
-
Constructor Summary
Constructors Constructor Description PersistenceManagerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
activePublisherInvocations()
Returns how many publisher invocations are currently active.java.util.concurrent.CompletionStage<java.lang.Boolean>
addSegments(IntSet segments)
Notifies any underlying segmented stores that the segments provided are owned by this cache and to start/configure any underlying resources required to handle requests for entries on the given segments.java.util.concurrent.CompletionStage<java.lang.Void>
clearAllStores(java.util.function.Predicate<? super StoreConfiguration> predicate)
InvokesAdvancedCacheWriter.clear()
on all the stores that aloes it.java.util.concurrent.CompletionStage<java.lang.Void>
commitAllTxStores(javax.transaction.Transaction transaction, java.util.function.Predicate<? super StoreConfiguration> predicate)
Perform the commit operation for the provided transaction on all Tx stores.protected AsyncCacheWriter
createAsyncWriter(CacheWriter writer)
java.util.concurrent.CompletionStage<java.lang.Void>
deleteBatchFromAllNonTxStores(java.lang.Iterable<java.lang.Object> keys, java.util.function.Predicate<? super StoreConfiguration> predicate, long flags)
Remove all entries from the underlying non-transactional stores as a single batch.java.util.concurrent.CompletionStage<java.lang.Boolean>
deleteFromAllStores(java.lang.Object key, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate)
boolean
deleteFromAllStoresSync(java.lang.Object key, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate)
Same asPersistenceManager.deleteFromAllStores(Object, int, Predicate)
except synchronous - Should only be invoked from persistence thread and from passivation or activation codevoid
disableStore(java.lang.String storeType)
Marks the given storage as disabled.java.util.List<CacheLoader>
getAllLoaders()
java.util.List<CacheWriter>
getAllTxWriters()
java.util.List<CacheWriter>
getAllWriters()
StreamAwareMarshaller
getMarshaller()
<T> java.util.Set<T>
getStores(java.lang.Class<T> storeClass)
java.util.Collection<java.lang.String>
getStoresAsString()
boolean
hasWriter()
Returns whether the manager is enabled and has at least one storeboolean
isAvailable()
boolean
isEnabled()
boolean
isPreloaded()
boolean
isReadOnly()
<K,V>
java.util.concurrent.CompletionStage<MarshallableEntry<K,V>>loadFromAllStores(java.lang.Object key, boolean localInvocation, boolean includeStores)
Loads an entry from the persistence store for the given key.<K,V>
java.util.concurrent.CompletionStage<MarshallableEntry<K,V>>loadFromAllStores(java.lang.Object key, int segment, boolean localInvocation, boolean includeStores)
Same asPersistenceManager.loadFromAllStores(Object, boolean, boolean)
except that the segment of the key is also provided to avoid having to calculate the segment.<K,V>
MarshallableEntry<K,V>loadFromAllStoresSync(java.lang.Object key, boolean localInvocation, boolean includeStores)
Same asPersistenceManager.loadFromAllStores(Object, boolean, boolean)
except synchronous - Should only be invoked from persistence thread and from passivation or activation code<K,V>
MarshallableEntry<K,V>loadFromAllStoresSync(java.lang.Object key, int segment, boolean localInvocation, boolean includeStores)
Same asPersistenceManager.loadFromAllStores(Object, int, boolean, boolean)
except synchronous - Should only be invoked from persistence thread and from passivation or activation codeprotected void
pollStoreAvailability()
java.util.concurrent.CompletionStage<java.lang.Void>
preload()
Loads the data from the external store into memory during cache startup.java.util.concurrent.CompletionStage<java.lang.Void>
prepareAllTxStores(javax.transaction.Transaction transaction, BatchModification batchModification, java.util.function.Predicate<? super StoreConfiguration> predicate)
Perform the prepare phase of 2PC on all Tx stores.<K,V>
io.reactivex.Flowable<MarshallableEntry<K,V>>publishEntries(java.util.function.Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata, java.util.function.Predicate<? super StoreConfiguration> predicate)
Returns a publisher that will publish all entries stored by the underlying cache store.<K,V>
io.reactivex.Flowable<MarshallableEntry<K,V>>publishEntries(IntSet segments, java.util.function.Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata, java.util.function.Predicate<? super StoreConfiguration> predicate)
Returns a publisher that will publish entries that map to the provided segments.<K> io.reactivex.Flowable<K>
publishKeys(java.util.function.Predicate<? super K> filter, java.util.function.Predicate<? super StoreConfiguration> predicate)
Returns a publisher that will publish all keys stored by the underlying cache store.<K> io.reactivex.Flowable<K>
publishKeys(IntSet segments, java.util.function.Predicate<? super K> filter, java.util.function.Predicate<? super StoreConfiguration> predicate)
Returns a publisher that will publish keys that map to the provided segments.void
purgeExpired()
Removes the expired entries from all the existing storage.java.util.concurrent.CompletionStage<java.lang.Boolean>
removeSegments(IntSet segments)
Notifies any underlying segmented stores that a given segment is no longer owned by this cache and allowing it to remove the given segments and release resources related to it.java.util.concurrent.CompletionStage<java.lang.Void>
rollbackAllTxStores(javax.transaction.Transaction transaction, java.util.function.Predicate<? super StoreConfiguration> predicate)
Perform the rollback operation for the provided transaction on all Tx stores.void
setClearOnStop(boolean clearOnStop)
java.util.concurrent.CompletionStage<java.lang.Integer>
size(java.util.function.Predicate<? super StoreConfiguration> predicate)
Returns the count of how many entries are persisted.java.util.concurrent.CompletionStage<java.lang.Integer>
size(IntSet segments)
Returns the count of how many entries are persisted within the given segments.void
start()
Invoked on component startvoid
stop()
Invoked on component stopjava.util.concurrent.CompletionStage<java.lang.Void>
writeBatchToAllNonTxStores(java.lang.Iterable<MarshallableEntry> entries, java.util.function.Predicate<? super StoreConfiguration> predicate, long flags)
Write all entries to the underlying non-transactional stores as a single batch.java.util.concurrent.CompletionStage<java.lang.Void>
writeToAllNonTxStores(MarshallableEntry marshalledEntry, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate, long flags)
void
writeToAllNonTxStoresSync(MarshallableEntry marshalledEntry, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate)
Same asPersistenceManager.writeToAllNonTxStores(MarshallableEntry, int, Predicate)
except synchronous - Should only be invoked from persistence thread and from passivation or activation code-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.persistence.manager.PersistenceManager
publishEntries, size, writeToAllNonTxStores
-
-
-
-
Method Detail
-
start
public void start()
Description copied from interface:Lifecycle
Invoked on component start
-
activePublisherInvocations
public int activePublisherInvocations()
Returns how many publisher invocations are currently active.- Returns:
- count of active publisher instances
-
pollStoreAvailability
protected void pollStoreAvailability()
-
stop
public void stop()
Description copied from interface:Lifecycle
Invoked on component stop
-
hasWriter
public boolean hasWriter()
Description copied from interface:PersistenceManager
Returns whether the manager is enabled and has at least one store- Specified by:
hasWriter
in interfacePersistenceManager
-
isEnabled
public boolean isEnabled()
- Specified by:
isEnabled
in interfacePersistenceManager
-
isAvailable
public boolean isAvailable()
- Specified by:
isAvailable
in interfacePersistenceManager
- Returns:
- true if all configured stores are available and ready for read/write operations.
-
isPreloaded
public boolean isPreloaded()
- Specified by:
isPreloaded
in interfacePersistenceManager
- Returns:
- true if all entries from the store have been inserted to the cache. If the persistence/preload is disabled or eviction limit was reached when preloading, returns false.
-
preload
public java.util.concurrent.CompletionStage<java.lang.Void> preload()
Description copied from interface:PersistenceManager
Loads the data from the external store into memory during cache startup.- Specified by:
preload
in interfacePersistenceManager
-
disableStore
public void disableStore(java.lang.String storeType)
Description copied from interface:PersistenceManager
Marks the given storage as disabled.- Specified by:
disableStore
in interfacePersistenceManager
-
getStores
public <T> java.util.Set<T> getStores(java.lang.Class<T> storeClass)
- Specified by:
getStores
in interfacePersistenceManager
-
getStoresAsString
public java.util.Collection<java.lang.String> getStoresAsString()
- Specified by:
getStoresAsString
in interfacePersistenceManager
-
purgeExpired
public void purgeExpired()
Description copied from interface:PersistenceManager
Removes the expired entries from all the existing storage.- Specified by:
purgeExpired
in interfacePersistenceManager
-
clearAllStores
public java.util.concurrent.CompletionStage<java.lang.Void> clearAllStores(java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
InvokesAdvancedCacheWriter.clear()
on all the stores that aloes it.- Specified by:
clearAllStores
in interfacePersistenceManager
-
deleteFromAllStoresSync
public boolean deleteFromAllStoresSync(java.lang.Object key, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Same asPersistenceManager.deleteFromAllStores(Object, int, Predicate)
except synchronous - Should only be invoked from persistence thread and from passivation or activation code- Specified by:
deleteFromAllStoresSync
in interfacePersistenceManager
-
deleteFromAllStores
public java.util.concurrent.CompletionStage<java.lang.Boolean> deleteFromAllStores(java.lang.Object key, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate)
- Specified by:
deleteFromAllStores
in interfacePersistenceManager
-
publishEntries
public <K,V> io.reactivex.Flowable<MarshallableEntry<K,V>> publishEntries(java.util.function.Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Returns a publisher that will publish all entries stored by the underlying cache store. Only the first cache store that implementsAdvancedCacheLoader
will be used. Predicate is applied by the underlying loader in a best attempt to improve performance.Caller can tell the store to also fetch the value or metadata. In some cases this can improve performance. If metadata is not fetched the publisher may include expired entries.
- Specified by:
publishEntries
in interfacePersistenceManager
- Type Parameters:
K
- key typeV
- value type- Parameters:
filter
- filter so that only entries whose key matches are returnedfetchValue
- whether to fetch value or notfetchMetadata
- whether to fetch metadata or notpredicate
- whether a store can be used by publish entries- Returns:
- publisher that will publish entries
-
publishEntries
public <K,V> io.reactivex.Flowable<MarshallableEntry<K,V>> publishEntries(IntSet segments, java.util.function.Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Returns a publisher that will publish entries that map to the provided segments. It will attempt to find the first segmented store if one is available. If not it will fall back to the first non segmented store and filter out entries that don't map to the provided segment.- Specified by:
publishEntries
in interfacePersistenceManager
- Type Parameters:
K
- key typeV
- value type- Parameters:
segments
- only entries that map to these segments are processedfilter
- filter so that only entries whose key matches are returnedfetchValue
- whether to fetch value or notfetchMetadata
- whether to fetch metadata or notpredicate
- whether a store can be used by publish entries- Returns:
- publisher that will publish entries belonging to the given segments
-
publishKeys
public <K> io.reactivex.Flowable<K> publishKeys(java.util.function.Predicate<? super K> filter, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Returns a publisher that will publish all keys stored by the underlying cache store. Only the first cache store that implementsAdvancedCacheLoader
will be used. Predicate is applied by the underlying loader in a best attempt to improve performance.This method should be preferred over
PersistenceManager.publishEntries(Predicate, boolean, boolean, Predicate)
when only keys are desired as many stores can do this in a significantly more performant way.This publisher will never return a key which belongs to an expired entry
- Specified by:
publishKeys
in interfacePersistenceManager
- Type Parameters:
K
- key type- Parameters:
filter
- filter so that only keys which match are returnedpredicate
- access mode to choose what type of loader to use- Returns:
- publisher that will publish keys
-
publishKeys
public <K> io.reactivex.Flowable<K> publishKeys(IntSet segments, java.util.function.Predicate<? super K> filter, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Returns a publisher that will publish keys that map to the provided segments. It will attempt to find the first segmented store if one is available. If not it will fall back to the first non segmented store and filter out entries that don't map to the provided segment.This method should be preferred over
PersistenceManager.publishEntries(IntSet, Predicate, boolean, boolean, Predicate)
when only keys are desired as many stores can do this in a significantly more performant way.This publisher will never return a key which belongs to an expired entry
- Specified by:
publishKeys
in interfacePersistenceManager
- Type Parameters:
K
- key type- Parameters:
segments
- only keys that map to these segments are processedfilter
- filter so that only keys which match are returnedpredicate
- access mode to choose what type of loader to use- Returns:
- publisher that will publish keys belonging to the given segments
-
loadFromAllStoresSync
public <K,V> MarshallableEntry<K,V> loadFromAllStoresSync(java.lang.Object key, boolean localInvocation, boolean includeStores)
Description copied from interface:PersistenceManager
Same asPersistenceManager.loadFromAllStores(Object, boolean, boolean)
except synchronous - Should only be invoked from persistence thread and from passivation or activation code- Specified by:
loadFromAllStoresSync
in interfacePersistenceManager
-
loadFromAllStores
public <K,V> java.util.concurrent.CompletionStage<MarshallableEntry<K,V>> loadFromAllStores(java.lang.Object key, boolean localInvocation, boolean includeStores)
Description copied from interface:PersistenceManager
Loads an entry from the persistence store for the given key. The returned value may be null. This value is guaranteed to not be expired when it was returned.- Specified by:
loadFromAllStores
in interfacePersistenceManager
- Parameters:
key
- key to read the entry fromlocalInvocation
- whether this invocation is a local invocation. Some loaders may be ignored if it is not localincludeStores
- if a loader that is also a store can be loaded from- Returns:
- entry that maps to the key
-
loadFromAllStoresSync
public <K,V> MarshallableEntry<K,V> loadFromAllStoresSync(java.lang.Object key, int segment, boolean localInvocation, boolean includeStores)
Description copied from interface:PersistenceManager
Same asPersistenceManager.loadFromAllStores(Object, int, boolean, boolean)
except synchronous - Should only be invoked from persistence thread and from passivation or activation code- Specified by:
loadFromAllStoresSync
in interfacePersistenceManager
-
loadFromAllStores
public <K,V> java.util.concurrent.CompletionStage<MarshallableEntry<K,V>> loadFromAllStores(java.lang.Object key, int segment, boolean localInvocation, boolean includeStores)
Description copied from interface:PersistenceManager
Same asPersistenceManager.loadFromAllStores(Object, boolean, boolean)
except that the segment of the key is also provided to avoid having to calculate the segment.- Specified by:
loadFromAllStores
in interfacePersistenceManager
- Parameters:
key
- key to read the entry fromsegment
- segment the key maps tolocalInvocation
- whether this invocation is a local invocation. Some loaders may be ignored if it is not localincludeStores
- if a loader that is also a store can be loaded from- Returns:
- entry that maps to the key
-
writeToAllNonTxStoresSync
public void writeToAllNonTxStoresSync(MarshallableEntry marshalledEntry, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Same asPersistenceManager.writeToAllNonTxStores(MarshallableEntry, int, Predicate)
except synchronous - Should only be invoked from persistence thread and from passivation or activation code- Specified by:
writeToAllNonTxStoresSync
in interfacePersistenceManager
-
writeToAllNonTxStores
public java.util.concurrent.CompletionStage<java.lang.Void> writeToAllNonTxStores(MarshallableEntry marshalledEntry, int segment, java.util.function.Predicate<? super StoreConfiguration> predicate, long flags)
- Specified by:
writeToAllNonTxStores
in interfacePersistenceManager
flags
- Flags used during command invocation- See Also:
PersistenceManager.writeToAllNonTxStores(MarshallableEntry, int, Predicate)
-
writeBatchToAllNonTxStores
public java.util.concurrent.CompletionStage<java.lang.Void> writeBatchToAllNonTxStores(java.lang.Iterable<MarshallableEntry> entries, java.util.function.Predicate<? super StoreConfiguration> predicate, long flags)
Description copied from interface:PersistenceManager
Write all entries to the underlying non-transactional stores as a single batch.- Specified by:
writeBatchToAllNonTxStores
in interfacePersistenceManager
- Parameters:
entries
- a List of MarshalledEntry to be written to the store.predicate
- whether a given store should write the entryflags
- Flags used during command invocation
-
deleteBatchFromAllNonTxStores
public java.util.concurrent.CompletionStage<java.lang.Void> deleteBatchFromAllNonTxStores(java.lang.Iterable<java.lang.Object> keys, java.util.function.Predicate<? super StoreConfiguration> predicate, long flags)
Description copied from interface:PersistenceManager
Remove all entries from the underlying non-transactional stores as a single batch.- Specified by:
deleteBatchFromAllNonTxStores
in interfacePersistenceManager
- Parameters:
keys
- a List of Keys to be removed from the store.predicate
- whether a given store should delete the entriesflags
- Flags used during command invocation
-
prepareAllTxStores
public java.util.concurrent.CompletionStage<java.lang.Void> prepareAllTxStores(javax.transaction.Transaction transaction, BatchModification batchModification, java.util.function.Predicate<? super StoreConfiguration> predicate) throws PersistenceException
Description copied from interface:PersistenceManager
Perform the prepare phase of 2PC on all Tx stores.- Specified by:
prepareAllTxStores
in interfacePersistenceManager
- Parameters:
transaction
- the current transactional context.batchModification
- an object containing the write/remove operations required for this transaction.predicate
- should we prepare on a given store- Throws:
PersistenceException
- if an error is encountered at any of the underlying stores.
-
commitAllTxStores
public java.util.concurrent.CompletionStage<java.lang.Void> commitAllTxStores(javax.transaction.Transaction transaction, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Perform the commit operation for the provided transaction on all Tx stores.- Specified by:
commitAllTxStores
in interfacePersistenceManager
- Parameters:
transaction
- the transactional context to be committed.predicate
- should we commit each store
-
rollbackAllTxStores
public java.util.concurrent.CompletionStage<java.lang.Void> rollbackAllTxStores(javax.transaction.Transaction transaction, java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Perform the rollback operation for the provided transaction on all Tx stores.- Specified by:
rollbackAllTxStores
in interfacePersistenceManager
- Parameters:
transaction
- the transactional context to be rolledback.predicate
- should we rollback each store
-
size
public java.util.concurrent.CompletionStage<java.lang.Integer> size(java.util.function.Predicate<? super StoreConfiguration> predicate)
Description copied from interface:PersistenceManager
Returns the count of how many entries are persisted. If no store can handle the request for the given mode a value of -1 is returned instead.- Specified by:
size
in interfacePersistenceManager
- Parameters:
predicate
- whether a loader can be used- Returns:
- size or -1 if size couldn't be computed
-
size
public java.util.concurrent.CompletionStage<java.lang.Integer> size(IntSet segments)
Description copied from interface:PersistenceManager
Returns the count of how many entries are persisted within the given segments. The returned value will always be 0 or greater.- Specified by:
size
in interfacePersistenceManager
- Parameters:
segments
- which segments to count entries from- Returns:
- how many entries are in the store which map to the given segments
-
setClearOnStop
public void setClearOnStop(boolean clearOnStop)
- Specified by:
setClearOnStop
in interfacePersistenceManager
-
addSegments
public java.util.concurrent.CompletionStage<java.lang.Boolean> addSegments(IntSet segments)
Description copied from interface:PersistenceManager
Notifies any underlying segmented stores that the segments provided are owned by this cache and to start/configure any underlying resources required to handle requests for entries on the given segments.This only affects stores that are not shared as shared stores have to keep all segments running at all times
This method returns true if all stores were able to handle the added segments. That is that either there are no stores or that all the configured stores are segmented. Note that configured loaders do not affect the return value.
- Specified by:
addSegments
in interfacePersistenceManager
- Parameters:
segments
- segments this cache owns- Returns:
- false if a configured store couldn't configure newly added segments
-
removeSegments
public java.util.concurrent.CompletionStage<java.lang.Boolean> removeSegments(IntSet segments)
Description copied from interface:PersistenceManager
Notifies any underlying segmented stores that a given segment is no longer owned by this cache and allowing it to remove the given segments and release resources related to it.This only affects stores that are not shared as shared stores have to keep all segments running at all times
This method returns true if all stores were able to handle the added segments. That is that either there are no stores or that all the configured stores are segmented. Note that configured loaders do not affect the return value.
- Specified by:
removeSegments
in interfacePersistenceManager
- Parameters:
segments
- segments this cache no longer owns- Returns:
- false if a configured store couldn't remove configured segments
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfacePersistenceManager
- Returns:
- true if no
CacheWriter
instances have been configured.
-
getAllLoaders
public java.util.List<CacheLoader> getAllLoaders()
-
getAllWriters
public java.util.List<CacheWriter> getAllWriters()
-
getAllTxWriters
public java.util.List<CacheWriter> getAllTxWriters()
-
createAsyncWriter
protected AsyncCacheWriter createAsyncWriter(CacheWriter writer)
-
getMarshaller
public StreamAwareMarshaller getMarshaller()
-
-