gxzookeeper

package
v1.11.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2021 License: Apache-2.0 Imports: 7 Imported by: 31

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilZkClientConn no conn error
	ErrNilZkClientConn = perrors.New("zookeeper Client{conn} is nil")
	// ErrNilChildren no children error
	ErrNilChildren = perrors.Errorf("has none children")
	// ErrNilNode no node error
	ErrNilNode = perrors.Errorf("node does not exist")
)

Functions

func StateToString

func StateToString(state zk.State) string

StateToString will transfer zk state to string

func WithZkEventHandler

func WithZkEventHandler(handler ZkEventHandler) zkClientOption

WithZkEventHandler sets zk Client event

func WithZkTimeOut

func WithZkTimeOut(t time.Duration) zkClientOption

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

func WithZkName

func WithZkName(name string) Option

WithZkName sets zk Client name

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

func (z *ZookeeperClient) GetChildrenW(path string) ([]string, <-chan zk.Event, error)

GetChildrenW gets children watch by @path

func (*ZookeeperClient) GetContent

func (z *ZookeeperClient) GetContent(zkPath string) ([]byte, *zk.Stat, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL