• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang doozer.Conn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/soundcloud/doozer.Conn的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Conn类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: wait

func wait(
	conn *doozer.Conn,
	rev int64,
	root string,
	entryc chan *journal.Entry,
	errc chan error,
) {
	for {
		ev, err := conn.Wait(path.Join(root, "**"), rev+1)
		if err != nil {
			errc <- fmt.Errorf("error waiting for event: %s", err)
			return
		}

		rev = ev.Rev

		var entry *journal.Entry
		if ev.IsSet() {
			entry = journal.NewEntry(ev.Rev, journal.OpSet, ev.Path, ev.Body)
		} else if ev.IsDel() {
			entry = journal.NewEntry(ev.Rev, journal.OpDel, ev.Path, []byte{})
		} else {
			continue
		}

		entryc <- entry
	}
}
开发者ID:soundcloud,项目名称:doozer-journal,代码行数:28,代码来源:replicate.go


示例2: waitFor

func waitFor(cl *doozer.Conn, path string) {
	var rev int64
	for {
		ev, err := cl.Wait(path, rev)
		if err != nil {
			panic(err)
		}
		if ev.IsSet() && len(ev.Body) > 0 {
			break
		}
		rev = ev.Rev + 1
	}
}
开发者ID:zyxar,项目名称:doozerd,代码行数:13,代码来源:misc_test.go


示例3: activate

func activate(st *store.Store, self string, c *doozer.Conn) int64 {
	rev, _ := st.Snap()

	for _, base := range store.Getdir(st, calDir) {
		p := calDir + "/" + base
		v, rev := st.Get(p)
		if rev != store.Dir && v[0] == "" {
			seqn, err := c.Set(p, rev, []byte(self))
			if err != nil {
				log.Println(err)
				continue
			}

			return seqn
		}
	}

	for {
		ch, err := st.Wait(calGlob, rev+1)
		if err != nil {
			panic(err)
		}
		ev, ok := <-ch
		if !ok {
			panic(io.EOF)
		}
		rev = ev.Rev
		// TODO ev.IsEmpty()
		if ev.IsSet() && ev.Body == "" {
			seqn, err := c.Set(ev.Path, ev.Rev, []byte(self))
			if err != nil {
				log.Println(err)
				continue
			}
			return seqn
		} else if ev.IsSet() && ev.Body == self {
			return ev.Seqn
		}
	}

	return 0
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:42,代码来源:peer.go


示例4: follow

func follow(st *store.Store, cl *doozer.Conn, rev int64, stop chan bool) {
	for {
		ev, err := cl.Wait("/**", rev)
		if err != nil {
			panic(err)
		}

		// store.Clobber is okay here because the event
		// has already passed through another store
		mut := store.MustEncodeSet(ev.Path, string(ev.Body), store.Clobber)
		st.Ops <- store.Op{ev.Rev, mut}
		rev = ev.Rev + 1

		select {
		case <-stop:
			return
		default:
		}
	}
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:20,代码来源:peer.go


示例5: elect

// Elect chooses a seed node, and returns a connection to a cal.
// If this process is the seed, returns nil.
func elect(name, id, laddr string, b *doozer.Conn) *doozer.Conn {
	// advertise our presence, since we might become a cal
	nspath := "/ctl/ns/" + name + "/" + id
	r, err := b.Set(nspath, 0, []byte(laddr))
	if err != nil {
		panic(err)
	}

	// fight to be the seed
	_, err = b.Set("/ctl/boot/"+name, 0, []byte(id))
	if err, ok := err.(*doozer.Error); ok && err.Err == doozer.ErrOldRev {
		// we lost, lookup addresses again
		cl := lookupAndAttach(b, name)
		if cl == nil {
			panic("failed to attach after losing election")
		}

		// also delete our entry, since we're not officially a cal yet.
		// it gets set again in peer.Main when we become a cal.
		err := b.Del(nspath, r)
		if err != nil {
			panic(err)
		}

		return cl
	} else if err != nil {
		panic(err)
	}

	return nil // we are the seed node -- don't attach
}
开发者ID:zyxar,项目名称:doozerd,代码行数:33,代码来源:boot.go


示例6: lookup

// Find possible addresses for cluster named name.
func lookup(b *doozer.Conn, name string) (as []string) {
	rev, err := b.Rev()
	if err != nil {
		panic(err)
	}

	path := "/ctl/ns/" + name
	names, err := b.Getdir(path, rev, 0, -1)
	if err == doozer.ErrNoEnt {
		return nil
	} else if err, ok := err.(*doozer.Error); ok && err.Err == doozer.ErrNoEnt {
		return nil
	} else if err != nil {
		panic(err)
	}

	path += "/"
	for _, name := range names {
		body, _, err := b.Get(path+name, &rev)
		if err != nil {
			panic(err)
		}
		as = append(as, string(body))
	}
	return as
}
开发者ID:zyxar,项目名称:doozerd,代码行数:27,代码来源:boot.go


示例7: writer

func writer(
	conn *doozer.Conn,
	root string,
	entryc chan *journal.Entry,
	errc chan error,
) {
	for entry := range entryc {
		if strings.HasPrefix(entry.Path, root) &&
			!strings.HasPrefix(entry.Path, journal.InternalPrefix) {

			var err error
			switch entry.Op {
			case journal.OpSet:
				_, e := conn.Set(entry.Path, -1, entry.Value)
				if e != nil {
					err = fmt.Errorf("unable setting '%s' to '%s'", entry.Path, string(entry.Value))
				}
			case journal.OpDel:
				e := conn.Del(entry.Path, -1)
				if e != nil {
					err = fmt.Errorf("unable deleting '%s'", entry.Path)
				}
			default:
				err = fmt.Errorf("unknown operation %s", entry.Op)
			}

			if err != nil {
				errc <- err
				return
			}

			b, err := journal.Marshal(entry)
			if err != nil {
				continue
			}
			fmt.Println(string(b))
		}
	}
}
开发者ID:soundcloud,项目名称:doozer-journal,代码行数:39,代码来源:replicate.go


示例8: walk

func walk(
	conn *doozer.Conn,
	rev int64,
	entryc chan *journal.Entry,
) doozer.WalkFunc {
	return func(p string, info *doozer.FileInfo, err error) error {
		if err != nil {
			return fmt.Errorf("error walking tree: %s", err)
		}

		if !info.IsDir {
			val, _, err := conn.Get(p, &rev)
			if err != nil {
				return fmt.Errorf("error getting value for '%s': %s", p, err)
			}

			entryc <- journal.NewEntry(-1, journal.OpSet, p, val)
		}

		return nil
	}
}
开发者ID:soundcloud,项目名称:doozer-journal,代码行数:22,代码来源:replicate.go


示例9: Main

// Main has doc
func Main(
	clusterName, self, buri, rwsk, rosk string,
	cl *doozer.Conn,
	udpConn *net.UDPConn,
	listener, webListener net.Listener,
	pulseInterval, fillDelay, kickTimeout, hi int64,
	st *store.Store,
) {
	listenAddr := listener.Addr().String()

	canWrite := make(chan bool, 1)
	in := make(chan consensus.Packet, 1024)

	pr := &proposer{
		seqns: make(chan int64, alpha),
		props: make(chan *consensus.Prop),
		st:    st,
	}

	calSrv := func(start int64) {
		go gc.Pulse(self, st.Seqns, pr, pulseInterval)
		go gc.Clean(st, hi, time.Tick(1e9))
		var m consensus.Manager
		m.Self = self
		m.DefRev = start
		m.Alpha = alpha
		m.In = in
		m.Out = in
		m.Ops = st.Ops
		m.PSeqn = pr.seqns
		m.Props = pr.props
		m.TFill = fillDelay
		m.Store = st
		m.Ticker = time.Tick(10e6)
		go m.Run()
	}

	hostname, err := os.Hostname()
	if err != nil {
		hostname = "unknown"
	}

	if cl == nil { // we are the only node in a new cluster
		set(st, "/ctl/name", clusterName, store.Missing)
		set(st, "/ctl/node/"+self+"/addr", listenAddr, store.Missing)
		set(st, "/ctl/node/"+self+"/hostname", hostname, store.Missing)
		set(st, "/ctl/node/"+self+"/version", Version, store.Missing)
		set(st, "/ctl/cal/0", self, store.Missing)
		if buri == "" {
			set(st, "/ctl/ns/"+clusterName+"/"+self, listenAddr, store.Missing)
		}
		calSrv(<-st.Seqns)
		// Skip ahead alpha steps so that the registrar can provide a
		// meaningful cluster.
		for i := 0; i < alpha; i++ {
			st.Ops <- store.Op{1 + <-st.Seqns, store.Nop}
		}
		canWrite <- true
		go setReady(pr, self)
	} else {
		setC(cl, "/ctl/node/"+self+"/addr", listenAddr, store.Clobber)
		setC(cl, "/ctl/node/"+self+"/hostname", hostname, store.Clobber)
		setC(cl, "/ctl/node/"+self+"/version", Version, store.Clobber)

		rev, err := cl.Rev()
		if err != nil {
			panic(err)
		}

		stop := make(chan bool, 1)

		go follow(st, cl, rev+1, stop)

		err = doozer.Walk(cl, rev, "/", func(path string, f *doozer.FileInfo, e error) (err error) {
			if f.IsDir {
				return
			}
			if e != nil {
				return e
			}
			// store.Clobber is okay here because the event
			// has already passed through another store
			body, _, err := cl.Get(path, &f.Rev)
			if err != nil {
				return
			}
			mut := store.MustEncodeSet(path, string(body), store.Clobber)
			st.Ops <- store.Op{f.Rev, mut}
			return
		})
		if err != nil {
			panic(err)
		}
		st.Flush()

		ch, err := st.Wait(store.Any, rev+1)
		if err == nil {
			<-ch
		}
//.........这里部分代码省略.........
开发者ID:soundcloud,项目名称:doozerd,代码行数:101,代码来源:peer.go


示例10: setC

func setC(cl *doozer.Conn, path, body string, rev int64) {
	_, err := cl.Set(path, rev, []byte(body))
	if err != nil {
		panic(err)
	}
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:6,代码来源:peer.go


示例11: advanceUntil

func advanceUntil(cl *doozer.Conn, ver <-chan int64, done int64) {
	for <-ver < done {
		cl.Nop()
	}
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:5,代码来源:peer.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang store.New函数代码示例发布时间:2022-05-28
下一篇:
Golang cotterpin.Snapshotable类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap