summaryrefslogtreecommitdiffstats
path: root/zkfacade
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2022-10-10 10:54:21 +0200
committerjonmv <venstad@gmail.com>2022-10-10 12:33:57 +0200
commitb121927ba9f5252cb2adc0b7bee1fda44b31841e (patch)
tree17089dda76717f15b8a062d040f38cec99b30ba2 /zkfacade
parent762483d3e51b899a6b24f7675a861c0f6d0f2a59 (diff)
No inheritance on AbstractComponent
Diffstat (limited to 'zkfacade')
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/api/AbstractSingletonWorker.java13
-rw-r--r--zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorWrapperTest.java14
2 files changed, 14 insertions, 13 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/api/AbstractSingletonWorker.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/api/AbstractSingletonWorker.java
index be0b01e732b..dc0540e73c5 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/api/AbstractSingletonWorker.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/api/AbstractSingletonWorker.java
@@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicReference;
*
* @author jonmv
*/
-public abstract class AbstractSingletonWorker extends AbstractComponent implements SingletonWorker {
+public abstract class AbstractSingletonWorker implements SingletonWorker {
private final AtomicReference<VespaCurator> owner = new AtomicReference<>();
@@ -33,16 +33,16 @@ public abstract class AbstractSingletonWorker extends AbstractComponent implemen
* {@link VespaCurator#isActive(String)} may be polled to see whether this container is currently
* allowed to have an active singleton with the given ID.
*/
- protected String id() { return getClass().getName(); }
+ public String id() { return getClass().getName(); }
/**
- * Call this at the end of construction of the child or owner.
+ * <strong>Call this at the end of construction of the owner of this.</strong>
* If this activates the singleton, this happens synchronously, and any errors are propagated here.
* If this replaces an already active singleton, its deactivation is also called, prior to activation of this.
* If (de)activation is not complete within the given timeout, a timeout exception is thrown.
* If an error occurs (due to failed activation), unregistration is automatically attempted, with the same timeout.
*/
- protected final void register(VespaCurator curator, Duration timeout) {
+ public final void register(VespaCurator curator, Duration timeout) {
if ( ! owner.compareAndSet(null, curator)) {
throw new IllegalArgumentException(this + " is already registered with " + owner.get());
}
@@ -61,12 +61,13 @@ public abstract class AbstractSingletonWorker extends AbstractComponent implemen
}
/**
- * Call this at the start of deconstruction of the child!
+ * <strong>Call this at the start of deconstruction of the owner of this!</strong>
+ * <p>
* If this singleton is active, deactivation will be called synchronously, and errors propagated here.
* If this also triggers activation of a new singleton, its activation is called after deactivation of this.
* If (de)activation is not complete within the given timeout, a timeout exception is thrown.
*/
- protected final void unregister(Duration timeout) {
+ public final void unregister(Duration timeout) {
VespaCurator curator = owner.getAndSet(null);
if (curator == null) {
throw new IllegalArgumentException(this + " was not registered with any owners");
diff --git a/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorWrapperTest.java b/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorWrapperTest.java
index 6767dd7e1a8..131222e62f8 100644
--- a/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorWrapperTest.java
+++ b/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorWrapperTest.java
@@ -88,7 +88,7 @@ public class CuratorWrapperTest {
assertTrue(singleton.isActive);
assertTrue(wrapped.exists(lockPath));
assertTrue(curator.isActive(singleton.id()));
- singleton.deconstruct();
+ singleton.shutdown();
assertFalse(singleton.isActive);
// ... and deactivated as a result of unregistering again.
@@ -143,12 +143,12 @@ public class CuratorWrapperTest {
assertFalse(newSingleton.isActive);
assertFalse(singleton.isActive);
- singleton.deconstruct();
+ singleton.shutdown();
assertTrue(newerSingleton.isActive);
assertFalse(newSingleton.isActive);
assertFalse(singleton.isActive);
- newerSingleton.deconstruct();
+ newerSingleton.shutdown();
assertFalse(newerSingleton.isActive);
assertTrue(newSingleton.isActive);
assertFalse(singleton.isActive);
@@ -182,7 +182,7 @@ public class CuratorWrapperTest {
stunning.arriveAndAwaitAdvance(); // Failing component is done cleaning up after itself.
assertTrue(newSingleton.isActive);
assertEquals("failed to register failing singleton", thrownMessage.get());
- newSingleton.deconstruct();
+ newSingleton.shutdown();
curator.deconstruct();
}
@@ -226,7 +226,7 @@ public class CuratorWrapperTest {
singleton.phaser.arriveAndAwaitAdvance();
assertTrue(singleton.isActive);
singleton.phaser.arriveAndDeregister();
- singleton.deconstruct();
+ singleton.shutdown();
assertFalse(singleton.isActive);
curator.deconstruct();
@@ -237,10 +237,10 @@ public class CuratorWrapperTest {
Singleton(VespaCurator curator) { register(curator, Duration.ofSeconds(2)); }
boolean isActive;
Phaser phaser = new Phaser(1);
- @Override protected String id() { return "singleton"; } // ... lest anonymous subclasses get different IDs ... ƪ(`▿▿▿▿´ƪ)
+ @Override public String id() { return "singleton"; } // ... lest anonymous subclasses get different IDs ... ƪ(`▿▿▿▿´ƪ)
@Override public void activate() { isActive = true; phaser.arriveAndAwaitAdvance(); }
@Override public void deactivate() { isActive = false; phaser.arriveAndAwaitAdvance(); }
- @Override public void deconstruct() { unregister(Duration.ofSeconds(2)); }
+ public void shutdown() { unregister(Duration.ofSeconds(2)); }
}
}