All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.hotrod.SyncToAsyncEntryProcessor Maven / Gradle / Ivy

The newest version!
package org.infinispan.hotrod;

import java.util.concurrent.Flow;

import org.infinispan.api.async.AsyncCacheEntryProcessor;
import org.infinispan.api.common.MutableCacheEntry;
import org.infinispan.api.common.process.CacheEntryProcessorContext;
import org.infinispan.api.common.process.CacheEntryProcessorResult;
import org.infinispan.api.sync.SyncCacheEntryProcessor;
import org.reactivestreams.FlowAdapters;

import io.reactivex.rxjava3.core.Flowable;

public class SyncToAsyncEntryProcessor implements AsyncCacheEntryProcessor {
   private final SyncCacheEntryProcessor syncCacheEntryProcessor;

   public SyncToAsyncEntryProcessor(SyncCacheEntryProcessor syncCacheEntryProcessor) {
      this.syncCacheEntryProcessor = syncCacheEntryProcessor;
   }

   @Override
   public Flow.Publisher> process(Flow.Publisher> entries, CacheEntryProcessorContext context) {
      Flowable> flowable = Flowable.fromPublisher(FlowAdapters.toPublisher(entries))
            .map(e -> {
               try {
                  return CacheEntryProcessorResult.onResult(e.key(), syncCacheEntryProcessor.process(e, context));
               } catch (Throwable t) {
                  return CacheEntryProcessorResult.onError(e.key(), t);
               }
            });
      return FlowAdapters.toFlowPublisher(flowable);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy