本文整理匯總了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")
}