Пример #1
0
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())
	if *quiet {
		log.SetOutput(ioutil.Discard)
	}

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			glog.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	opts := []bh.AppOption{bh.Persistent(*replFactor)}
	if *random {
		rp := bh.RandomPlacement{
			Rand: rand.New(rand.NewSource(time.Now().UnixNano())),
		}
		opts = append(opts, bh.Placement(rp))
	}
	a := bh.NewApp("kvstore", opts...)
	kv := &store.KVStore{
		Hive:    bh.DefaultHive,
		Buckets: uint64(*buckets),
	}
	a.Handle(store.Put{}, kv)
	a.Handle(store.Get(""), kv)
	a.Handle(store.Del(""), kv)
	a.HandleHTTP("/{key}", kv)

	bh.Start()
}
Пример #2
0
func main() {
	flag.Parse()

	if *k%2 != 0 || *from < 1 || *to < 1 || *k < *from || *k < *to {
		log.Fatal("Invalid parameters", *from, *to, *k)
	}

	flag.Parse()
	if *cpuProfile != "" {
		f, err := os.Create(*cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	routing.InstallRouting(*epoc)

	chrono := bh.NewApp("Chrono")
	ch := make(chan bool, 1024)
	cnt := 0
	rcvF := func(msg bh.Msg, ctx bh.RcvContext) error {
		if cnt++; cnt%1024 == 0 {
			ch <- true
		}
		return nil
	}
	mapF := func(msg bh.Msg, ctx bh.MapContext) bh.MappedCells {
		return ctx.LocalMappedCells()
	}
	chrono.HandleFunc(routing.Advertisement{}, mapF, rcvF)

	start := time.Now()
	for p := *from; p <= *to; p++ {
		go func(p int) {
			if err := emitPod(p, *k); err != nil {
				panic(err)
			}
		}(p)
	}
	go func() {
		bh.Start()
		close(ch)
	}()

	finish := time.Now()
	for {
		select {
		case _, ok := <-ch:
			if !ok {
				return
			}
			finish = time.Now()
		case <-time.After(*idleTimeout):
			log.Printf("Took %v (%v-%v)", finish.Sub(start), start, finish)
		}
	}
}
Пример #3
0
func Example_hTTP() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(HelloHTTP{}, beehive.RuntimeMap(RcvfHTTP), RcvfHTTP)
	// Register the HTTP handler for the hello world application.
	app.HandleHTTP("/{name}", &HelloHTTPHandler{}).Methods("POST")
	// Start the DefaultHive.
	beehive.Start()
}
Пример #4
0
func Example_detached() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(HelloDetached{},
		beehive.RuntimeMap(RcvfDetached), RcvfDetached)
	// Register the detached handler for the hello world listener.
	app.Detached(NewHelloListener())
	// Start the DefaultHive.
	beehive.Start()
}
Пример #5
0
func main() {
	shouldPing := flag.Bool("ping", false, "Whether to ping.")
	shouldPong := flag.Bool("pong", false, "Whether to pong.")

	pingApp := bh.NewApp("Ping", bh.Persistent(2))
	pingApp.Handle(pong{}, &pinger{})

	pongApp := bh.NewApp("Pong", bh.Persistent(2))
	pongApp.Handle(ping{}, &ponger{})

	if *shouldPing {
		bh.Emit(ping{})
	}

	if *shouldPong {
		bh.Emit(pong{})
	}

	bh.Start()
}
Пример #6
0
func main() {
	app := bh.NewApp("HelloWorld", bh.Persistent(1))
	app.HandleFunc(string(""), mapf, rcvf)

	name1 := "1st name"
	name2 := "2nd name"
	for i := 0; i < 3; i++ {
		go bh.Emit(name1)
		go bh.Emit(name2)
	}

	bh.Start()
}
Пример #7
0
func Example() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(Hello{}, beehive.RuntimeMap(Rcvf), Rcvf)
	// Emit simply emits a message, here a
	// string of your name.
	go beehive.Emit(Hello{Name: "your name"})
	// Emit another message with the same name
	// to test the counting feature.
	go beehive.Emit(Hello{Name: "your name"})
	// Start the DefualtHive.
	beehive.Start()
}
Пример #8
0
// InstallRouting installs the routing application on bh.DefaultHive.
// timeout is the duration between each epoc of routing advertisements.
func InstallRouting(timeout time.Duration) {
	app := bh.NewApp("Routing")
	router := Router{}
	app.Handle(Advertisement{}, router)
	app.Handle(Discovery{}, router)
	app.Handle(Timeout{}, router)
	go func() {
		ticker := time.NewTicker(timeout)
		for {
			<-ticker.C
			bh.Emit(Timeout{})
		}
	}()
}
func main() {
	logger.InitDefault()
	logger.Trace.Println("[main] Init beehive app")
	// Create the application and
	beehiveApp := beehive.NewApp("beehive-app", beehive.Persistent(0))
	// Register the handler for MessageToBee messages.
	beehiveApp.HandleFunc(
		MessageToBee{},
		beehive.RuntimeMap(BeeHandler),
		BeeHandler)

	initHTTPHandler(beehiveApp)

	logger.Trace.Println("[main] Start beehive")
	beehive.Start()
}
Пример #10
0
func Example_reply() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(HelloReply{}, beehive.RuntimeMap(RcvfReply), RcvfReply)

	// Start the default hive.
	go beehive.Start()
	defer beehive.Stop()

	name := "your name"
	for i := 0; i < 2; i++ {
		// Sync sends the Hello message and waits until it receives the reply.
		res, err := beehive.Sync(context.TODO(), HelloReply{Name: name})
		if err != nil {
			glog.Fatalf("error in sending Hello: %v", err)
		}
		cnt := res.(int)
		fmt.Printf("hello %s (%d)!\n", name, cnt)
	}
}