Example #1
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()
}
Example #2
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()
}
Example #3
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()
}
Example #4
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{})
		}
	}()
}
Example #5
0
// emitPod emits discovery messages for the links of a pod p in a k-ary fat-tree
// network. Note that 1 <= p <= k.
func emitPod(p int, k int) error {
	if p < 1 || p > k {
		return fmt.Errorf("No pod #%d in a %d-ary fat-tree", p, k)
	}

	// Emit internal links in the pod.
	for e := 1; e <= k/2; e++ {
		edgeN := routing.Node{
			ID: fmt.Sprintf("E-%d-%d", p, e),
		}
		for h := 1; h <= k/2; h++ {
			hostN := routing.Node{
				ID:      fmt.Sprintf("H-%d-%d-%d", p, e, h),
				Endhost: true,
			}
			bh.Emit(routing.Discovery(routing.Edge{
				From: edgeN,
				To:   hostN,
			}))
			bh.Emit(routing.Discovery(routing.Edge{
				From: hostN,
				To:   edgeN,
			}))
		}
		for a := 1; a <= k/2; a++ {
			aggrN := routing.Node{
				ID: fmt.Sprintf("A-%d-%d", p, a),
			}
			bh.Emit(routing.Discovery(routing.Edge{
				From: edgeN,
				To:   aggrN,
			}))
			bh.Emit(routing.Discovery(routing.Edge{
				From: aggrN,
				To:   edgeN,
			}))
			fmt.Printf("%v <-> %v\n", aggrN, edgeN)
		}
	}

	// Emit uplinks to core switches.
	for a := 1; a <= k/2; a++ {
		aggrN := routing.Node{
			ID: fmt.Sprintf("A-%d-%d", p, a),
		}
		for c := k/2*(a-1) + 1; c <= k/2*a; c++ {
			coreN := routing.Node{
				ID: fmt.Sprintf("C-%d", c),
			}
			bh.Emit(routing.Discovery(routing.Edge{
				From: aggrN,
				To:   coreN,
			}))
			bh.Emit(routing.Discovery(routing.Edge{
				From: coreN,
				To:   aggrN,
			}))
			fmt.Printf("%v <-> %v\n", coreN, aggrN)
		}
	}

	return nil
}