当前位置: 首页>>代码示例>>Golang>>正文


Golang Store.Watch方法代码示例

本文整理汇总了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
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:14,代码来源:registrar.go

示例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()
	}
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:12,代码来源:clean.go

示例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)
	}
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:16,代码来源:member.go

示例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)
			}
		}
	}
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:23,代码来源:lock.go

示例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")
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:70,代码来源:mon.go


注:本文中的doozer/store.Store.Watch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。