Callable: Replace classes with lambda expression

In Java 8 Callable is functional interface and can be replaced with
lambda expressions.

Change-Id: I32907f32c9dc3f394da64f22c384e8f3c33670d4
This commit is contained in:
David Ostrovsky
2017-03-26 21:03:32 +02:00
parent baf902fae0
commit bfa7a2f0a7
15 changed files with 160 additions and 276 deletions

View File

@@ -20,7 +20,6 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
@@ -245,47 +244,26 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
}
ListenableFuture<?> insert(final Document doc) {
return submit(
new Callable<Long>() {
@Override
public Long call() throws IOException, InterruptedException {
return writer.addDocument(doc);
}
});
return submit(() -> writer.addDocument(doc));
}
ListenableFuture<?> replace(final Term term, final Document doc) {
return submit(
new Callable<Long>() {
@Override
public Long call() throws IOException, InterruptedException {
return writer.updateDocument(term, doc);
}
});
return submit(() -> writer.updateDocument(term, doc));
}
ListenableFuture<?> delete(final Term term) {
return submit(
new Callable<Long>() {
@Override
public Long call() throws IOException, InterruptedException {
return writer.deleteDocuments(term);
}
});
return submit(() -> writer.deleteDocuments(term));
}
private ListenableFuture<?> submit(Callable<Long> task) {
ListenableFuture<Long> future = Futures.nonCancellationPropagating(writerThread.submit(task));
return Futures.transformAsync(
future,
new AsyncFunction<Long, Void>() {
@Override
public ListenableFuture<Void> apply(Long gen) throws InterruptedException {
// Tell the reopen thread a future is waiting on this
// generation so it uses the min stale time when refreshing.
reopenThread.waitForGeneration(gen, 0);
return new NrtFuture(gen);
}
gen -> {
// Tell the reopen thread a future is waiting on this
// generation so it uses the min stale time when refreshing.
reopenThread.waitForGeneration(gen, 0);
return new NrtFuture(gen);
},
directExecutor());
}