Documentation
¶
Index ¶
- Variables
- type ChildData
- type DummyLogger
- type Logger
- type NodeCache
- type NodeCacheListenable
- type NodeCacheListener
- type NodeCacheListenerContainer
- type NodeState
- type PathChildrenCache
- type RefreshMode
- type TreeCache
- func (tc *TreeCache) CurrentChildren(fullPath string) (map[string]*ChildData, error)
- func (tc *TreeCache) CurrentData(fullPath string) (*ChildData, error)
- func (tc *TreeCache) Listenable() TreeCacheListenable
- func (tc *TreeCache) SetCacheData(cacheData bool) *TreeCache
- func (tc *TreeCache) SetCreateParentNodes(yes bool) *TreeCache
- func (tc *TreeCache) SetLogger(l Logger) *TreeCache
- func (tc *TreeCache) SetMaxDepth(depth int) *TreeCache
- func (tc *TreeCache) Start() error
- func (tc *TreeCache) Stop()
- func (tc *TreeCache) UnhandledErrorListenable() curator.UnhandledErrorListenable
- type TreeCacheEvent
- type TreeCacheEventType
- type TreeCacheListenable
- type TreeCacheListener
- type TreeCacheListenerContainer
- type TreeCacheSelector
- type TreeNode
Constants ¶
This section is empty.
Variables ¶
var DefaultTreeCacheSelector = NewTreeCacheSelector( func(p string) bool { return true }, func(p string) bool { return true }, )
DefaultTreeCacheSelector returns true for all methods
var ErrNodeNotFound = errors.New("node not found")
ErrNodeNotFound indicates a node can not be found.
var ErrNodeNotLive = errors.New("node state is not LIVE")
ErrNodeNotLive indicates the state of node is not LIVE.
var ErrRootNotMatch = errors.New("root path not match")
ErrRootNotMatch indicates the root path does not match.
var IgnoreBuiltinTreeCacheSelector = NewTreeCacheSelector( func(path string) bool { return !strings.HasPrefix(path, "/zookeeper") }, func(path string) bool { return !strings.HasPrefix(path, "/zookeeper") }, )
IgnoreBuiltinTreeCacheSelector ignores path starts with /zookeeper This could be useful if you use / as your root
Functions ¶
This section is empty.
Types ¶
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 DummyLogger ¶
type DummyLogger struct{}
DummyLogger is a Logger does nothing.
func (DummyLogger) Debugf ¶
func (l DummyLogger) Debugf(string, ...interface{})
Debugf does nothing.
func (DummyLogger) Printf ¶
func (l DummyLogger) Printf(string, ...interface{})
Printf does nothing.
type NodeCache ¶
type NodeCache struct {
// contains filtered or unexported fields
}
A utility that attempts to keep the data from a node locally cached. This class will watch the node, respond to update/create/delete events, pull down the data, etc. You can register a listener that will get notified when changes occur.
func NewNodeCache ¶
func NewNodeCache(client curator.CuratorFramework, path string, dataIsCompressed bool) *NodeCache
func (*NodeCache) NodeCacheListenable ¶
func (c *NodeCache) NodeCacheListenable() NodeCacheListenable
func (*NodeCache) Start ¶
Start the cache. The cache is not started automatically. You must call this method.
func (*NodeCache) StartAndInitalize ¶
Same as Start() but gives the option of doing an initial build
type NodeCacheListenable ¶
type NodeCacheListenable interface { curator.Listenable /* [T] */ AddListener(listener NodeCacheListener) RemoveListener(listener NodeCacheListener) }
type NodeCacheListener ¶
type NodeCacheListener interface { // Called when a change has occurred NodeChanged() error }
type NodeCacheListenerContainer ¶
type NodeCacheListenerContainer struct {
*curator.ListenerContainer
}
func (*NodeCacheListenerContainer) AddListener ¶
func (c *NodeCacheListenerContainer) AddListener(listener NodeCacheListener)
func (*NodeCacheListenerContainer) RemoveListener ¶
func (c *NodeCacheListenerContainer) RemoveListener(listener NodeCacheListener)
type NodeState ¶
type NodeState int32
NodeState represents state of TreeNode. TODO: make this a private type?
func (*NodeState) CompareAndSwap ¶
CompareAndSwap set the state to new if value is old atomatically.
type PathChildrenCache ¶
type PathChildrenCache struct {
// contains filtered or unexported fields
}
A utility that attempts to keep all data from all children of a ZK path locally cached. This class 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.
func NewPathChildrenCache ¶
func NewPathChildrenCache(client curator.CuratorFramework, path string, cacheData, dataIsCompressed bool) *PathChildrenCache
func (*PathChildrenCache) RefreshMode ¶
func (c *PathChildrenCache) RefreshMode(mode RefreshMode)
type RefreshMode ¶
type RefreshMode int
const ( STANDARD RefreshMode = iota FORCE_GET_DATA_AND_STAT POST_INITIALIZED )
type TreeCache ¶
type TreeCache struct {
// contains filtered or unexported fields
}
TreeCache 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 of this class 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 NewTreeCache ¶
func NewTreeCache(client curator.CuratorFramework, root string, selector TreeCacheSelector) *TreeCache
NewTreeCache creates a TreeCache 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 (*TreeCache) 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 (*TreeCache) 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 (*TreeCache) Listenable ¶
func (tc *TreeCache) Listenable() TreeCacheListenable
Listenable returns the cache listeners.
func (*TreeCache) 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 (*TreeCache) 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 (*TreeCache) 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.
func (*TreeCache) Start ¶
Start starts the TreeCache. The cache is not started automatically. You must call this method.
func (*TreeCache) UnhandledErrorListenable ¶
func (tc *TreeCache) UnhandledErrorListenable() curator.UnhandledErrorListenable
UnhandledErrorListenable allows catching unhandled errors in asynchornous operations.
type TreeCacheEvent ¶
type TreeCacheEvent struct { Type TreeCacheEventType Data *ChildData }
TreeCacheEvent represents a change to a path
func (TreeCacheEvent) String ¶
func (e TreeCacheEvent) String() string
String returns the string representation of TreeCacheEvent
type TreeCacheEventType ¶
type TreeCacheEventType int
TreeCacheEventType represents the type of change to a path
const ( // TreeCacheEventNodeAdded indicates a node was added TreeCacheEventNodeAdded TreeCacheEventType = iota // TreeCacheEventNodeUpdated indicates a node's data was changed TreeCacheEventNodeUpdated // TreeCacheEventNodeRemoved indicates a node was removed from the tree TreeCacheEventNodeRemoved // TreeCacheEventConnSuspended is called when the connection has changed to SUSPENDED TreeCacheEventConnSuspended // TreeCacheEventConnReconnected is called when the connection has changed to RECONNECTED TreeCacheEventConnReconnected // TreeCacheEventConnLost is called when the connection has changed to LOST TreeCacheEventConnLost // TreeCacheEventInitialized is posted after the initial cache has been fully populated TreeCacheEventInitialized )
func (TreeCacheEventType) String ¶
func (et TreeCacheEventType) String() string
String returns the string representation of TreeCacheEventType "Unknown" is returned when event type is unknown
type TreeCacheListenable ¶
type TreeCacheListenable interface { curator.Listenable AddListener(TreeCacheListener) RemoveListener(TreeCacheListener) }
TreeCacheListenable represents a container of TreeCacheListener(s).
type TreeCacheListener ¶
type TreeCacheListener interface { // Called when a change has occurred ChildEvent(client curator.CuratorFramework, event TreeCacheEvent) error }
TreeCacheListener represents listener for TreeCache changes
func NewTreeCacheListener ¶
func NewTreeCacheListener(cb childEventCallback) TreeCacheListener
NewTreeCacheListener creates TreeCacheListener with given function
type TreeCacheListenerContainer ¶
type TreeCacheListenerContainer struct {
curator.ListenerContainer
}
TreeCacheListenerContainer is a container of TreeCacheListener.
func (*TreeCacheListenerContainer) AddListener ¶
func (c *TreeCacheListenerContainer) AddListener(listener TreeCacheListener)
AddListener adds a listener to the container.
func (*TreeCacheListenerContainer) RemoveListener ¶
func (c *TreeCacheListenerContainer) RemoveListener(listener TreeCacheListener)
RemoveListener removes a listener to the container.
type TreeCacheSelector ¶
type TreeCacheSelector interface { // TraverseChildren returns true if children of this path should be cached. // i.e. if false is returned, this node is not queried to // determine if it has children or not TraverseChildren(fullPath string) bool // AcceptChild returns true if this node should be returned from the cache AcceptChild(fullPath string) bool }
TreeCacheSelector controls which nodes a TreeCache 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 NewTreeCacheSelector ¶
func NewTreeCacheSelector(traverseChildren, acceptChild func(string) bool) TreeCacheSelector
NewTreeCacheSelector creates a new TreeCacheSelector with given functions
type TreeNode ¶
TreeNode represents a node in a tree of znodes.
func NewTreeNode ¶
NewTreeNode creates a TreeNode with given path and parent. NOTE: parent should be nil if the node is root.
func (*TreeNode) FindChild ¶
FindChild finds a child of current node by its relative path. NOTE: path should contain no slash.
func (*TreeNode) RemoveChild ¶
RemoveChild removes child by path.
func (*TreeNode) SwapChildData ¶
SwapChildData sets ChildData to given value and returns the old ChildData.