diff options
author | gjoranv <gv@verizonmedia.com> | 2020-12-15 13:50:53 +0100 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2020-12-15 15:07:38 +0100 |
commit | 81d4a76511c3dfc19aed98b47153dcea95fd31fd (patch) | |
tree | 4dde9ec312997bdb700273b0f6d7da3f751c146e | |
parent | 79e8e0a9632002c6c7a3bb687820b896019c4ded (diff) |
Extract method for task waiting and exception handling.
-rw-r--r-- | container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java index 65a02d128fc..b33671d724d 100644 --- a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeoutException; import java.util.logging.Level; import org.osgi.framework.Bundle; @@ -86,22 +87,25 @@ public class Deconstructor implements ComponentDeconstructor { var task = executor.schedule(new DestructComponentTask(destructibleComponents, bundles), delay.getSeconds(), TimeUnit.SECONDS); if (mode.equals(Mode.SHUTDOWN)) { - // Wait for deconstruction to finish - try { - log.info("Waiting up to " + SHUTDOWN_DECONSTRUCT_TIMEOUT.toSeconds() + " seconds for all components to deconstruct."); - task.get(SHUTDOWN_DECONSTRUCT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - log.info("Interrupted while waiting for component deconstruction to finish."); - Thread.currentThread().interrupt(); - } catch (ExecutionException e) { - log.warning("Component deconstruction threw an exception: " + e.getMessage()); - } catch (TimeoutException e) { - log.warning("Component deconstruction timed out."); - } + waitFor(task, SHUTDOWN_DECONSTRUCT_TIMEOUT); } } } + private void waitFor(ScheduledFuture<?> task, Duration timeout) { + try { + log.info("Waiting up to " + timeout.toSeconds() + " seconds for all components to deconstruct."); + task.get(timeout.toMillis(), TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + log.info("Interrupted while waiting for component deconstruction to finish."); + Thread.currentThread().interrupt(); + } catch (ExecutionException e) { + log.warning("Component deconstruction threw an exception: " + e.getMessage()); + } catch (TimeoutException e) { + log.warning("Component deconstruction timed out."); + } + } + private static class DestructComponentTask implements Runnable { private final Random random = new Random(System.nanoTime()); |