本文整理汇总了Golang中doozer/store.Store.Watch方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.Watch方法的具体用法?Golang Store.Watch怎么用?Golang Store.Watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类doozer/store.Store
的用法示例。
在下文中一共展示了Store.Watch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewRegistrar
// This thing keeps track of who is supposed to be in the cluster for every
// seqn. It also remembers the network address of every member.
// TODO remove the `start` param when store.Get provides a version
func NewRegistrar(st *store.Store, start uint64, alpha int) *Registrar {
rg := &Registrar{
alpha: alpha,
st: st,
evs: st.Watch("**"), // watch absolutely everything
lookupCh: make(chan *lookup),
lookups: new(lookupQueue),
}
go rg.process(start, readdirMap(st, membersKey), readdirMap(st, slotKey))
return rg
}
示例2: Clean
func Clean(st *store.Store) {
cl := &cleaner{
st: st,
table: make(map[string]uint64),
logger: util.NewLogger("clean"),
}
for ev := range st.Watch("/doozer/info/*/applied") {
cl.update(ev)
cl.check()
}
}
示例3: Clean
func Clean(st *store.Store, p paxos.Proposer) {
logger := util.NewLogger("member")
for ev := range st.Watch("/session/*") {
if !ev.IsDel() {
continue
}
parts := strings.Split(ev.Path, "/", 3)
name := parts[2]
logger.Printf("lost session %s", name)
clearSlot(p, ev, name)
removeMember(p, ev, name)
removeInfo(p, ev, name)
}
}
示例4: Clean
func Clean(st *store.Store, pp paxos.Proposer) {
logger := util.NewLogger("lock")
for ev := range st.Watch("/session/*") {
if !ev.IsDel() {
continue
}
parts := strings.Split(ev.Path, "/", 3)
name := parts[2]
logger.Printf("lost session %s", name)
ch, err := store.Walk(ev, "/lock/**")
if err != nil {
continue
}
for ev := range ch {
if ev.Body == name {
paxos.Del(pp, ev.Path, ev.Cas)
}
}
}
}
示例5: Monitor
func Monitor(self string, st *store.Store, cl SetDeler) os.Error {
mon := &monitor{
self: self,
st: st,
cl: cl,
clock: make(chan ticker),
units: make(map[string]unit),
refs: make(map[string]int),
exitCh: make(chan exit),
readyCh: make(chan ready),
logger: util.NewLogger("monitor"),
}
mon.logger.Println("reading units")
evs := make(chan store.Event)
st.GetDirAndWatch(ctlKey, evs)
go func(c <-chan store.Event) {
for e := range c {
evs <- e
}
close(evs)
}(st.Watch(lockKey + "/*"))
for {
select {
case t := <-mon.clock:
t.tick()
case ev := <-evs:
prefix, id := path.Split(ev.Path)
switch prefix {
case ctlDir:
if ev.IsDel() {
mon.logger.Println("\n\n\ndel", id)
mon.decrefUnit(id)
break
}
ut := mon.increfUnit(id)
if ut == nil {
break
}
switch ev.Body {
case "start":
ut.start()
case "stop":
ut.stop()
case "auto", "":
fallthrough
default:
// nothing
}
case lockDir:
ut := mon.units[id]
if ut == nil {
break
}
ut.dispatchLockEvent(ev)
}
case e := <-mon.exitCh:
e.e.exited(e.w)
case r := <-mon.readyCh:
r.r.ready(r.f)
}
}
panic("unreachable")
}