Package org.infinispan.persistence.file
Class SingleFileStore<K,V>
- java.lang.Object
-
- org.infinispan.persistence.file.SingleFileStore<K,V>
-
- All Implemented Interfaces:
Lifecycle,AdvancedCacheLoader<K,V>,AdvancedCacheWriter<K,V>,AdvancedLoadWriteStore<K,V>,CacheLoader<K,V>,CacheWriter<K,V>,ExternalStore<K,V>
public class SingleFileStore<K,V> extends Object implements AdvancedLoadWriteStore<K,V>
A filesystem-based implementation of aAdvancedLoadWriteStore. This file store stores cache values in a single file <location>/<cache name>.dat, keys and file positions are kept in memory. Note: this CacheStore implementation keeps keys and file positions in memory! The current implementation needs about 100 bytes per cache entry, plus the memory for the key objects. So, the space taken by this cache store is both the space in the file itself plus the in-memory index with the keys and their file positions. With this in mind and to avoid the cache store leading to OutOfMemoryExceptions, you can optionally configure the maximum number of entries to maintain in this cache store, which affects both the size of the file and the size of the in-memory index. However, setting this maximum limit results in older entries in the cache store to be eliminated, and hence, it only makes sense configuring a maximum limit if Infinispan is used as a cache where loss of data in the cache store does not lead to data loss, and data can be recomputed or re-queried from the original data source. This class is fully thread safe, yet allows for concurrent load / store of individual cache entries.- Since:
- 6.0
- Author:
- Karsten Blees, Mircea Markus
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.persistence.spi.AdvancedCacheLoader
AdvancedCacheLoader.CacheLoaderTask<K,V>, AdvancedCacheLoader.TaskContext
-
Nested classes/interfaces inherited from interface org.infinispan.persistence.spi.AdvancedCacheWriter
AdvancedCacheWriter.PurgeListener<K>
-
-
Field Summary
Fields Modifier and Type Field Description protected InitializationContextctx
-
Constructor Summary
Constructors Constructor Description SingleFileStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all the data from the storage.booleancontains(Object key)The base class implementation callsCacheLoader.loadEntry(Object)for this, we can do better because we keep all keys in memory.booleandelete(Object key)voiddestroy()Method to be used to destroy and clean up any resources associated with this store.io.reactivex.Flowable<MarshallableEntry<K,V>>entryPublisher(Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata)Publishes all entries from this store.SingleFileStoreConfigurationgetConfiguration()voidinit(InitializationContext ctx)Used to initialize a cache loader.booleanisAvailable()MarshallableEntry<K,V>loadEntry(Object key)Fetches an entry from the storage.io.reactivex.Flowable<K>publishKeys(Predicate<? super K> filter)Publishes all the keys from this store.voidpurge(Executor threadPool, AdvancedCacheWriter.PurgeListener task)Using the thread in the pool, removed all the expired data from the persistence storage.intsize()Returns the number of elements in the store.voidstart()Invoked on component startvoidstop()Invoked on component stopvoidwrite(MarshallableEntry<? extends K,? extends V> marshalledEntry)Persists the entry to the storage.-
Methods inherited from interface org.infinispan.persistence.spi.AdvancedCacheLoader
process, publishEntries
-
Methods inherited from interface org.infinispan.persistence.spi.CacheLoader
load
-
Methods inherited from interface org.infinispan.persistence.spi.CacheWriter
bulkUpdate, deleteBatch, write, writeBatch
-
-
-
-
Field Detail
-
ctx
protected InitializationContext ctx
-
-
Method Detail
-
init
public void init(InitializationContext ctx)
Description copied from interface:CacheLoaderUsed to initialize a cache loader. Typically invoked by thePersistenceManagerwhen setting up cache loaders.- Specified by:
initin interfaceCacheLoader<K,V>- Specified by:
initin interfaceCacheWriter<K,V>
-
start
public void start()
Description copied from interface:LifecycleInvoked on component start
-
stop
public void stop()
Description copied from interface:LifecycleInvoked on component stop
-
destroy
public void destroy()
Description copied from interface:ExternalStoreMethod to be used to destroy and clean up any resources associated with this store. This is normally only useful for non shared stores.This method will ensure the store is stopped and properly cleans up all resources for it.
- Specified by:
destroyin interfaceExternalStore<K,V>
-
isAvailable
public boolean isAvailable()
- Specified by:
isAvailablein interfaceCacheLoader<K,V>- Specified by:
isAvailablein interfaceCacheWriter<K,V>- Specified by:
isAvailablein interfaceExternalStore<K,V>- Returns:
- true if the writer can be connected to, otherwise false
-
contains
public boolean contains(Object key)
The base class implementation callsCacheLoader.loadEntry(Object)for this, we can do better because we keep all keys in memory.- Specified by:
containsin interfaceCacheLoader<K,V>
-
write
public void write(MarshallableEntry<? extends K,? extends V> marshalledEntry)
Description copied from interface:CacheWriterPersists the entry to the storage.- Specified by:
writein interfaceCacheWriter<K,V>- See Also:
MarshallableEntry
-
clear
public void clear()
Description copied from interface:AdvancedCacheWriterRemoves all the data from the storage.- Specified by:
clearin interfaceAdvancedCacheWriter<K,V>
-
delete
public boolean delete(Object key)
- Specified by:
deletein interfaceCacheWriter<K,V>- Returns:
- true if the entry existed in the persistent store and it was deleted.
-
loadEntry
public MarshallableEntry<K,V> loadEntry(Object key)
Description copied from interface:CacheLoaderFetches an entry from the storage. If aMarshallableEntryneeds to be created here,InitializationContext.getMarshallableEntryFactory()()} andInitializationContext.getByteBufferFactory()should be used.- Specified by:
loadEntryin interfaceCacheLoader<K,V>- Returns:
- the entry, or null if the entry does not exist
-
publishKeys
public io.reactivex.Flowable<K> publishKeys(Predicate<? super K> filter)
Description copied from interface:AdvancedCacheLoaderPublishes all the keys from this store. The given publisher can be used by as manySubscribers as desired. Keys are not retrieved until a given Subscriber requests them from theSubscription.Stores will return only non expired keys
- Specified by:
publishKeysin interfaceAdvancedCacheLoader<K,V>- Parameters:
filter- a filter - null is treated as allowing all entries- Returns:
- a publisher that will provide the keys from the store
-
entryPublisher
public io.reactivex.Flowable<MarshallableEntry<K,V>> entryPublisher(Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata)
Description copied from interface:AdvancedCacheLoaderPublishes all entries from this store. The given publisher can be used by as manySubscribers as desired. Entries are not retrieved until a given Subscriber requests them from theSubscription.If fetchMetadata is true this store must guarantee to not return any expired entries.
- Specified by:
entryPublisherin interfaceAdvancedCacheLoader<K,V>- Parameters:
filter- a filter - null is treated as allowing all entriesfetchValue- whether or not to fetch the value from the persistent store. E.g. if the iteration is intended only over the key set, no point fetching the values from the persistent store as wellfetchMetadata- whether or not to fetch the metadata from the persistent store. E.g. if the iteration is intended only ove the key set, then no point fetching the metadata from the persistent store as well- Returns:
- a publisher that will provide the entries from the store
-
purge
public void purge(Executor threadPool, AdvancedCacheWriter.PurgeListener task)
Description copied from interface:AdvancedCacheWriterUsing the thread in the pool, removed all the expired data from the persistence storage. For each removed entry, the supplied listener is invoked.When this method returns all entries will be purged and no tasks will be running due to this loader in the provided executor. If however an exception is thrown there could be tasks still pending or running in the executor.
- Specified by:
purgein interfaceAdvancedCacheWriter<K,V>
-
size
public int size()
Description copied from interface:AdvancedCacheLoaderReturns the number of elements in the store.- Specified by:
sizein interfaceAdvancedCacheLoader<K,V>
-
getConfiguration
public SingleFileStoreConfiguration getConfiguration()
-
-