Class NodeAnnouncer

java.lang.Object
org.apache.druid.curator.announcement.NodeAnnouncer
All Implemented Interfaces:
ServiceAnnouncer

public class NodeAnnouncer extends Object implements ServiceAnnouncer
The NodeAnnouncer class is responsible for announcing a single node in a ZooKeeper ensemble. It creates an ephemeral node at a specified path and monitors its existence to ensure that it remains active until it is explicitly unannounced or the object is closed.

This class uses Apache Curator's NodeCache recipe under the hood to track a single node, along with all of its parent's status. See PathChildrenAnnouncer for an announcer that uses the PathChildrenCache recipe instead.

  • Constructor Details

    • NodeAnnouncer

      public NodeAnnouncer(org.apache.curator.framework.CuratorFramework curator, ExecutorService exec)
  • Method Details

    • start

      public void start()
      Specified by:
      start in interface ServiceAnnouncer
    • stop

      public void stop()
      Specified by:
      stop in interface ServiceAnnouncer
    • announce

      public void announce(String path, byte[] bytes)
      Overload of announce(String, byte[], boolean), but removes parent node of path after announcement.
      Specified by:
      announce in interface ServiceAnnouncer
    • announce

      public void announce(String path, byte[] bytes, boolean removeParentIfCreated)
      Announces the provided bytes at the given path.

      Announcement using NodeAnnouncer will create an ephemeral znode at the specified path, and listens for changes on your znode. Your znode will exist until it is unannounced, or until stop() is called.

      Specified by:
      announce in interface ServiceAnnouncer
      Parameters:
      path - The path to announce at
      bytes - The payload to announce
      removeParentIfCreated - remove parent of "path" if we had created that parent during announcement
    • update

      public void update(String path, byte[] bytes)
      Specified by:
      update in interface ServiceAnnouncer
    • unannounce

      public void unannounce(String path)
      Unannounces an announcement created at path. Note that if all announcements get removed, the Announcer will continue to have ZK watches on paths because clearing them out is a source of ugly race conditions.

      If you need to completely clear all the state of what is being watched and announced, stop() the Announcer.

      Specified by:
      unannounce in interface ServiceAnnouncer
      Parameters:
      path - the path to unannounce