org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of infinispan-embedded-query
Show all versions of infinispan-embedded-query
Infinispan Embedded Query All-in-One module
The newest version!
package org.infinispan.query.impl.massindex;
import static org.infinispan.query.impl.massindex.MassIndexStrategyFactory.calculateStrategy;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import org.hibernate.search.engine.spi.EntityIndexBinding;
import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.spi.SearchIntegrator;
import org.hibernate.search.spi.impl.PojoIndexedTypeIdentifier;
import org.infinispan.AdvancedCache;
import org.infinispan.distexec.DefaultExecutorService;
import org.infinispan.distexec.DistributedExecutorService;
import org.infinispan.distexec.DistributedTask;
import org.infinispan.query.MassIndexer;
import org.infinispan.query.impl.massindex.MassIndexStrategy.CleanExecutionMode;
import org.infinispan.query.impl.massindex.MassIndexStrategy.FlushExecutionMode;
import org.infinispan.query.impl.massindex.MassIndexStrategy.IndexingExecutionMode;
import org.infinispan.query.logging.Log;
import org.infinispan.util.logging.LogFactory;
/**
* @author gustavonalle
* @since 7.1
*/
public class DistributedExecutorMassIndexer implements MassIndexer {
private static final Log LOG = LogFactory.getLog(DistributedExecutorMassIndexer.class, Log.class);
private final AdvancedCache cache;
private final SearchIntegrator searchIntegrator;
private final IndexUpdater indexUpdater;
private final DistributedExecutorService executor;
public DistributedExecutorMassIndexer(AdvancedCache cache, SearchIntegrator searchIntegrator) {
this.cache = cache;
this.searchIntegrator = searchIntegrator;
this.indexUpdater = new IndexUpdater(cache);
this.executor = new DefaultExecutorService(cache);
}
@Override
@SuppressWarnings("unchecked")
public void start() {
CompletableFuture executionResult = executeInternal(false);
executionResult.join();
}
@Override
public CompletableFuture startAsync() {
return executeInternal(true);
}
private void addFutureListToFutures(List> futures, List> futureList) {
futureList.forEach(f -> futures.add(f.exceptionally(t -> {
if (t instanceof InterruptedException) {
Thread.currentThread().interrupt();
return null;
} else if (t instanceof CompletionException) {
Throwable cause = t.getCause();
throw LOG.errorExecutingMassIndexer(cause);
} else {
throw LOG.errorExecutingMassIndexer(t);
}
})));
}
@Override
public CompletableFuture reindex(Object... keys) {
List> futures = new ArrayList<>();
Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy