forked from dt/curator.go
/
event.go
98 lines (70 loc) · 2.89 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package curator
import (
"fmt"
"github.com/samuel/go-zookeeper/zk"
)
type CuratorEventType int
const (
CREATE CuratorEventType = iota // CuratorFramework.Create() -> Err(), Path(), Data()
DELETE // CuratorFramework.Delete() -> Err(), Path()
EXISTS // CuratorFramework.CheckExists() -> Err(), Path(), Stat()
GET_DATA // CuratorFramework.GetData() -> Err(), Path(), Stat(), Data()
SET_DATA // CuratorFramework.SetData() -> Err(), Path(), Stat()
CHILDREN // CuratorFramework.GetChildren() -> Err(), Path(), Stat(), Children()
SYNC // CuratorFramework.Sync() -> Err(), Path()
GET_ACL // CuratorFramework.GetACL() -> Err(), Path()
SET_ACL // CuratorFramework.SetACL() -> Err(), Path()
WATCHED // Watchable.UsingWatcher() -> WatchedEvent()
CLOSING // Event sent when client is being closed
)
var CuratorEventTypeNames = []string{"CREATE", "DELETE", "EXISTS", "GET_DATA", "SET_DATA", "CHILDREN", "SYNC", "GET_ACL", "SET_ACL", "WATCHED", "CLOSING"}
func (t CuratorEventType) String() string {
if int(t) < len(CuratorEventTypeNames) {
return CuratorEventTypeNames[int(t)]
}
return fmt.Sprintf("Type #%d", int(t))
}
// A super set of all the various Zookeeper events/background methods.
type CuratorEvent interface {
// check here first - this value determines the type of event and which methods will have valid values
Type() CuratorEventType
// "rc" from async callbacks
Err() error
// the path
Path() string
// the context object passed to Backgroundable.InBackground(interface{})
Context() interface{}
// any stat
Stat() *zk.Stat
// any data
Data() []byte
// any name
Name() string
// any children
Children() []string
// any ACL list or null
ACLs() []zk.ACL
WatchedEvent() *zk.Event
}
type curatorEvent struct {
eventType CuratorEventType
err error
path string
name string
children []string
context interface{}
stat *zk.Stat
data []byte
watchedEvent *zk.Event
acls []zk.ACL
}
func (e *curatorEvent) Type() CuratorEventType { return e.eventType }
func (e *curatorEvent) Err() error { return e.err }
func (e *curatorEvent) Path() string { return e.path }
func (e *curatorEvent) Context() interface{} { return e.context }
func (e *curatorEvent) Stat() *zk.Stat { return e.stat }
func (e *curatorEvent) Data() []byte { return e.data }
func (e *curatorEvent) Name() string { return e.name }
func (e *curatorEvent) Children() []string { return e.children }
func (e *curatorEvent) ACLs() []zk.ACL { return e.acls }
func (e *curatorEvent) WatchedEvent() *zk.Event { return e.watchedEvent }