Apache Curator Recipes

Curator实现了 ZooKeeper recipes文档中列出的所有技巧(除了两段提交two phase commit)。点击下面的技巧的名字可以查看详细信息。


  • Leader Latch - 在分布式计算中, leader选举是在几台节点中指派单一的进程作为任务组织者的过程。在任务开始前, 所有的网络节点都不知道哪一个节点会作为任务的leader或coordinator. 一旦leader选举算法被执行, 网络中的每个节点都将知道一个特别的唯一的节点作为任务leader.

  • Leader Election - 初始的leader选举实现.



  • Barrier - 分布式的barriers。 会阻塞全部的节点的处理,直到条件满足,所有的节点会继续执行.
  • Double Barrier - 双barrier 允许客户端在一个计算开始点和结束点保持同步。当足够的进程加入barrier, 进程开始它们的计算, 当所有的进程完成计算才离开.


  • Shared Counter - 管理一个共享的整数integer. 所有监控同一path的客户端都会得到最新的值(ZK的 一致性保证).
  • Distributed Atomic Long - 尝试原子增加的计数器首先它尝试乐观锁.如果失败,可选的InterProcessMutex会被采用. 不管是optimistic 还是 mutex, 重试机制都被用来尝试增加值.


  • Path Cache - Path Cache用来监控ZNode. Whenever a child is added, updated or removed, the Path Cache will change its state to contain the current set of children, the children's data and the children's state. Path caches in the Curator Framework are provided by the PathChildrenCache class. Changes to the path are passed to registered PathChildrenCacheListener instances.
  • Node Cache - A utility that attempts to keep the data from a node locally cached. This class will watch the node, respond to update/create/delete events, pull down the data, etc. You can register a listener that will get notified when changes occur.


  • Persistent Ephemeral Node - An ephemeral node that attempts to stay present in ZooKeeper, even through connection and session interruptions..


  • Distributed Queue - 分布式的ZK队列. Items put into the queue are guaranteed to be ordered (by means of ZK's PERSISTENTSEQUENTIAL node). If a single consumer takes items out of the queue, they will be ordered FIFO. If ordering is important, use a LeaderSelector to nominate a single consumer.
  • Distributed Id Queue - A version of DistributedQueue that allows IDs to be associated with queue items. Items can then be removed from the queue if needed.
  • Distributed Priority Queue - An implementation of the Distributed Priority Queue ZK recipe.
  • Distributed Delay Queue - An implementation of a Distributed Delay Queue.
  • Simple Distributed Queue - A drop-in replacement for the DistributedQueue that comes with the ZK distribution.