zookeeper

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NodeEventAdded = newNodeEvent("node event node added")
View Source
var NodeEventDeleted = newNodeEvent("node event node deleted")
View Source
var NodeEventError = newNodeEvent("node event node listen error")
View Source
var NodeEventNodeNotFound = newNodeEvent("node event node not found")
View Source
var NodeEventStopped = newNodeEvent("node event zk is stopped")
View Source
var ZKLogger zk.Logger = &defaultLogger{}

Functions

func NewServiceScript added in v0.5.7

func NewServiceScript(config interface{}) (res map[string]interface{}, err error)

Types

type Config

type Config struct {
	Address           string      `json:"address"`
	Username          string      `json:"username,omitempty"`
	Password          string      `json:"password,omitempty"`
	SessionTimeout    int         `json:"sessionTimeout,omitempty"`    // 会话超时 单位 毫秒
	ConnectionTimeout int         `json:"connectionTimeout,omitempty"` // 客户端连接超时 单位 毫秒
	SSHClient         *ssh.Client `json:"-"`
}

type IService added in v0.0.5

type IService interface {
	// Close 关闭 客户端
	Close()
	// GetConn 获取 zk Conn
	GetConn() *zk.Conn
	// Info 查看 zk 相关信息
	Info() (info *Info, err error)
	// Create 创建 永久 节点
	Create(path string, value string) (err error)
	// CreateIfNotExists 如果不存在 则创建 永久 节点 创建时候如果已存在不报错  如果 父节点不存在 则先创建父节点
	CreateIfNotExists(path string, value string) (err error)
	// CreateEphemeral 创建 临时 节点
	CreateEphemeral(path string, value string) (err error)
	// CreateEphemeralIfNotExists 如果不存在 则创建 临时 节点 创建时候如果已存在不报错 如果 父节点不存在 则先创建父节点
	CreateEphemeralIfNotExists(path string, value string) (err error)
	// Exists 查看节点是否存在
	Exists(path string) (isExist bool, err error)
	// Set 设置 节点 值
	Set(path string, value string) (err error)
	// Get 查看 节点 数据
	Get(path string) (value string, err error)
	// GetInfo 查看 节点 信息
	GetInfo(path string) (info *NodeInfo, err error)
	// Stat 节点 状态
	Stat(path string) (info *StatInfo, err error)
	// GetChildren 查询 子节点
	GetChildren(path string) (children []string, err error)
	// Delete 删除节点 如果 包含子节点 则先删除所有子节点
	Delete(path string) (err error)
	// WatchChildren 监听 子节点 只监听当前节点下的子节点 NodeEventError 监听异常 NodeEventStopped zk客户端关闭 NodeEventAdded 节点新增 NodeEventDeleted 节点删除 NodeEventNodeNotFound 节点不存在
	WatchChildren(path string, listen func(data *WatchChildrenListenData) (finish bool)) (err error)
}

func New

func New(config *Config) (IService, error)

New 创建zookeeper客户端

type Info

type Info struct {
	Server    string   `json:"server"`
	SessionID int64    `json:"sessionID"`
	State     zk.State `json:"state"`
}

type NodeEvent

type NodeEvent string

type NodeInfo

type NodeInfo struct {
	Path string    `json:"path"`
	Data string    `json:"data"`
	Stat *StatInfo `json:"stat"`
}

type Service added in v0.0.5

type Service struct {
	*Config
	// contains filtered or unexported fields
}

Service 注册处理器在线信息等

func (*Service) Close added in v0.5.7

func (this_ *Service) Close()

func (*Service) Create added in v0.0.5

func (this_ *Service) Create(path string, data string) (err error)

func (*Service) CreateEphemeral added in v0.5.7

func (this_ *Service) CreateEphemeral(path string, data string) (err error)

func (*Service) CreateEphemeralIfNotExists added in v0.5.7

func (this_ *Service) CreateEphemeralIfNotExists(path string, data string) (err error)

func (*Service) CreateIfNotExists added in v0.0.5

func (this_ *Service) CreateIfNotExists(path string, data string) (err error)

CreateIfNotExists 一层层检查,如果不存在则创建

func (*Service) Delete added in v0.0.5

func (this_ *Service) Delete(path string) (err error)

Delete 删除节点 如果有子节点,则子节点一同删除

func (*Service) Exists added in v0.0.5

func (this_ *Service) Exists(path string) (isExist bool, err error)

Exists 判断节点是否存在

func (*Service) Get added in v0.0.5

func (this_ *Service) Get(path string) (data string, err error)

Get 获取节点信息

func (*Service) GetChildren added in v0.0.5

func (this_ *Service) GetChildren(path string) (children []string, err error)

GetChildren 查询子节点

func (*Service) GetConn added in v0.0.5

func (this_ *Service) GetConn() *zk.Conn

func (*Service) GetInfo added in v0.5.7

func (this_ *Service) GetInfo(path string) (info *NodeInfo, err error)

GetInfo 获取节点信息

func (*Service) GetServers added in v0.0.5

func (this_ *Service) GetServers() []string

func (*Service) Info added in v0.0.5

func (this_ *Service) Info() (info *Info, err error)

Info ZK信息

func (*Service) Set added in v0.0.5

func (this_ *Service) Set(path string, data string) (err error)

Set 修改节点数据

func (*Service) Stat added in v0.0.5

func (this_ *Service) Stat(path string) (info *StatInfo, err error)

Stat 获取节点状态

func (*Service) WatchChildren added in v0.0.5

func (this_ *Service) WatchChildren(path string, listen func(data *WatchChildrenListenData) (finish bool)) (err error)

WatchChildren 监听子节点 子节点 新增 删除

type StatInfo

type StatInfo struct {
	Czxid          int64 `json:"czxid,omitempty"`
	Mzxid          int64 `json:"mzxid,omitempty"`
	Ctime          int64 `json:"ctime,omitempty"`
	Mtime          int64 `json:"mtime,omitempty"`
	Version        int32 `json:"version,omitempty"`
	Cversion       int32 `json:"cversion,omitempty"`
	Aversion       int32 `json:"aversion,omitempty"`
	EphemeralOwner int64 `json:"ephemeralOwner,omitempty"`
	DataLength     int32 `json:"dataLength,omitempty"`
	NumChildren    int32 `json:"numChildren,omitempty"`
	Pzxid          int64 `json:"pzxid,omitempty"`
}

func StatToInfo

func StatToInfo(stat *zk.Stat) (info *StatInfo)

type WatchChildrenListenData

type WatchChildrenListenData struct {
	Path  string     `json:"path"`
	Event *NodeEvent `json:"event"`
	Child string     `json:"child"`
	Err   error      `json:"err"`
}

Jump to

Keyboard shortcuts

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