Esempio n. 1
0
// Rcvf receives the message and the context.
func Rcvf(msg beehive.Msg, ctx beehive.RcvContext) error {
	// msg is an envelope around the Hello message.
	// You can retrieve the Hello, using msg.Data() and then
	// you need to assert that its a Hello.
	hello := msg.Data().(Hello)
	// Using ctx.Dict you can get (or create) a dictionary.
	dict := ctx.Dict("hello_dict")
	// Using Get(), you can get the value associated with
	// a key in the dictionary. Keys are always string
	// and values are generic interface{}'s.
	v, err := dict.Get(hello.Name)
	// If there is an error, the entry is not in the
	// dictionary. Otherwise, we set cnt based on
	// the value we already have in the dictionary
	// for that name.
	cnt := 0
	if err == nil {
		cnt = v.(int)
	}
	// Now we increment the count.
	cnt++
	// And then we print the hello message.
	ctx.Printf("hello %s (%d)!\n", hello.Name, cnt)
	// Finally we update the count stored in the dictionary.
	return dict.Put(hello.Name, cnt)
}
Esempio n. 2
0
func rcvf(msg bh.Msg, ctx bh.RcvContext) error {
	name := msg.Data().(string)

	cnt := 0
	if v, err := ctx.Dict(helloDict).Get(name); err == nil {
		cnt = v.(int)
	}

	cnt++
	ctx.Printf("hello %s (%d)!\n", name, cnt)
	ctx.Dict(helloDict).Put(name, cnt)
	return nil
}
Esempio n. 3
0
func hostJoinedRcvf(msg bh.Msg, ctx bh.RcvContext) error {
	ctx.Printf("Rcv of HostJoinedHandler Called")
	ctx.Printf("%v", msg.Data().(nom.HostJoined))
	return nil
}