blob: 8463747515695d1b877383bc3c03a8a61eb84dcb [file] [log] [blame]
khenaidoocfee5f42018-07-19 22:47:38 -04001package kvstore
2
3const (
4 // Default timeout in seconds when making a kvstore request
5 defaultKVGetTimeout = 5
6 // Maximum channel buffer between publisher/subscriber goroutines
7 maxClientChannelBufferSize = 10
8)
9
10// These constants represent the event types returned by the KV client
11const (
12 PUT = iota
13 DELETE
14 CONNECTIONDOWN
15 UNKNOWN
16)
17
18// KVPair is a common wrapper for key-value pairs returned from the KV store
19type KVPair struct {
20 Key string
21 Value interface{}
22 Session string
23 Lease int64
24}
25
26// NewKVPair creates a new KVPair object
27func NewKVPair(key string, value interface{}, session string, lease int64) *KVPair {
28 kv := new(KVPair)
29 kv.Key = key
30 kv.Value = value
31 kv.Session = session
32 kv.Lease = lease
33 return kv
34}
35
36// Event is generated by the KV client when a key change is detected
37type Event struct {
38 EventType int
39 Key interface{}
40 Value interface{}
41}
42
43// NewEvent creates a new Event object
44func NewEvent(eventType int, key interface{}, value interface{}) *Event {
45 evnt := new(Event)
46 evnt.EventType = eventType
47 evnt.Key = key
48 evnt.Value = value
49
50 return evnt
51}
52
53// Client represents the set of APIs a KV Client must implement
54type Client interface {
55 List(key string, timeout int) (map[string]*KVPair, error)
56 Get(key string, timeout int) (*KVPair, error)
57 Put(key string, value interface{}, timeout int) error
58 Delete(key string, timeout int) error
59 Reserve(key string, value interface{}, ttl int64) (interface{}, error)
60 ReleaseReservation(key string) error
61 ReleaseAllReservations() error
62 RenewReservation(key string) error
63 Watch(key string) chan *Event
64 CloseWatch(key string, ch chan *Event)
65 Close()
66}