Documentation
¶
Index ¶
- Constants
- Variables
- func ReleaseWatchObject(wo *WatchObject)
- type BaseNode
- type INodeNotifyHandler
- type Node
- func (n *Node) Children(path string) ([]string, error)
- func (n *Node) Close()
- func (n *Node) Create(path string, buffer []byte) error
- func (n *Node) Exists(path string) (bool, error)
- func (n *Node) Get(path string) ([]byte, error)
- func (n *Node) Open() error
- func (n *Node) Remove(path string) error
- func (n *Node) Server() string
- func (n *Node) Set(path string, buffer []byte) error
- func (n *Node) State() string
- func (n *Node) WatchClose(path string)
- func (n *Node) WatchOpen(path string, callback WatchHandlerFunc) error
- type NodeData
- type NodeHandlerFunc
- type NodeMapper
- func (mapper *NodeMapper) Append(key string, value *NodeData) int
- func (mapper *NodeMapper) Clear()
- func (mapper *NodeMapper) Contains(key string) bool
- func (mapper *NodeMapper) Copy(m map[string]*NodeData)
- func (mapper *NodeMapper) Count() int
- func (mapper *NodeMapper) Get(key string) *NodeData
- func (mapper *NodeMapper) GetKeys() []string
- func (mapper *NodeMapper) GetNodes(location string, ipaddr string, hostname string) NodesPair
- func (mapper *NodeMapper) Remove(key string) int
- func (mapper *NodeMapper) Set(key string, value *NodeData) int
- type NodeStore
- type NodeType
- type NodesPair
- type PulseHandlerFunc
- type Server
- func (s *Server) Children(path string) ([]string, error)
- func (s *Server) Clear()
- func (s *Server) Close() error
- func (s *Server) Create(path string, buffer []byte) error
- func (s *Server) Exists(path string) (bool, error)
- func (s *Server) Get(path string) ([]byte, error)
- func (s *Server) GetLocation() string
- func (s *Server) GetNodes(location string, ipaddr string, hostname string) NodesPair
- func (s *Server) GetOS() string
- func (s *Server) GetPlatform() string
- func (s *Server) Open() error
- func (s *Server) RefreshCache() error
- func (s *Server) Remove(path string) error
- func (s *Server) Server() string
- func (s *Server) Set(path string, buffer []byte) error
- func (s *Server) SetPulse(value string) error
- func (s *Server) State() string
- func (w *Server) WatchClose(path string)
- func (w *Server) WatchOpen(path string, callback WatchHandlerFunc) error
- type ServerArgs
- type SuspicionMapper
- type WatchHandlerFunc
- type WatchObject
- type Worker
- func (w *Worker) Children(path string) ([]string, error)
- func (w *Worker) Close() error
- func (w *Worker) Create(path string, buffer []byte) error
- func (w *Worker) Exists(path string) (bool, error)
- func (w *Worker) Get(path string) ([]byte, error)
- func (w *Worker) GetLocation() string
- func (w *Worker) GetOS() string
- func (w *Worker) GetPlatform() string
- func (w *Worker) Open() error
- func (w *Worker) Remove(path string) error
- func (w *Worker) Server() string
- func (w *Worker) Set(path string, buffer []byte) error
- func (w *Worker) SetAttach(attach []byte)
- func (w *Worker) SetPulse(value string) error
- func (w *Worker) Signin(attach []byte) error
- func (w *Worker) Signout() error
- func (w *Worker) State() string
- func (w *Worker) WatchClose(path string)
- func (w *Worker) WatchOpen(path string, callback WatchHandlerFunc) error
- type WorkerArgs
Constants ¶
View Source
const RetryInterval time.Duration = time.Second * 5
Variables ¶
Functions ¶
func ReleaseWatchObject ¶
func ReleaseWatchObject(wo *WatchObject)
func CreateWatchObject(path string, conn *zk.Conn, callback WatchHandlerFunc) *WatchObject {
if conn == nil { return nil } watchobject := &WatchObject{ Path: path, exit: make(chan bool), } go func(wo *WatchObject, c *zk.Conn, fn WatchHandlerFunc) { listen := true NEW_WATCH: for listen { ret, _, ev, err := c.ExistsW(wo.Path) if err != nil { if callback != nil { callback(wo.Path, nil, err) } time.Sleep(RetryInterval) goto NEW_WATCH } select { case <-ev: { if ret { data, _, err := c.Get(wo.Path) if err != nil { if callback != nil { callback(wo.Path, nil, err) } time.Sleep(RetryInterval) goto NEW_WATCH } if callback != nil { callback(wo.Path, data, nil) } } else { if callback != nil { callback(wo.Path, nil, errors.New("watch exists not found.")) } time.Sleep(RetryInterval) goto NEW_WATCH } } case <-wo.exit: { listen = false } } } }(watchobject, conn, callback) return watchobject }
Types ¶
type INodeNotifyHandler ¶
type Node ¶
func (*Node) WatchClose ¶
type NodeData ¶
type NodeData struct { BaseNode DataCenter string `json:"datacenter"` //数据中心名称(一般为调度服务器位置) Location string `json:"location"` //节点分区位置 OS string `json:"os"` //节点系统 Platform string `json:"platform"` //节点平台 IpAddr string `json:"ipaddr"` //网络地址 APIAddr string `json:"apiaddr"` //节点API ProcessId int `json:"pid"` //节点进程号 Singin bool `json:"singin"` //签到状态 Timestamp int64 `json:"timestamp"` //心跳时间戳 Alivestamp int64 `json:"alivestamp"` //存活时间戳,若发生改变则代表节点已重启 Attach []byte `json:"attach"` //附加数据 }
type NodeHandlerFunc ¶
type NodeHandlerFunc func(nodestore *NodeStore)
func (NodeHandlerFunc) OnZkWrapperNodeHandlerFunc ¶
func (fn NodeHandlerFunc) OnZkWrapperNodeHandlerFunc(nodestore *NodeStore)
type NodeMapper ¶
func NewNodeMapper ¶
func NewNodeMapper() *NodeMapper
func (*NodeMapper) Clear ¶
func (mapper *NodeMapper) Clear()
func (*NodeMapper) Contains ¶
func (mapper *NodeMapper) Contains(key string) bool
func (*NodeMapper) Copy ¶
func (mapper *NodeMapper) Copy(m map[string]*NodeData)
func (*NodeMapper) Count ¶
func (mapper *NodeMapper) Count() int
func (*NodeMapper) Get ¶
func (mapper *NodeMapper) Get(key string) *NodeData
func (*NodeMapper) GetKeys ¶
func (mapper *NodeMapper) GetKeys() []string
func (*NodeMapper) GetNodes ¶
func (mapper *NodeMapper) GetNodes(location string, ipaddr string, hostname string) NodesPair
func (*NodeMapper) Remove ¶
func (mapper *NodeMapper) Remove(key string) int
type NodeStore ¶
func NewNodeStore ¶
func NewNodeStore() *NodeStore
func (*NodeStore) DeadTotalSize ¶
func (*NodeStore) NewTotalSize ¶
func (*NodeStore) RecoveryTotalSize ¶
type PulseHandlerFunc ¶
func (PulseHandlerFunc) OnZkWrapperPulseHandlerFunc ¶
func (fn PulseHandlerFunc) OnZkWrapperPulseHandlerFunc(key string, nodedata *NodeData, err error)
type Server ¶
type Server struct { Key string Root string Pulse time.Duration TimeoutSec float64 Node *Node Data *NodeData Cache *NodeMapper Blacklist *SuspicionMapper Handler INodeNotifyHandler // contains filtered or unexported fields }
func NewServer ¶
func NewServer(key string, args *ServerArgs, handler INodeNotifyHandler) (*Server, error)
func (*Server) GetLocation ¶
func (*Server) GetPlatform ¶
func (*Server) RefreshCache ¶
func (*Server) WatchClose ¶
type ServerArgs ¶
type SuspicionMapper ¶
type SuspicionMapper struct {
// contains filtered or unexported fields
}
func NewSuspicionMapper ¶
func NewSuspicionMapper() *SuspicionMapper
func (*SuspicionMapper) Add ¶
func (mapper *SuspicionMapper) Add(key string) int
func (*SuspicionMapper) Clear ¶
func (mapper *SuspicionMapper) Clear()
func (*SuspicionMapper) Del ¶
func (mapper *SuspicionMapper) Del(key string) int
func (*SuspicionMapper) Get ¶
func (mapper *SuspicionMapper) Get(key string) int64
type WatchHandlerFunc ¶
type WatchObject ¶
type WatchObject struct { Path string // contains filtered or unexported fields }
func CreateWatchObject ¶
func CreateWatchObject(path string, conn *zk.Conn, callback WatchHandlerFunc) *WatchObject
type Worker ¶
type Worker struct { Key string Root string Path string Pulse time.Duration Node *Node Data *NodeData Handler INodeNotifyHandler // contains filtered or unexported fields }
func NewWorker ¶
func NewWorker(key string, args *WorkerArgs, handler INodeNotifyHandler) (*Worker, error)
func (*Worker) GetLocation ¶
func (*Worker) GetPlatform ¶
func (*Worker) WatchClose ¶
Click to show internal directories.
Click to hide internal directories.