Documentation ¶
Index ¶
- Variables
- func StateToString(state zk.State) string
- func WithZkEventHandler(handler ZkEventHandler) zkClientOption
- func WithZkTimeOut(t time.Duration) zkClientOption
- type DefaultHandler
- type Option
- type ZkEventHandler
- type ZookeeperClient
- func (z *ZookeeperClient) Close()
- func (z *ZookeeperClient) Create(basePath string) error
- func (z *ZookeeperClient) CreateTempWithValue(basePath string, value []byte) error
- func (z *ZookeeperClient) CreateWithValue(basePath string, value []byte) error
- func (z *ZookeeperClient) Delete(basePath string) error
- func (z *ZookeeperClient) ExistW(zkPath string) (<-chan zk.Event, error)
- func (z *ZookeeperClient) GetChildren(path string) ([]string, error)
- func (z *ZookeeperClient) GetChildrenW(path string) ([]string, <-chan zk.Event, error)
- func (z *ZookeeperClient) GetContent(zkPath string) ([]byte, *zk.Stat, error)
- func (z *ZookeeperClient) GetEventHandler() ZkEventHandler
- func (z *ZookeeperClient) Reconnect() <-chan struct{}
- func (z *ZookeeperClient) RegisterEvent(zkPath string, event *chan struct{})
- func (z *ZookeeperClient) RegisterTemp(basePath string, node string) (string, error)
- func (z *ZookeeperClient) RegisterTempSeq(basePath string, data []byte) (string, error)
- func (z *ZookeeperClient) SetContent(zkPath string, content []byte, version int32) (*zk.Stat, error)
- func (z *ZookeeperClient) UnregisterEvent(zkPath string, event *chan struct{})
- func (z *ZookeeperClient) ZkConnValid() bool
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func StateToString ¶
StateToString will transfer zk state to string
func WithZkEventHandler ¶
func WithZkEventHandler(handler ZkEventHandler) zkClientOption
WithZkEventHandler sets zk Client event
func WithZkTimeOut ¶
WithZkTimeOut sets zk Client timeout
Types ¶
type DefaultHandler ¶
type DefaultHandler struct{}
DefaultHandler is default handler for zk event
func (*DefaultHandler) HandleZkEvent ¶
func (d *DefaultHandler) HandleZkEvent(z *ZookeeperClient)
HandleZkEvent handles zookeeper events
type Option ¶
type Option func(*options)
Option will define a function of handling Options
func WithTestCluster ¶
func WithTestCluster(ts *zk.TestCluster) Option
WithTestCluster sets test cluster for zk Client
type ZkEventHandler ¶
type ZkEventHandler interface {
HandleZkEvent(z *ZookeeperClient)
}
ZkEventHandler interface
type ZookeeperClient ¶
type ZookeeperClient struct { ZkAddrs []string sync.RWMutex // for conn Conn *zk.Conn Timeout time.Duration Wait sync.WaitGroup Session <-chan zk.Event // contains filtered or unexported fields }
ZookeeperClient represents zookeeper Client Configuration
func NewMockZookeeperClient ¶
func NewMockZookeeperClient(name string, timeout time.Duration, opts ...Option) (*zk.TestCluster, *ZookeeperClient, <-chan zk.Event, error)
NewMockZookeeperClient returns a mock Client instance
func NewZookeeperClient ¶
func NewZookeeperClient(name string, zkAddrs []string, share bool, opts ...zkClientOption) (*ZookeeperClient, error)
NewZookeeperClient will create a ZookeeperClient
func (*ZookeeperClient) Close ¶
func (z *ZookeeperClient) Close()
func (*ZookeeperClient) Create ¶
func (z *ZookeeperClient) Create(basePath string) error
Create will create the node recursively, which means that if the parent node is absent, it will create parent node first. And the value for the basePath is ""
func (*ZookeeperClient) CreateTempWithValue ¶
func (z *ZookeeperClient) CreateTempWithValue(basePath string, value []byte) error
CreateTempWithValue will create the node recursively, which means that if the parent node is absent, it will create parent node first,and set value in last child path If the path exist, it will update data
func (*ZookeeperClient) CreateWithValue ¶
func (z *ZookeeperClient) CreateWithValue(basePath string, value []byte) error
CreateWithValue will create the node recursively, which means that if the parent node is absent, it will create parent node first.
func (*ZookeeperClient) Delete ¶
func (z *ZookeeperClient) Delete(basePath string) error
Delete will delete basePath
func (*ZookeeperClient) ExistW ¶
func (z *ZookeeperClient) ExistW(zkPath string) (<-chan zk.Event, error)
ExistW to judge watch whether it exists or not by @zkPath
func (*ZookeeperClient) GetChildren ¶
func (z *ZookeeperClient) GetChildren(path string) ([]string, error)
GetChildren gets children by @path
func (*ZookeeperClient) GetChildrenW ¶
GetChildrenW gets children watch by @path
func (*ZookeeperClient) GetContent ¶
GetContent gets content by @zkPath
func (*ZookeeperClient) GetEventHandler ¶
func (z *ZookeeperClient) GetEventHandler() ZkEventHandler
GetEventHandler gets zookeeper event handler
func (*ZookeeperClient) Reconnect ¶
func (z *ZookeeperClient) Reconnect() <-chan struct{}
Reconnect gets zookeeper reconnect event
func (*ZookeeperClient) RegisterEvent ¶
func (z *ZookeeperClient) RegisterEvent(zkPath string, event *chan struct{})
RegisterEvent registers zookeeper events
func (*ZookeeperClient) RegisterTemp ¶
func (z *ZookeeperClient) RegisterTemp(basePath string, node string) (string, error)
RegisterTemp registers temporary node by @basePath and @node
func (*ZookeeperClient) RegisterTempSeq ¶
func (z *ZookeeperClient) RegisterTempSeq(basePath string, data []byte) (string, error)
RegisterTempSeq register temporary sequence node by @basePath and @data
func (*ZookeeperClient) SetContent ¶
func (z *ZookeeperClient) SetContent(zkPath string, content []byte, version int32) (*zk.Stat, error)
SetContent set content of zkPath
func (*ZookeeperClient) UnregisterEvent ¶
func (z *ZookeeperClient) UnregisterEvent(zkPath string, event *chan struct{})
UnregisterEvent unregisters zookeeper events
func (*ZookeeperClient) ZkConnValid ¶
func (z *ZookeeperClient) ZkConnValid() bool
ZkConnValid validates zookeeper connection