2016-03-01 17:47:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-03-25 12:21:10 +00:00
|
|
|
#include <zkutil/Common.h>
|
2016-03-01 17:47:53 +00:00
|
|
|
#include <string>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace zkutil
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Single distributed barrier for ZooKeeper.
|
|
|
|
*/
|
|
|
|
class SingleBarrier final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using CancellationHook = std::function<void()>;
|
|
|
|
|
|
|
|
public:
|
2016-03-25 12:21:10 +00:00
|
|
|
SingleBarrier(GetZooKeeper get_zookeeper_, const std::string & path_, size_t counter_);
|
2016-03-01 17:47:53 +00:00
|
|
|
|
|
|
|
SingleBarrier(const SingleBarrier &) = delete;
|
|
|
|
SingleBarrier & operator=(const SingleBarrier &) = delete;
|
|
|
|
|
|
|
|
SingleBarrier(SingleBarrier &&) = default;
|
|
|
|
SingleBarrier & operator=(SingleBarrier &&) = default;
|
|
|
|
|
|
|
|
/// Register a function that checks whether barrier operation should be cancelled.
|
|
|
|
void setCancellationHook(CancellationHook cancellation_hook_);
|
|
|
|
|
|
|
|
void enter(uint64_t timeout = 0);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void abortIfRequested();
|
|
|
|
|
|
|
|
private:
|
2016-03-25 12:21:10 +00:00
|
|
|
GetZooKeeper get_zookeeper;
|
2016-05-28 17:31:50 +00:00
|
|
|
EventPtr event = std::make_shared<Poco::Event>();
|
2016-03-01 17:47:53 +00:00
|
|
|
CancellationHook cancellation_hook;
|
|
|
|
std::string path;
|
2016-03-25 11:48:45 +00:00
|
|
|
std::string token;
|
2016-03-01 17:47:53 +00:00
|
|
|
size_t counter;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|