Documentation ¶
Index ¶
- Variables
- type Cache
- func (c *Cache) AddErrorListener(l *ErrorListener)
- func (c *Cache) AddEventListener(l *CacheEventListener)
- func (c *Cache) CurrentChildren(fullPath string) (map[string]*ChildData, error)
- func (c *Cache) CurrentData(fullPath string) (*ChildData, error)
- func (c *Cache) DelErrorListener(l *ErrorListener)
- func (c *Cache) DelEventListener(l *CacheEventListener)
- func (c *Cache) SetCacheData(cacheData bool) *Cache
- func (c *Cache) SetCreateParentNodes(yes bool) *Cache
- func (c *Cache) SetMaxDepth(depth int) *Cache
- func (c *Cache) Start() error
- func (c *Cache) Stop()
- type CacheEvent
- type CacheEventListener
- type CacheEventListeners
- type CacheEventType
- type CacheState
- type ChildData
- type ErrorListener
- type ErrorListeners
- type Node
- type NodeState
- type Selector
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNodeNotFound indicates a node can not be found. ErrNodeNotFound = errors.New("node not found") // ErrRootNotMatch indicates the root path does not match. ErrRootNotMatch = errors.New("root path not match") // ErrNodeNotLive indicates the state of node is not LIVE. ErrNodeNotLive = errors.New("node state is not LIVE") )
var DefaultSelector = NewSelector(FuncAcceptAll, FuncAcceptAll)
DefaultSelector always returns true.
var FuncAcceptAll = func(string) bool { return true }
FuncAcceptAll is a function that always returns true.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a a utility that attempts to keep all data from all children of a ZK path locally cached. It will watch the ZK path, respond to update/create/delete events, pull down the data, etc. You can register a listener that will get notified when changes occur.
NOTE: It's not possible to stay transactionally in sync. Users must be prepared for false-positives and false-negatives. Additionally, always use the version number when updating data to avoid overwriting another process' change.
func NewCache ¶
NewCache creates a Cache for the given client and path with default options.
If the client is namespaced, all operations on the resulting TreeCache will be in terms of the namespace, including all published events. The given path is the root at which the TreeCache will watch and explore. If no node exists at the given path, the TreeCache will be initially empty.
func (*Cache) AddErrorListener ¶
func (c *Cache) AddErrorListener(l *ErrorListener)
AddErrorListener adds an error listener.
func (*Cache) AddEventListener ¶
func (c *Cache) AddEventListener(l *CacheEventListener)
AddEventListener adds a CacheEventListener.
func (*Cache) CurrentChildren ¶
CurrentChildren returns the current set of children at the given full path, mapped by child name. There are no guarantees of accuracy; this is merely the most recent view of the data. If there is no node at this path, ErrNodeNotFound is returned.
func (*Cache) CurrentData ¶
CurrentData returns the current data for the given full path. There are no guarantees of accuracy. This is merely the most recent view of the data. If there is no node at the given path, ErrNodeNotFound is returned.
func (*Cache) DelErrorListener ¶
func (c *Cache) DelErrorListener(l *ErrorListener)
DelErrorListener deletes the first occurrence of l.
func (*Cache) DelEventListener ¶
func (c *Cache) DelEventListener(l *CacheEventListener)
DelEventListener deletes the first occurrence of l.
func (*Cache) SetCacheData ¶
SetCacheData sets whether or not to cache byte data per node, default true. NOTE: When this set to false, the events still contain data of znode but you can't query them by TreeCache.CurrentData/CurrentChildren
func (*Cache) SetCreateParentNodes ¶
SetCreateParentNodes sets whether to auto-create parent nodes for the cached path. By default, TreeCache does not do this. Note: Parent nodes is only created when Start() is called.
func (*Cache) SetMaxDepth ¶
SetMaxDepth sets the maximum depth to explore/watch. Set to 0 will watch only the root node. Set to 1 will watch the root node and its immediate children. Default to math.MaxInt32.
type CacheEvent ¶
type CacheEvent struct { Type CacheEventType Data *ChildData }
CacheEvent represents a change to a path
func (CacheEvent) String ¶
func (e CacheEvent) String() string
String returns the string representation of CacheEvent
type CacheEventListener ¶
type CacheEventListener struct {
// contains filtered or unexported fields
}
CacheEventListener is a handler of cache event.
func NewCacheEventListener ¶
func NewCacheEventListener(fn func(CacheEvent)) *CacheEventListener
NewCacheEventListener creates CacheEventListener with fn.
func (*CacheEventListener) Handle ¶
func (l *CacheEventListener) Handle(e CacheEvent)
Handle calls the function with e.
type CacheEventListeners ¶
CacheEventListeners is a set of CacheEventListeners.
func NewCacheEventListeners ¶
func NewCacheEventListeners() *CacheEventListeners
NewCacheEventListeners creates empty CacheEventListeners.
func (*CacheEventListeners) Add ¶
func (l *CacheEventListeners) Add(listener *CacheEventListener)
Add adds a CacheEventListener.
func (*CacheEventListeners) Broadcast ¶
func (l *CacheEventListeners) Broadcast(e CacheEvent)
Broadcast calls every listener with given CacheEvent.
func (*CacheEventListeners) Clear ¶
func (l *CacheEventListeners) Clear()
Clear deletes all listeners.
func (*CacheEventListeners) Count ¶
func (l *CacheEventListeners) Count() int
Count returns the number of listeners.
func (*CacheEventListeners) Del ¶
func (l *CacheEventListeners) Del(listener *CacheEventListener)
Del deletes the first occurrence of listener.
type CacheEventType ¶
type CacheEventType int
CacheEventType represents the type of change to a path.
const ( // CacheEventNodeAdded indicates a node was added. CacheEventNodeAdded CacheEventType = iota // CacheEventNodeUpdated indicates a node's data was changed. CacheEventNodeUpdated // CacheEventNodeRemoved indicates a node was removed from the tree. CacheEventNodeRemoved // CacheEventConnSuspended is called when the connection has changed to SUSPENDED. CacheEventConnSuspended // CacheEventConnReconnected is called when the connection has changed to RECONNECTED. CacheEventConnReconnected // CacheEventConnLost is called when the connection has changed to LOST. CacheEventConnLost // CacheEventInitialized is posted after the initial cache has been fully populated. CacheEventInitialized )
func (CacheEventType) String ¶
func (et CacheEventType) String() string
String returns the string representation of CacheEventType. "Unknown" is returned when event type is unknown
type CacheState ¶
type CacheState int32
CacheState represents the state of a Cache.
const ( // CacheStateLatent indicates Cache.Start() has not yet been called. CacheStateLatent CacheState = iota // CacheStateStarted indicates Cache.Start() has been called. CacheStateStarted // CacheStateStopped indicates Cache.Close() has been called. CacheStateStopped )
func (*CacheState) EqualTo ¶
func (s *CacheState) EqualTo(x CacheState) bool
EqualTo returns true if value equals to given CacheState.
func (*CacheState) SetValueIf ¶
func (s *CacheState) SetValueIf(old, new CacheState) bool
SetValueIf does a CAS operation.
type ChildData ¶
type ChildData struct {
// contains filtered or unexported fields
}
ChildData contains data of a node including: stat, data, path
func NewChildData ¶
NewChildData creates ChildData.
func (ChildData) Data ¶
Data returns the node data for this child when the cache mode is set to cache data
type ErrorListener ¶
type ErrorListener struct {
// contains filtered or unexported fields
}
ErrorListener is a handler of error.
func NewErrorListener ¶
func NewErrorListener(fn func(error)) *ErrorListener
NewErrorListener creates ErrorListener from fn.
func (*ErrorListener) Handle ¶
func (l *ErrorListener) Handle(e error)
Handle calls the function with e.
type ErrorListeners ¶
ErrorListeners is a set of listeners.
func NewErrorListeners ¶
func NewErrorListeners() *ErrorListeners
NewErrorListeners creates empty ErrorListeners.
func (*ErrorListeners) Add ¶
func (l *ErrorListeners) Add(listener *ErrorListener)
Add adds a ErrorListener.
func (*ErrorListeners) Broadcast ¶
func (l *ErrorListeners) Broadcast(err error)
Broadcast calls every listener with given error.
func (*ErrorListeners) Count ¶
func (l *ErrorListeners) Count() int
Count returns the number of listeners.
func (*ErrorListeners) Del ¶
func (l *ErrorListeners) Del(listener *ErrorListener)
Del deletes the first occurrence of listener.
type Node ¶
Node represents a node within a tree of ZNodes.
func NewNode ¶
NewNode creates a Node with given path and parent. NOTE: Parent should be nil if the node is root.
func (*Node) FindChild ¶
FindChild finds a child of current node by its relative path. NOTE: path should contain no slash.
func (*Node) RemoveChild ¶
RemoveChild removes child by path.
func (*Node) SwapChildData ¶
SwapChildData sets ChildData to given value and returns the old ChildData.
type NodeState ¶
type NodeState int32
NodeState represents state of a Node.
func (*NodeState) SetValueIf ¶
SetValueIf does a CAS operation.
type Selector ¶
Selector controls the nodes a Cache processes. When iterating over the children of a parent node, a given node's children are queried only if TraverseChildren returns true. When caching the list of nodes for a parent node, a given node is stored only if AcceptChild returns true.
func NewSelector ¶
NewSelector creates Selector.