From 3144aec4cff50f200115c8ed06fa34594e7f3026 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 7 Feb 2022 15:17:50 +0100 Subject: Throw exception if subscriber is invoked after it's closed --- config/abi-spec.json | 11 +++++++++++ .../java/com/yahoo/config/subscription/ConfigSubscriber.java | 6 +++++- .../yahoo/config/subscription/SubscriberClosedException.java | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 config/src/main/java/com/yahoo/config/subscription/SubscriberClosedException.java (limited to 'config') diff --git a/config/abi-spec.json b/config/abi-spec.json index 844835ae1c5..e94749cfba8 100644 --- a/config/abi-spec.json +++ b/config/abi-spec.json @@ -297,5 +297,16 @@ "fields": [ "public final java.lang.String payload" ] + }, + "com.yahoo.config.subscription.SubscriberClosedException": { + "superClass": "java.lang.RuntimeException", + "interfaces": [], + "attributes": [ + "public" + ], + "methods": [ + "public void ()" + ], + "fields": [] } } \ No newline at end of file diff --git a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java index de5eeb5649c..a89d60108ac 100644 --- a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java +++ b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java @@ -156,6 +156,7 @@ public class ConfigSubscriber implements AutoCloseable { * false if this is for reconfiguration * @return true if a config/reconfig of your system should happen * @throws ConfigInterruptedException if thread performing this call interrupted. + * @throws SubscriberClosedException if subscriber is closed */ public boolean nextConfig(boolean isInitializing) { return nextConfig(TimingValues.defaultNextConfigTimeout, isInitializing); @@ -187,6 +188,7 @@ public class ConfigSubscriber implements AutoCloseable { * false if this is for reconfiguration * @return true if a config/reconfig of your system should happen * @throws ConfigInterruptedException if thread performing this call interrupted. + * @throws SubscriberClosedException if subscriber is closed */ public boolean nextConfig(long timeoutMillis, boolean isInitializing) { return acquireSnapshot(timeoutMillis, true, isInitializing); @@ -218,6 +220,7 @@ public class ConfigSubscriber implements AutoCloseable { * false if this is for reconfiguration * @return true if generations for all configs have been updated. * @throws ConfigInterruptedException if thread performing this call interrupted. + * @throws SubscriberClosedException if subscriber is closed */ public boolean nextGeneration(boolean isInitializing) { return nextGeneration(TimingValues.defaultNextConfigTimeout, isInitializing); @@ -249,6 +252,7 @@ public class ConfigSubscriber implements AutoCloseable { * false if this is for reconfiguration * @return true if generations for all configs have been updated. * @throws ConfigInterruptedException if thread performing this call interrupted. + * @throws SubscriberClosedException if subscriber is closed */ public boolean nextGeneration(long timeoutMillis, boolean isInitializing) { return acquireSnapshot(timeoutMillis, false, isInitializing); @@ -271,7 +275,7 @@ public class ConfigSubscriber implements AutoCloseable { private boolean acquireSnapshot(long timeoutInMillis, boolean requireChange, boolean isInitializing) { boolean applyOnRestartOnly; synchronized (monitor) { - if (state == State.CLOSED) return false; + if (state == State.CLOSED) throw new SubscriberClosedException(); state = State.FROZEN; applyOnRestartOnly = applyOnRestart; } diff --git a/config/src/main/java/com/yahoo/config/subscription/SubscriberClosedException.java b/config/src/main/java/com/yahoo/config/subscription/SubscriberClosedException.java new file mode 100644 index 00000000000..f7051ab1b38 --- /dev/null +++ b/config/src/main/java/com/yahoo/config/subscription/SubscriberClosedException.java @@ -0,0 +1,11 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.subscription; + +/** + * Thrown when {@link ConfigSubscriber} is closed + * + * @author bjorncs + * @deprecated Will be removed in Vespa 8. Only for internal use. + */ +@Deprecated(forRemoval = true, since = "7") +public class SubscriberClosedException extends RuntimeException {} -- cgit v1.2.3