Class AbstractSingletonWorker

java.lang.Object
com.yahoo.vespa.curator.api.AbstractSingletonWorker
All Implemented Interfaces:
VespaCurator.SingletonWorker

public abstract class AbstractSingletonWorker extends Object implements VespaCurator.SingletonWorker
Super-class for implementations of VespaCurator.SingletonWorker. Users should call VespaCurator.registerSingleton(java.lang.String, com.yahoo.vespa.curator.api.VespaCurator.SingletonWorker) at construction, and VespaCurator.unregisterSingleton(com.yahoo.vespa.curator.api.VespaCurator.SingletonWorker) at deconstruction. If this fails activation on registration, it will immediately unregister as well, before propagating the error. Consequently, registering this on construction will allow detecting a failed component generation, and instead retain the previous generation, provided enough verification is done in VespaCurator.SingletonWorker.activate(). The default ID to use with registration is the concrete class name, e.g., my.example.Singleton.
Author:
jonmv
  • Constructor Details

    • AbstractSingletonWorker

      public AbstractSingletonWorker()
  • Method Details

    • id

      public String id()
      The singleton ID to use when registering this with a VespaCurator. At most one singleton worker with the given ID will be active, in the cluster, at any time. VespaCurator.isActive(String) may be polled to see whether this container is currently allowed to have an active singleton with the given ID.
    • register

      public final void register(VespaCurator curator, Duration timeout)
      Call this at the end of construction of the owner of this. 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.
    • unregister

      public final void unregister(Duration timeout)
      Call this at the start of deconstruction of the owner of this!

      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.