Package org.apache.ignite.cache.store
Class CacheLoadOnlyStoreAdapter<K,V,I>
- java.lang.Object
- 
- org.apache.ignite.cache.store.CacheLoadOnlyStoreAdapter<K,V,I>
 
- 
- Type Parameters:
- K- Key type.
- V- Value type.
- I- Input type.
 - All Implemented Interfaces:
- javax.cache.integration.CacheLoader<K,V>,- javax.cache.integration.CacheWriter<K,V>,- CacheStore<K,V>
 
 public abstract class CacheLoadOnlyStoreAdapter<K,V,I> extends Object implements CacheStore<K,V> This adapter designed to support stores with bulk loading from stream-like source.This class processes input data in the following way: - 
          Iterator of input record obtained from user-defined inputIterator(Object...).
- 
          Iterator continuously queried for input records and they are grouped into batches of batchSize.
- 
          Batch is placed into processing queue and puled by one of threadsCntworking threads.
- 
          Each record in batch is passed to user-defined parse(Object, Object...)method and result is stored into cache.
 Two methods should be implemented by inheritants: - 
          inputIterator(Object...). It should open underlying data source and iterate all record available in it. Individual records could be in very raw form, like text lines for CSV files.
- 
          parse(Object, Object...). This method should process input records and transform them into key-value pairs for cache.
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intDFLT_BATCH_QUEUE_SIZEDefault batch queue size (max batches count to limit memory usage).static intDFLT_BATCH_SIZEDefault batch size (number of records read withinputIterator(Object...)and then submitted to internal pool at a time).static intDFLT_THREADS_COUNTDefault number of working threads (equal to the number of available processors).
 - 
Constructor SummaryConstructors Constructor Description CacheLoadOnlyStoreAdapter()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddelete(Object key)voiddeleteAll(Collection<?> keys)intgetBatchQueueSize()Returns batch queue size.intgetBatchSize()Returns batch size.intgetThreadsCount()Returns number of worker threads.protected abstract Iterator<I>inputIterator(@Nullable Object... args)Returns iterator of input records.Vload(K key)Map<K,V>loadAll(Iterable<? extends K> keys)voidloadCache(IgniteBiInClosure<K,V> c, @Nullable Object... args)Loads all values from underlying persistent storage.protected abstract @Nullable IgniteBiTuple<K,V>parse(I rec, @Nullable Object... args)This method should transform raw data records into valid key-value pairs to be stored into cache.voidsessionEnd(boolean commit)Tells store to commit or rollback a transaction depending on the value of the'commit'parameter.voidsetBatchQueueSize(int batchQueueSize)Sets batch queue size.voidsetBatchSize(int batchSize)Sets batch size.voidsetThreadsCount(int threadsCnt)Sets number of worker threads.voidwrite(javax.cache.Cache.Entry<? extends K,? extends V> entry)voidwriteAll(Collection<javax.cache.Cache.Entry<? extends K,? extends V>> entries)
 
- 
- 
- 
Field Detail- 
DFLT_BATCH_SIZEpublic static final int DFLT_BATCH_SIZE Default batch size (number of records read withinputIterator(Object...)and then submitted to internal pool at a time).- See Also:
- Constant Field Values
 
 - 
DFLT_BATCH_QUEUE_SIZEpublic static final int DFLT_BATCH_QUEUE_SIZE Default batch queue size (max batches count to limit memory usage).- See Also:
- Constant Field Values
 
 - 
DFLT_THREADS_COUNTpublic static final int DFLT_THREADS_COUNT Default number of working threads (equal to the number of available processors).
 
- 
 - 
Method Detail- 
inputIteratorprotected abstract Iterator<I> inputIterator(@Nullable @Nullable Object... args) throws javax.cache.integration.CacheLoaderException Returns iterator of input records.Note that returned iterator doesn't have to be thread-safe. Thus it could operate on raw streams, DB connections, etc. without additional synchronization. - Parameters:
- args- Arguments passes into- IgniteCache.loadCache(IgniteBiPredicate, Object...)method.
- Returns:
- Iterator over input records.
- Throws:
- javax.cache.integration.CacheLoaderException- If iterator can't be created with the given arguments.
 
 - 
parse@Nullable protected abstract @Nullable IgniteBiTuple<K,V> parse(I rec, @Nullable @Nullable Object... args) This method should transform raw data records into valid key-value pairs to be stored into cache.If nullis returned then this record will be just skipped.- Parameters:
- rec- A raw data record.
- args- Arguments passed into- IgniteCache.loadCache(IgniteBiPredicate, Object...)method.
- Returns:
- Cache entry to be saved in cache or nullif no entry could be produced from this record.
 
 - 
loadCachepublic void loadCache(IgniteBiInClosure<K,V> c, @Nullable @Nullable Object... args) Loads all values from underlying persistent storage. Note that keys are not passed, so it is up to implementation to figure out what to load. This method is called wheneverIgniteCache.loadCache(IgniteBiPredicate, Object...)method is invoked which is usually to preload the cache from persistent storage.This method is optional, and cache implementation does not depend on this method to do anything. Default implementation of this method in CacheStoreAdapterdoes nothing.For every loaded value method IgniteBiInClosure.apply(Object, Object)should be called on the passed in closure. The closure will then make sure that the loaded value is stored in cache.- Specified by:
- loadCachein interface- CacheStore<K,V>
- Parameters:
- c- Closure for loaded values.
- args- Arguments passes into- IgniteCache.loadCache(IgniteBiPredicate, Object...)method.
 
 - 
getBatchSizepublic int getBatchSize() Returns batch size.- Returns:
- Batch size.
 
 - 
setBatchSizepublic void setBatchSize(int batchSize) Sets batch size.- Parameters:
- batchSize- Batch size.
 
 - 
getBatchQueueSizepublic int getBatchQueueSize() Returns batch queue size.- Returns:
- Batch queue size.
 
 - 
setBatchQueueSizepublic void setBatchQueueSize(int batchQueueSize) Sets batch queue size.- Parameters:
- batchQueueSize- Batch queue size.
 
 - 
getThreadsCountpublic int getThreadsCount() Returns number of worker threads.- Returns:
- Number of worker threads.
 
 - 
setThreadsCountpublic void setThreadsCount(int threadsCnt) Sets number of worker threads.- Parameters:
- threadsCnt- Number of worker threads.
 
 - 
writeAllpublic void writeAll(Collection<javax.cache.Cache.Entry<? extends K,? extends V>> entries) 
 - 
deletepublic void delete(Object key) 
 - 
deleteAllpublic void deleteAll(Collection<?> keys) 
 - 
sessionEndpublic void sessionEnd(boolean commit) Tells store to commit or rollback a transaction depending on the value of the'commit'parameter.- Specified by:
- sessionEndin interface- CacheStore<K,V>
- Parameters:
- commit-- Trueif transaction should commit,- falsefor rollback.
 
 
- 
 
-