Ejemplo n.º 1
0
func activate(st *store.Store, self string, c *doozer.Client) int64 {
	w := store.NewWatch(st, calGlob)

	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
			}

			w.Stop()
			return seqn
		}
	}

	for ev := range w.C {
		// 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
			}
			w.Stop()
			return seqn
		}
	}

	return 0
}
Ejemplo n.º 2
0
Archivo: member.go Proyecto: kr/doozer
func getName(addr string, g store.Getter) string {
	for _, name := range store.Getdir(g, "/ctl/node") {
		if store.GetString(g, "/ctl/node/"+name+"/addr") == addr {
			return name
		}
	}
	return ""
}
Ejemplo n.º 3
0
func getAddrs(g store.Getter) map[string]bool {
	// TODO include only CALs, once followers use TCP for updates.

	ids := store.Getdir(g, "/ctl/node")
	addrs := make(map[string]bool)

	for _, id := range ids {
		addrs[store.GetString(g, "/ctl/node/"+id+"/addr")] = true
	}

	return addrs
}
Ejemplo n.º 4
0
func getCals(g store.Getter) []string {
	ents := store.Getdir(g, "/ctl/cal")
	cals := make([]string, len(ents))

	i := 0
	for _, cal := range ents {
		id := store.GetString(g, "/ctl/cal/"+cal)
		if id != "" {
			cals[i] = id
			i++
		}
	}

	cals = cals[0:i]
	sort.Strings(cals)

	return cals
}
Ejemplo n.º 5
0
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(os.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
}