zkclient

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

zkclient - A golang zookeeper client

GoDoc

Features

  • auto reconnect
  • set/get/delete value
  • support string/json codec, and you can implement your own, see codec.go
  • real-time synchronize data from zookeeper to memory, see demo

Reference

  • github.com/samuel/go-zookeeper

Documentation

Overview

zkclient is a client of zookeeper. support features: - auto reconnect - set/get/delete value - support string/json codec, and you can implement your own - real-time synchronize data from zookeeper to memory

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StateAlive

func StateAlive(state zk.State) bool

StateAlive whether zk state alive

Types

type AlarmTrigger

type AlarmTrigger func(err error)

AlarmTrigger alarm function

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client for zookeeper

func NewClient

func NewClient(servers []string, timeout time.Duration) (*Client, error)

NewClient zookeeper client

func (*Client) AppendDeadWatcher

func (cli *Client) AppendDeadWatcher(watcher *Watcher)

AppendDeadWatcher add dead watcher, wait to watch again

func (*Client) Close

func (cli *Client) Close()

Close client, NOT use Client which already calling Close()

func (*Client) Conn

func (cli *Client) Conn() *zk.Conn

Conn for zookeeper

func (*Client) ConnAlive

func (cli *Client) ConnAlive() bool

ConnAlive check

func (*Client) Connecting

func (cli *Client) Connecting() bool

Connecting check

func (*Client) Delete

func (cli *Client) Delete(path string) error

Delete path

func (*Client) EnsurePath

func (cli *Client) EnsurePath(path string) error

EnsurePath check or create target path

func (*Client) Get

func (cli *Client) Get(path string, codec Codec, typ reflect.Type) (interface{}, error)

Get value from zookeeper, the raw value will be decoded by codec

func (*Client) NewWatcher

func (cli *Client) NewWatcher(path string, handler EventHandler) (*Watcher, error)

NewWatcher create new watcher

func (*Client) Reconnect

func (cli *Client) Reconnect() error

Reconnect connection

func (*Client) SetAlarmTrigger

func (cli *Client) SetAlarmTrigger(f AlarmTrigger)

SetAlarmTrigger set zookeeper alarm function

func (*Client) SetJSON

func (cli *Client) SetJSON(path string, obj interface{}) error

SetJSON in zookeeper

func (*Client) SetJSONMapValue

func (cli *Client) SetJSONMapValue(path, key string, obj interface{}) error

SetJSONMapValue in zookeeper

func (*Client) SetMapValue

func (cli *Client) SetMapValue(path, key string, obj interface{}, codec Codec) error

SetMapValue set map value in zookeeper

func (*Client) SetPackValue

func (cli *Client) SetPackValue(path string, pack *PackValue) error

SetPackValue set pack value in zookeeper

func (*Client) SetRawValue

func (cli *Client) SetRawValue(path string, bytes []byte) error

SetRawValue set raw value in zookeeper

func (*Client) SetString

func (cli *Client) SetString(path, s string) error

SetString in zookeeper

func (*Client) SetStringMapValue

func (cli *Client) SetStringMapValue(path, key, s string) error

SetStringMapValue in zookeeper

func (*Client) SetValue

func (cli *Client) SetValue(path string, obj interface{}, codec Codec) error

SetValue set value in zookeeper

func (*Client) Sync

func (cli *Client) Sync(path string, obj interface{}, codec Codec) error

Sync synchronize value of the path to obj

func (*Client) SyncJSON

func (cli *Client) SyncJSON(path string, obj interface{}) error

SyncJSON config

func (*Client) SyncJSONMap

func (cli *Client) SyncJSONMap(path string, obj interface{}) error

SyncJSONMap config

func (*Client) SyncMap

func (cli *Client) SyncMap(path string, m interface{}, valueCodec Codec, callback EventCallback, syncChildChange bool) error

SyncMap synchronize sub-path value into a map syncChildChange : whether sync the change event of the data of children

func (*Client) SyncString

func (cli *Client) SyncString(path, s string) error

SyncString config

func (*Client) SyncStringMap

func (cli *Client) SyncStringMap(path string, m map[string]string) error

SyncStringMap config

type Codec

type Codec interface {
	Encode(obj interface{}) ([]byte, error)
	Decode(data []byte, typ reflect.Type) (reflect.Value, error)
}

Codec for data

type EventCallback

type EventCallback func() error

EventCallback event callback

type EventHandler

type EventHandler func(*Client, *zk.Event) (<-chan zk.Event, error)

EventHandler zookeeper event handler

type JSONCodec

type JSONCodec struct{}

JSONCodec struct

func (*JSONCodec) Decode

func (c *JSONCodec) Decode(data []byte, typ reflect.Type) (reflect.Value, error)

Decode zk json decode

func (*JSONCodec) Encode

func (c *JSONCodec) Encode(obj interface{}) ([]byte, error)

Encode zk json encode

type PackMap

type PackMap struct {
	// contains filtered or unexported fields
}

func MapPack

func MapPack(obj interface{}, codec Codec) (*PackMap, error)

func (*PackMap) Delete

func (p *PackMap) Delete(key string)

func (*PackMap) Get

func (p *PackMap) Get(key string) ([]byte, error)

func (*PackMap) Set

func (p *PackMap) Set(key string, data []byte) error

type PackValue

type PackValue struct {
	// contains filtered or unexported fields
}

func Pack

func Pack(obj interface{}, codec Codec) (*PackValue, error)

func PackString

func PackString(s *string) *PackValue

func (*PackValue) Get

func (p *PackValue) Get() ([]byte, error)

func (*PackValue) Set

func (p *PackValue) Set(data []byte) error

type StringCodec

type StringCodec struct {
}

func (*StringCodec) Decode

func (c *StringCodec) Decode(data []byte, typ reflect.Type) (reflect.Value, error)

func (*StringCodec) Encode

func (c *StringCodec) Encode(obj interface{}) ([]byte, error)

type Watcher

type Watcher struct {
	Path string
	// contains filtered or unexported fields
}

Watcher zookeeper watcher

func (*Watcher) Watch

func (w *Watcher) Watch()

Watch start watch event

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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