Search in sources :

Example 1 with KeyFilter

use of org.infinispan.filter.KeyFilter in project indy by Commonjava.

the class StorageFileIO method process.

@Override
public void process(KeyFilter<? super String> filter, CacheLoaderTask<String, byte[]> task, Executor executor, boolean fetchValue, boolean fetchMetadata) {
    Path root = Paths.get(storageRoot);
    walkFiles((path -> {
        if (filter.accept(path.relativize(root).toString())) {
            executor.execute(() -> {
                if (Thread.currentThread().isInterrupted()) {
                    Logger logger = LoggerFactory.getLogger(getClass());
                    logger.debug("The cache-loader process thread is interrupted at the start. Bailing out.");
                    return;
                }
                try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(path.toFile())))) {
                    StorageFileEntry entry = new StorageFileEntry();
                    entry.load(in, fetchMetadata, fetchValue);
                    StorageFileTaskContext ctx = new StorageFileTaskContext();
                    task.processEntry(entry, ctx);
                } catch (ClassNotFoundException | IOException e) {
                    Logger logger = LoggerFactory.getLogger(getClass());
                    logger.error("Cannot read file: " + path, e);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    Logger logger = LoggerFactory.getLogger(getClass());
                    logger.debug("cache-loader process method interrupted on: " + path, e);
                }
            });
        }
    }));
}
Also used : Path(java.nio.file.Path) GZIPInputStream(java.util.zip.GZIPInputStream) AdvancedCacheLoader(org.infinispan.persistence.spi.AdvancedCacheLoader) LoggerFactory(org.slf4j.LoggerFactory) ObjectInputStream(java.io.ObjectInputStream) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectOutputStream(java.io.ObjectOutputStream) Path(java.nio.file.Path) Logger(org.slf4j.Logger) Properties(java.util.Properties) Executor(java.util.concurrent.Executor) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) AdvancedCacheWriter(org.infinispan.persistence.spi.AdvancedCacheWriter) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) KeyFilter(org.infinispan.filter.KeyFilter) MarshalledEntry(org.infinispan.marshall.core.MarshalledEntry) Paths(java.nio.file.Paths) InitializationContext(org.infinispan.persistence.spi.InitializationContext) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) Logger(org.slf4j.Logger) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Executor (java.util.concurrent.Executor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 Stream (java.util.stream.Stream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 FileUtils (org.apache.commons.io.FileUtils)1 StoreConfiguration (org.infinispan.configuration.cache.StoreConfiguration)1 KeyFilter (org.infinispan.filter.KeyFilter)1