From dbf4100c71035245c7924ee60ad5038c5a825446 Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Thu, 31 Oct 2024 09:32:55 +0100 Subject: [PATCH] Separate blocking shutdown Separate unlocking CountDownLatch to shutdownBlocking() to avoid interaction with CountDownLatch for users who do not call blocking start. JIRA: LIGHTY-299 Signed-off-by: Ivan Hrasko --- .../controller/api/AbstractLightyModule.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/AbstractLightyModule.java b/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/AbstractLightyModule.java index add9cd750..50d29da11 100644 --- a/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/AbstractLightyModule.java +++ b/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/AbstractLightyModule.java @@ -193,7 +193,6 @@ public synchronized ListenableFuture shutdown() { @Override public final boolean shutdown(final long duration, final TimeUnit unit) { try { - shutdownLatch.countDown(); final var stopSuccess = shutdown().get(duration, unit); if (stopSuccess) { LOG.info("LightyModule {} stopped successfully!", getClass().getSimpleName()); @@ -209,4 +208,20 @@ public final boolean shutdown(final long duration, final TimeUnit unit) { } return false; } + + /** + * Invoke blocking shutdown after blocking start. + * + *

+ * Release CountDownLatch locking this thread and shutdown. + * @param duration duration to wait for shutdown to complete + * @param unit {@link TimeUnit} of {@code duration} + * @return {@code boolean} indicating shutdown sucess + * @deprecated Use {@code shutdown()} or {@code shutdown(duration, unit)} instead in case you want blocking shutdown. + */ + @Deprecated(forRemoval = true) + public final boolean shutdownBlocking(final long duration, final TimeUnit unit) { + shutdownLatch.countDown(); + return shutdown(duration, unit); + } }