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 InitializationContext
ctx
-
Constructor Summary
Constructors Constructor Description SingleFileStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all the data from the storage.boolean
contains(Object key)
The base class implementation callsCacheLoader.loadEntry(Object)
for this, we can do better because we keep all keys in memory.boolean
delete(Object key)
void
destroy()
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.SingleFileStoreConfiguration
getConfiguration()
void
init(InitializationContext ctx)
Used to initialize a cache loader.boolean
isAvailable()
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.void
purge(Executor threadPool, AdvancedCacheWriter.PurgeListener task)
Using the thread in the pool, removed all the expired data from the persistence storage.int
size()
Returns the number of elements in the store.void
start()
Invoked on component startvoid
stop()
Invoked on component stopvoid
write(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:CacheLoader
Used to initialize a cache loader. Typically invoked by thePersistenceManager
when setting up cache loaders.- Specified by:
init
in interfaceCacheLoader<K,V>
- Specified by:
init
in interfaceCacheWriter<K,V>
-
start
public void start()
Description copied from interface:Lifecycle
Invoked on component start
-
stop
public void stop()
Description copied from interface:Lifecycle
Invoked on component stop
-
destroy
public void destroy()
Description copied from interface:ExternalStore
Method 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:
destroy
in interfaceExternalStore<K,V>
-
isAvailable
public boolean isAvailable()
- Specified by:
isAvailable
in interfaceCacheLoader<K,V>
- Specified by:
isAvailable
in interfaceCacheWriter<K,V>
- Specified by:
isAvailable
in 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:
contains
in interfaceCacheLoader<K,V>
-
write
public void write(MarshallableEntry<? extends K,? extends V> marshalledEntry)
Description copied from interface:CacheWriter
Persists the entry to the storage.- Specified by:
write
in interfaceCacheWriter<K,V>
- See Also:
MarshallableEntry
-
clear
public void clear()
Description copied from interface:AdvancedCacheWriter
Removes all the data from the storage.- Specified by:
clear
in interfaceAdvancedCacheWriter<K,V>
-
delete
public boolean delete(Object key)
- Specified by:
delete
in 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:CacheLoader
Fetches an entry from the storage. If aMarshallableEntry
needs to be created here,InitializationContext.getMarshallableEntryFactory()
()} andInitializationContext.getByteBufferFactory()
should be used.- Specified by:
loadEntry
in 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:AdvancedCacheLoader
Publishes all the keys from this store. The given publisher can be used by as manySubscriber
s as desired. Keys are not retrieved until a given Subscriber requests them from theSubscription
.Stores will return only non expired keys
- Specified by:
publishKeys
in 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:AdvancedCacheLoader
Publishes all entries from this store. The given publisher can be used by as manySubscriber
s 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:
entryPublisher
in 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:AdvancedCacheWriter
Using 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:
purge
in interfaceAdvancedCacheWriter<K,V>
-
size
public int size()
Description copied from interface:AdvancedCacheLoader
Returns the number of elements in the store.- Specified by:
size
in interfaceAdvancedCacheLoader<K,V>
-
getConfiguration
public SingleFileStoreConfiguration getConfiguration()
-
-