zookeeper

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 6 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// NodeCreated represents the creation of a znode
	NodeCreated = zk.EventNodeCreated
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	Connect(url string) error
	GetConnection() *zk.Conn
	CreateNode(path string, data []byte) error
	DeleteNode(path string) error
	WatchForNode(path string) (<-chan zk.Event, error)
	LockEntity(name string) (string, bool)
	ReleaseEntity(lock string)
	GetData(path string) ([]byte, error)
	Close()
}

Driver is an interface that abstracts zookeeper calls This is a simple interface that allows for the creation/deletion of nodes Also we can watch for the creation of a node

type Zdriver

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

Zdriver is a simple implementation of the Driver interface This allows us to create and delete nodes, and create watches

func NewDriver

func NewDriver(url string) (*Zdriver, error)

NewDriver is just a constructor for the Zdriver class

func (*Zdriver) Close

func (d *Zdriver) Close()

Close closes the connection to zookeeper

func (*Zdriver) Connect

func (d *Zdriver) Connect(url string) error

Connect connects a driver to a zookeeper instance

func (*Zdriver) CreateNode

func (d *Zdriver) CreateNode(path string, data []byte) error

CreateNode create a znode along a path

func (*Zdriver) DeleteNode

func (d *Zdriver) DeleteNode(path string) error

DeleteNode deletes the znode at the given path

func (*Zdriver) GetConnection

func (d *Zdriver) GetConnection() *zk.Conn

GetConnection returns a connection to the same instance of zookeeper the driver is connected to

func (*Zdriver) GetData

func (d *Zdriver) GetData(path string) ([]byte, error)

GetData just grabs whatever data is at a node

func (*Zdriver) LockEntity

func (d *Zdriver) LockEntity(entity string) (string, bool)

LockEntity Locks a given entity, preventing other drivers from modifying it Returns the path to the lock and whether we own it or not This uses the locking scheme given in the official zookeeper recipes & solutions Source: http://zookeeper.apache.org/doc/r3.1.2/recipes.html The only change here is that we don't want to spin waiting for the lock

func (*Zdriver) ReleaseEntity

func (d *Zdriver) ReleaseEntity(path string)

ReleaseEntity releases the entity by deleting the znode that represents the lock

func (*Zdriver) WatchForNode

func (d *Zdriver) WatchForNode(path string) (<-chan zk.Event, error)

WatchForNode watches for the creation of a specific znode

Directories

Path Synopsis
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.

Jump to

Keyboard shortcuts

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