xzk

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 8 Imported by: 1

README

clients

Documentation

Index

Constants

View Source
const (
	PERSISTENT            = iota // 持久化节点
	EPHEMERAL                    // 临时节点, 客户端session超时这类节点就会被自动删除
	PERSISTENT_SEQUENTIAL        // 顺序自动编号持久化节点,这种节点会根据当前已存在的节点数自动加 1
	EPHEMERAL_SEQUENTIAL         // 临时自动编号节点
)

Variables

View Source
var (
	EventChildrenNodeChangeNames = map[EventChildrenNodeChangeType]string{
		EventChildrenNodeDelete:   "EventChildrenNodeDelete",
		EventChildrenNodeIncrease: "EventChildrenNodeIncrease",
	}
)
View Source
var (
	EventCurrntNodeChangeNames = map[EventCurrentNodeChangeType]string{
		EventNodeDelete:     "EventNodeDelete",
		EventNodeDataChange: "EventNodeDataChange",
	}
)

Functions

This section is empty.

Types

type ChildrenChange

type ChildrenChange struct {
	OperateType EventChildrenNodeChangeType // 监控到子节点的操作类型: 目前只支持监控子节点的 增加 删除
	Path        string                      // 节点路径
}

type Event

type Event struct {
	Type   EventType
	State  zk.State
	Path   string
	Data   string
	Err    error
	Server string
}

type EventChildrenNodeChangeType

type EventChildrenNodeChangeType int32
const (
	EventChildrenNodeDelete EventChildrenNodeChangeType = iota
	EventChildrenNodeIncrease
)

func (EventChildrenNodeChangeType) String

type EventCurrentNodeChangeType

type EventCurrentNodeChangeType int32
const (
	EventNodeDelete EventCurrentNodeChangeType = iota
	EventNodeDataChange
)

func (EventCurrentNodeChangeType) String

type EventType

type EventType int32
const (
	EventRecoverEphemeralNodeFail    EventType = 1
	EventRecoverEphemeralNodeSuccess EventType = 2
	EventSession                     EventType = -1
	Unknown                          EventType = -2
)

type NodeChange

type NodeChange struct {
	OperateType EventCurrentNodeChangeType // 监控到的子节点的操作类型
	OldData     string                     // 节点改变前的值
	NewData     string                     // 节点改变后的值
	Path        string                     // 节点路径
}

type NodeDetail

type NodeDetail struct {
	Data string
	Acl  []zk.ACL
}

type Option

type Option struct {
	Name           string        // 客户端名称, 需要唯一
	Addr           []string      // 节点地址
	SessionTimeout time.Duration // 连接创建超时时间
}

type WatchChildrenResponse

type WatchChildrenResponse struct {
	ChildrenChangeInfo []*ChildrenChange
	Err                error
}

type WatchNodeResponse

type WatchNodeResponse struct {
	NodeChangeInfo *NodeChange
	Err            error
}

type ZookeeperProxy

type ZookeeperProxy struct {
	Opt  *Option
	Conn *zk.Conn
	// contains filtered or unexported fields
}

func New

func New(opt *Option) (*ZookeeperProxy, error)

func (*ZookeeperProxy) Close

func (z *ZookeeperProxy) Close() error

func (*ZookeeperProxy) CreateNode

func (z *ZookeeperProxy) CreateNode(path string, flag int32, data string) (string, error)

创建节点(拥有所有权限)

func (*ZookeeperProxy) CreateNodeParent

func (z *ZookeeperProxy) CreateNodeParent(path string, flags int32, data string) (string, error)

创建节点(包含父节点): 若要创建节点的父节点不存在,则把 父节点 和 需求节点都创建出来。 注: 所有新建的父节点的flags 为0 , 需求节点的flags为传入的 flags

func (*ZookeeperProxy) CreateNodeWithAcls

func (z *ZookeeperProxy) CreateNodeWithAcls(path string, flag int32, acls []zk.ACL, data string) (string, error)

创建节点(自定义节点权限)

func (*ZookeeperProxy) Delete

func (z *ZookeeperProxy) Delete(path string) error

删除节点

func (*ZookeeperProxy) Exist

func (z *ZookeeperProxy) Exist(path string) (bool, error)

判断节点是否存在

func (*ZookeeperProxy) GetChildren

func (z *ZookeeperProxy) GetChildren(path string) ([]string, error)

获取子节点列表

func (*ZookeeperProxy) GetConnState

func (z *ZookeeperProxy) GetConnState() string

获取zookeeper当前的连接状态

func (*ZookeeperProxy) GetData

func (z *ZookeeperProxy) GetData(path string) (string, error)

获取节点值

func (*ZookeeperProxy) GetSessionId

func (z *ZookeeperProxy) GetSessionId() int64

获取当前连接的sessionId

func (*ZookeeperProxy) SetData

func (z *ZookeeperProxy) SetData(path string, s string) error

设置节点值

func (*ZookeeperProxy) StartLi

func (z *ZookeeperProxy) StartLi() (<-chan Event, error)

监听连接状态

func (*ZookeeperProxy) WatchChildren

func (z *ZookeeperProxy) WatchChildren(path string, listener func(respChan <-chan *WatchChildrenResponse))

监听子节点 TODO: 目前只支持对子节点进行 增加 或 删除的监控, 不支持对 子节点值改变 的监控

func (*ZookeeperProxy) WatchNode

func (z *ZookeeperProxy) WatchNode(path string, listener func(respChan <-chan *WatchNodeResponse))

对节点监听

Jump to

Keyboard shortcuts

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