Exemplo n.º 1
0
func Run(c *Config, j Job) {
	clusterName := j.Id()
	listener := &waffleListener{
		clusterName: clusterName,
		coordinator: newCoordinator(clusterName, c),
		job:         j,
	}
	balancer := &waffleBalancer{}
	config := donut.NewConfig()
	config.Servers = c.ZKServers
	config.NodeId = c.NodeId
	config.Timeout = 1 * 1e9

	cluster := donut.NewCluster(clusterName, config, balancer, listener)

	listener.cluster = cluster
	listener.done = make(chan byte)
	listener.config = config
	listener.coordinator.done = listener.done
	cluster.Join()
	<-listener.done
}
Exemplo n.º 2
0
func main() {
	if len(os.Args) < 3 {
		panic("usage: example <nodeId> <zkserv>")
	}
	listener := &ExampleListener{
		killers: make(map[string]chan byte),
	}
	config := donut.NewConfig()

	config.Servers = []string{os.Args[2]}
	hostname, err := os.Hostname()
	if err != nil {
		panic(err)
	}
	config.NodeId = hostname + "-" + os.Args[1]
	log.Printf("node id is %s", config.NodeId)

	c := donut.NewCluster("example", config, &ExampleBalancer{}, listener)
	listener.c = c
	listener.config = config
	c.Join()
	<-make(chan byte)
}