Get rid of unnecessary functional interfaces Use standard functional interfaces instead. Change-Id: I08db0228077dfef1d3362cf9d64f2ce89af31c5f
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventLocks.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventLocks.java index bbff4ee..a0d344b 100644 --- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventLocks.java +++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventLocks.java
@@ -23,6 +23,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; public class IndexEventLocks { private static final FluentLogger log = FluentLogger.forEnclosingClass(); @@ -39,15 +40,15 @@ } public CompletableFuture<?> withLock( - IndexTask id, IndexCallFunction function, VoidFunction lockAcquireTimeoutCallback) { + IndexTask id, Supplier<CompletableFuture<?>> indexTask, Runnable lockAcquireTimeoutCallback) { String indexId = id.indexId(); Semaphore idSemaphore = getSemaphore(indexId); try { log.atFine().log("Trying to acquire %s", id); if (idSemaphore.tryAcquire(WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { log.atFine().log("Acquired %s", id); - return function - .invoke() + return indexTask + .get() .whenComplete( (result, error) -> { try { @@ -66,7 +67,7 @@ "Acquisition of the locking of %s timed out after %d msec: consider increasing the number of shards", indexId, WAIT_TIMEOUT_MS); log.atWarning().log("%s", timeoutMessage); - lockAcquireTimeoutCallback.invoke(); + lockAcquireTimeoutCallback.run(); CompletableFuture<?> failureFuture = new CompletableFuture<>(); failureFuture.completeExceptionally(new InterruptedException(timeoutMessage)); return failureFuture; @@ -82,14 +83,4 @@ protected Semaphore getSemaphore(String indexId) { return semaphores.get(indexId); } - - @FunctionalInterface - public interface VoidFunction { - void invoke(); - } - - @FunctionalInterface - public interface IndexCallFunction { - CompletableFuture<?> invoke(); - } }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java index 7c6a4f6..bf87e4d 100644 --- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java +++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/index/IndexEventHandlerTest.java
@@ -34,7 +34,6 @@ import com.ericsson.gerrit.plugins.highavailability.index.IndexEventHandler.IndexChangeTask; import com.ericsson.gerrit.plugins.highavailability.index.IndexEventHandler.IndexGroupTask; import com.ericsson.gerrit.plugins.highavailability.index.IndexEventHandler.IndexTask; -import com.ericsson.gerrit.plugins.highavailability.index.IndexEventLocks.VoidFunction; import com.google.gerrit.entities.Account; import com.google.gerrit.entities.AccountGroup; import com.google.gerrit.entities.Change; @@ -567,14 +566,11 @@ private IndexTask task; private CyclicBarrier testBarrier; private Supplier<T> successFunc; - private VoidFunction failureFunc; + private Runnable failureFunc; private CompletableFuture<T> future; public TestTask( - IndexTask task, - CyclicBarrier testBarrier, - Supplier<T> successFunc, - VoidFunction failureFunc) { + IndexTask task, CyclicBarrier testBarrier, Supplier<T> successFunc, Runnable failureFunc) { this.task = task; this.testBarrier = testBarrier; this.successFunc = successFunc; @@ -598,7 +594,7 @@ }), () -> { await(); - failureFunc.invoke(); + failureFunc.run(); }) .whenComplete( (v, t) -> {