Class CuratorWrapper

java.lang.Object
com.yahoo.component.AbstractComponent
com.yahoo.vespa.curator.CuratorWrapper
All Implemented Interfaces:
com.yahoo.component.Component, com.yahoo.component.Deconstructable, VespaCurator, Comparable<com.yahoo.component.Component>

public class CuratorWrapper extends com.yahoo.component.AbstractComponent implements VespaCurator
Implementation of VespaCurator which delegates to a Curator. This prefixes all paths with "/user", to ensure separation with system ZK usage.
Author:
jonmv
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.yahoo.vespa.curator.api.VespaCurator

    VespaCurator.Data, VespaCurator.Meta, VespaCurator.SingletonWorker
  • Field Summary

    Fields inherited from class com.yahoo.component.AbstractComponent

    isDeconstructable
  • Constructor Summary

    Constructors
    Constructor
    Description
    CuratorWrapper(Curator curator, com.yahoo.jdisc.Metric metric)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    delete(com.yahoo.path.Path path)
    Deletes the node at the given path.
    boolean
    delete(com.yahoo.path.Path path, int expectedVersion)
    Atomically compares the version in the stat of the node at the given path, with the expected version, and then: if they are equal, attempts the delete operation (see VespaCurator.delete(Path)), and returns true; otherwise, returns false.
    void
    deleteAll(com.yahoo.path.Path path)
    Recursively deletes any node at the given path, and any children it may have.
    boolean
    isActive(String singletonId)
    Whether this container currently holds the exclusive lease for activation of singletons with this ID.
    list(com.yahoo.path.Path path)
    Lists the children of the node at the given path, or throws if there is no node at that path.
    lock(com.yahoo.path.Path path, Duration timeout)
    Creates and acquires a re-entrant lock with the given path.
    read(com.yahoo.path.Path path)
    Returns the content and stat for the node at the given path, or empty if no node exists at that path.
    void
    Register the singleton with the framework, so it may become active.
    stat(com.yahoo.path.Path path)
    Returns the stat for the node at the given path, or empty if no node exists at that path.
    void
    Unregister with the framework, so this singleton may no longer be active, and returns
    write(com.yahoo.path.Path path, byte[] data)
    Writes the given data to a node at the given path, creating it and its parents as needed, and returns the stat of the modified node.
    write(com.yahoo.path.Path path, byte[] data, int expectedVersion)
    Atomically compares the version in the stat of the node at the given path, with the expected version, and then: if they are equal, attempts the write operation (see VespaCurator.write(Path, byte[])); otherwise, return empty.

    Methods inherited from class com.yahoo.component.AbstractComponent

    clone, compareTo, getClassName, getId, getIdString, hasInitializedId, initId, isDeconstructable, setIsDeconstructable, toString

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CuratorWrapper

      @Inject public CuratorWrapper(Curator curator, com.yahoo.jdisc.Metric metric)
  • Method Details

    • stat

      public Optional<VespaCurator.Meta> stat(com.yahoo.path.Path path)
      Description copied from interface: VespaCurator
      Returns the stat for the node at the given path, or empty if no node exists at that path.
      Specified by:
      stat in interface VespaCurator
    • read

      public Optional<VespaCurator.Data> read(com.yahoo.path.Path path)
      Description copied from interface: VespaCurator
      Returns the content and stat for the node at the given path, or empty if no node exists at that path.
      Specified by:
      read in interface VespaCurator
    • write

      public VespaCurator.Meta write(com.yahoo.path.Path path, byte[] data)
      Description copied from interface: VespaCurator
      Writes the given data to a node at the given path, creating it and its parents as needed, and returns the stat of the modified node. Failure to write, due to connection loss, is retried a limited number of times.
      Specified by:
      write in interface VespaCurator
    • write

      public Optional<VespaCurator.Meta> write(com.yahoo.path.Path path, byte[] data, int expectedVersion)
      Description copied from interface: VespaCurator
      Atomically compares the version in the stat of the node at the given path, with the expected version, and then: if they are equal, attempts the write operation (see VespaCurator.write(Path, byte[])); otherwise, return empty.
      Specified by:
      write in interface VespaCurator
    • deleteAll

      public void deleteAll(com.yahoo.path.Path path)
      Description copied from interface: VespaCurator
      Recursively deletes any node at the given path, and any children it may have.
      Specified by:
      deleteAll in interface VespaCurator
    • delete

      public void delete(com.yahoo.path.Path path)
      Description copied from interface: VespaCurator
      Deletes the node at the given path. Failres due to connection loss are retried a limited number of times.
      Specified by:
      delete in interface VespaCurator
    • delete

      public boolean delete(com.yahoo.path.Path path, int expectedVersion)
      Description copied from interface: VespaCurator
      Atomically compares the version in the stat of the node at the given path, with the expected version, and then: if they are equal, attempts the delete operation (see VespaCurator.delete(Path)), and returns true; otherwise, returns false.
      Specified by:
      delete in interface VespaCurator
    • list

      public List<String> list(com.yahoo.path.Path path)
      Description copied from interface: VespaCurator
      Lists the children of the node at the given path, or throws if there is no node at that path.
      Specified by:
      list in interface VespaCurator
    • lock

      public AutoCloseable lock(com.yahoo.path.Path path, Duration timeout)
      Description copied from interface: VespaCurator
      Creates and acquires a re-entrant lock with the given path. This blocks until the lock is acquired or timeout elapses.
      Specified by:
      lock in interface VespaCurator
    • register

      public void register(VespaCurator.SingletonWorker singleton, Duration timeout)
      Description copied from interface: VespaCurator
      Register the singleton with the framework, so it may become active.

      Call this after construction of the singleton, typically during component construction!

      • 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.
      Specified by:
      register in interface VespaCurator
    • unregister

      public void unregister(VespaCurator.SingletonWorker singleton, Duration timeout)
      Description copied from interface: VespaCurator
      Unregister with the framework, so this singleton may no longer be active, and returns

      Call this before deconstruction of the singleton, typically during component deconstruction!

      • 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.
      Specified by:
      unregister in interface VespaCurator
    • isActive

      public boolean isActive(String singletonId)
      Description copied from interface: VespaCurator
      Whether this container currently holds the exclusive lease for activation of singletons with this ID.
      Specified by:
      isActive in interface VespaCurator
    • deconstruct

      public void deconstruct()
      Specified by:
      deconstruct in interface com.yahoo.component.Deconstructable
      Overrides:
      deconstruct in class com.yahoo.component.AbstractComponent