Class PathChildrenAnnouncer

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

public class PathChildrenAnnouncer extends Object implements ServiceAnnouncer
The PathChildrenAnnouncer class manages the announcement of a node, and watches all child and sibling nodes under the specified path in a ZooKeeper ensemble. It monitors these nodes to ensure their existence and manage their lifecycle collectively.

This class uses Apache Curator's PathChildrenCache recipe under the hood to track all znodes under the specified node's parent. See NodeAnnouncer for an announcer that uses the NodeCache recipe instead.

  • Constructor Details

    • PathChildrenAnnouncer

      public PathChildrenAnnouncer(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 PathChildrenAnnouncer will create an ephemeral znode at the specified path, and uses its parent path to watch all the siblings and children znodes of your specified path. The watched nodes will always 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