etcd/store/event.go

67 lines
1.6 KiB
Go
Raw Normal View History

// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2013-09-29 03:26:19 +04:00
package store
2013-09-03 22:30:42 +04:00
const (
2013-12-01 03:24:23 +04:00
Get = "get"
Create = "create"
Set = "set"
Update = "update"
Delete = "delete"
CompareAndSwap = "compareAndSwap"
2013-11-30 21:08:25 +04:00
CompareAndDelete = "compareAndDelete"
2013-12-01 03:24:23 +04:00
Expire = "expire"
2013-10-03 09:15:12 +04:00
)
2013-09-03 22:30:42 +04:00
type Event struct {
Action string `json:"action"`
Node *NodeExtern `json:"node,omitempty"`
PrevNode *NodeExtern `json:"prevNode,omitempty"`
EtcdIndex uint64 `json:"-"`
2013-09-03 22:30:42 +04:00
}
2013-11-28 08:04:52 +04:00
func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event {
n := &NodeExtern{
2013-11-10 08:49:19 +04:00
Key: key,
2013-11-28 08:04:52 +04:00
ModifiedIndex: modifiedIndex,
CreatedIndex: createdIndex,
}
return &Event{
Action: action,
Node: n,
2013-09-03 22:30:42 +04:00
}
}
func (e *Event) IsCreated() bool {
if e.Action == Create {
return true
}
return e.Action == Set && e.PrevNode == nil
}
2013-11-10 08:49:19 +04:00
func (e *Event) Index() uint64 {
2013-11-28 08:04:52 +04:00
return e.Node.ModifiedIndex
2013-11-10 08:49:19 +04:00
}
func (e *Event) Clone() *Event {
return &Event{
Action: e.Action,
EtcdIndex: e.EtcdIndex,
Node: e.Node.Clone(),
PrevNode: e.PrevNode.Clone(),
}
}