zk

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2015 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixEnv = "env://"
	PrefixZk  = "zk://"
)
View Source
const (
	StateUnknown           = zk.StateUnknown
	StateDisconnected      = zk.StateDisconnected
	StateConnecting        = zk.StateConnecting
	StateAuthFailed        = zk.StateAuthFailed
	StateConnectedReadOnly = zk.StateConnectedReadOnly
	StateSaslAuthenticated = zk.StateSaslAuthenticated
	StateExpired           = zk.StateExpired
	StateConnected         = zk.StateConnected
	StateHasSession        = zk.StateHasSession
)

Variables

View Source
var (
	ErrNotInitialized = errors.New("not-initialized")
	ErrNotWatching    = errors.New("not-watching")
	ErrInvalidState   = errors.New("invalid-state")
	ErrTimeout        = errors.New("timeout")
)
View Source
var (
	ErrNotConnected   = errors.New("zk-not-initialized")
	ErrConflict       = errors.New("error-conflict")
	ErrZkDisconnected = errors.New("error-zk-disconnected")

	ErrNotExist                = zk.ErrNoNode
	ErrConnectionClosed        = zk.ErrConnectionClosed
	ErrUnknown                 = zk.ErrUnknown
	ErrAPIError                = zk.ErrAPIError
	ErrNoAuth                  = zk.ErrNoAuth
	ErrBadVersion              = zk.ErrBadVersion
	ErrNoChildrenForEphemerals = zk.ErrNoChildrenForEphemerals
	ErrNodeExists              = zk.ErrNodeExists
	ErrNotEmpty                = zk.ErrNotEmpty
	ErrSessionExpired          = zk.ErrSessionExpired
	ErrInvalidACL              = zk.ErrInvalidACL
	ErrAuthFailed              = zk.ErrAuthFailed
	ErrClosing                 = zk.ErrClosing
	ErrNothing                 = zk.ErrNothing
	ErrSessionMoved            = zk.ErrSessionMoved
)

Functions

func CheckAndIncrement

func CheckAndIncrement(zc ZK, key registry.Path, current, increment int) (int, error)

func Connect

func Connect(servers []string, timeout time.Duration) (*zookeeper, error)

func CreateOrSet

func CreateOrSet(zc ZK, key registry.Path, value interface{}, ephemeral ...bool) error

func CreateOrSetBytes

func CreateOrSetBytes(zc ZK, key registry.Path, value []byte, ephemeral ...bool) error

func CreateOrSetInt

func CreateOrSetInt(zc ZK, key registry.Path, value int, ephemeral ...bool) error

func CreateOrSetString

func CreateOrSetString(zc ZK, key registry.Path, value string, ephemeral ...bool) error

func DeleteObject

func DeleteObject(zc ZK, key registry.Path) error

func GetBytes

func GetBytes(zc ZK, key registry.Path) []byte

func GetInt

func GetInt(zc ZK, key registry.Path) *int

func GetObject

func GetObject(zc ZK, key registry.Path, value interface{}) error

func GetString

func GetString(zc ZK, key registry.Path) *string

func Increment

func Increment(zc ZK, key registry.Path, increment int) error

func NewChange

func NewChange(c registry.Change, zkc ZK, persistent ...bool) watch

func NewCreate

func NewCreate(c registry.Create, zkc ZK, persistent ...bool) watch

func NewDelete

func NewDelete(d registry.Delete, zkc ZK, persistent ...bool) watch

func NewMembers

func NewMembers(m registry.Members, zkc ZK, persistent ...bool) watch

func PathExists

func PathExists(zc ZK, key registry.Path) bool

func Resolve

func Resolve(zc ZK, key registry.Path, value string) (registry.Path, string, error)

If value begins with env:// then automatically resolve the pointer recursively. Returns key, value, error

func VersionLockAndExecute

func VersionLockAndExecute(zc ZK, key registry.Path, rev int, f func() error) (int, error)

A simple non-ephemeral lock held at key and we use simply by incrementing and using it like a compare and swap.

func Visit

func Visit(zc ZK, key registry.Path, v func(registry.Path, []byte) bool) error

func ZkHosts

func ZkHosts() []string

Types

type Change

type Change struct {
	registry.Change
	// contains filtered or unexported fields
}

func (*Change) Apply

func (this *Change) Apply(handler func(k registry.Key, before, after *Node) bool) error

Change notification occurs when node is CREATED or when the value is CHANGED

func (*Change) Init

func (this *Change) Init(zkc ZK)

func (*Change) SetGroupChan

func (this *Change) SetGroupChan(c chan<- watch)

func (*Change) SetTimeout

func (this *Change) SetTimeout(t time.Duration) error

func (*Change) String

func (this *Change) String() string

func (*Change) Wait

func (this *Change) Wait() error

type Conditions

type Conditions struct {
	registry.Conditions
	// contains filtered or unexported fields
}

func NewConditions

func NewConditions(c registry.Conditions, zkc ZK, persistent ...bool) *Conditions

func (*Conditions) Init

func (this *Conditions) Init(zkc ZK) *Conditions

func (*Conditions) Pending

func (this *Conditions) Pending() []watch

func (*Conditions) Wait

func (this *Conditions) Wait() error

Simply blocks until it's either true or a timeout occurs. The error will indicate whether the condition is met or a timeout took place.

type Create

type Create struct {
	registry.Create
	// contains filtered or unexported fields
}

func (*Create) Apply

func (this *Create) Apply(handler func(k registry.Key, before, after *Node) bool) error

func (*Create) Init

func (this *Create) Init(zkc ZK)

func (*Create) SetGroupChan

func (this *Create) SetGroupChan(c chan<- watch)

func (*Create) SetTimeout

func (this *Create) SetTimeout(t time.Duration) error

func (*Create) String

func (this *Create) String() string

func (*Create) Wait

func (this *Create) Wait() error

type Delete

type Delete struct {
	registry.Delete
	// contains filtered or unexported fields
}

func (*Delete) Apply

func (this *Delete) Apply(handler func(k registry.Key, before, after *Node) bool) error

func (*Delete) Init

func (this *Delete) Init(zkc ZK)

func (*Delete) SetGroupChan

func (this *Delete) SetGroupChan(c chan<- watch)

func (*Delete) SetTimeout

func (this *Delete) SetTimeout(t time.Duration) error

func (*Delete) String

func (this *Delete) String() string

func (*Delete) Wait

func (this *Delete) Wait() error

type Dir added in v1.0.2

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

func (*Dir) Attr added in v1.0.2

func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) error

func (*Dir) Create added in v1.0.2

func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error)

func (*Dir) Lookup added in v1.0.2

func (d *Dir) Lookup(ctx context.Context, name string) (fs.Node, error)

func (*Dir) Mkdir added in v1.0.2

func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error)

func (*Dir) ReadDirAll added in v1.0.2

func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error)

func (*Dir) Remove added in v1.0.2

func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error

type Event

type Event struct {
	zk.Event
	Action string
	Note   string
}

func (Event) AsMap

func (e Event) AsMap() map[string]interface{}

func (Event) JSON

func (e Event) JSON() string

type FS added in v1.0.2

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

func NewFS added in v1.0.2

func NewFS(zc ZK, path registry.Path) *FS

func (*FS) Mount added in v1.0.2

func (this *FS) Mount(dir string, perm os.FileMode) error

func (*FS) Root added in v1.0.2

func (this *FS) Root() (fs.Node, error)

func (*FS) Shutdown added in v1.0.2

func (this *FS) Shutdown() error

func (*FS) Unmount added in v1.0.2

func (this *FS) Unmount() error

func (*FS) Wait added in v1.0.2

func (this *FS) Wait() error

type File added in v1.0.2

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

func (*File) Attr added in v1.0.2

func (f *File) Attr(ctx context.Context, a *fuse.Attr) error

func (*File) Flush added in v1.0.2

func (f *File) Flush(ctx context.Context, req *fuse.FlushRequest) error

func (*File) Open added in v1.0.2

func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)

func (*File) Read added in v1.0.2

func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error

func (*File) Release added in v1.0.2

func (f *File) Release(ctx context.Context, req *fuse.ReleaseRequest) error

func (*File) Setattr added in v1.0.2

func (f *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error

func (*File) Write added in v1.0.2

func (f *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error

type Members

type Members struct {
	registry.Members
	// contains filtered or unexported fields
}

func (*Members) Apply

func (this *Members) Apply(handler func(k registry.Key, before, after *Node) bool) error

func (*Members) Init

func (this *Members) Init(zkc ZK)

func (*Members) SetGroupChan

func (this *Members) SetGroupChan(c chan<- watch)

func (*Members) SetTimeout

func (this *Members) SetTimeout(t time.Duration) error

func (*Members) String

func (this *Members) String() string

func (*Members) Wait

func (this *Members) Wait() error

type Node

type Node struct {
	Path    string
	Value   []byte
	Members []string
	Stats   *zk.Stat
	Leaf    bool
	// contains filtered or unexported fields
}

func Follow

func Follow(zc ZK, key registry.Path) (*Node, error)

Node value

func (*Node) CheckAndIncrement

func (this *Node) CheckAndIncrement(current, increment int) (int, error)

func (*Node) Children

func (this *Node) Children() ([]*Node, error)

func (*Node) ChildrenRecursive

func (this *Node) ChildrenRecursive() ([]*Node, error)

func (*Node) CountChildren

func (this *Node) CountChildren() int32

func (*Node) Delete

func (this *Node) Delete() error

func (*Node) FilterChildrenRecursive

func (this *Node) FilterChildrenRecursive(filter func(*Node) bool) ([]*Node, error)

Recursively go through all the children. Apply filter for each node. If filter returns true for the particular node, this node (though not necessarily all its children) will be excluded. This is useful for searching through all true by name or by whether it's a parent node or not.

func (*Node) Get

func (this *Node) Get() error

func (*Node) GetBasename

func (z *Node) GetBasename() string

func (*Node) GetPath

func (z *Node) GetPath() string

func (*Node) GetValue

func (z *Node) GetValue() []byte

func (*Node) GetValueString

func (z *Node) GetValueString() string

func (*Node) Increment

func (this *Node) Increment(increment int) (int, error)

func (*Node) IsLeaf

func (z *Node) IsLeaf() bool

func (*Node) ListAllRecursive

func (this *Node) ListAllRecursive() ([]string, error)

func (*Node) Set

func (this *Node) Set(value []byte) error

func (*Node) VisitChildrenRecursive

func (this *Node) VisitChildrenRecursive(accept func(*Node) bool) ([]*Node, error)

func (*Node) Watch

func (this *Node) Watch(f func(Event)) (chan<- bool, error)

func (*Node) WatchChildren

func (this *Node) WatchChildren(f func(Event)) (chan<- bool, error)

type ZK

type ZK interface {
	Reconnect() error
	Close() error
	Events() <-chan Event
	Create(string, []byte) (*Node, error)
	CreateEphemeral(string, []byte) (*Node, error)
	Get(string) (*Node, error)
	Watch(string, func(Event)) (chan<- bool, error)
	WatchChildren(string, func(Event)) (chan<- bool, error)
	KeepWatch(string, func(Event) bool, ...func(error)) (chan<- bool, error)
	Delete(string) error
}

Jump to

Keyboard shortcuts

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