当前位置: 首页>>代码示例>>Golang>>正文


Golang beehive.Msg类代码示例

本文整理汇总了Golang中github.com/kandoo/beehive.Msg的典型用法代码示例。如果您正苦于以下问题:Golang Msg类的具体用法?Golang Msg怎么用?Golang Msg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Msg类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Rcv

func (h EnQHandler) Rcv(msg beehive.Msg, ctx beehive.RcvContext) error {
	enq := msg.Data().(Enque)
	dict := ctx.Dict(active)

	next := TaskID(1)
	if v, err := dict.Get("_next_"); err == nil {
		next = v.(TaskID)
	}

	key := next.String()
	task := Task{
		Queue: enq.Queue,
		ID:    next,
		Body:  enq.Body,
	}
	if err := dict.Put(key, task); err != nil {
		return err
	}

	if err := dict.Put("_next_", next+1); err != nil {
		return err
	}

	enqued := Enqued{
		ID:     enq.ID,
		Queue:  enq.Queue,
		TaskID: next,
	}
	return ctx.Reply(msg, enqued)
}
开发者ID:jyzhe,项目名称:beehive,代码行数:30,代码来源:server.go

示例2: Map

// Rcv maps Discovery based on its destination node and Advertisement messages
// based on their source node.
func (m RouterM) Map(msg bh.Msg, ctx bh.MapContext) bh.MappedCells {
	switch dm := msg.Data().(type) {
	case InterAreaQuery:
		return bh.MappedCells{{"__D__", "__0__"}}
	case InterAreaLink:
		return bh.MappedCells{{"__D__", "__0__"}}
	case area_setup:
		return bh.MappedCells{{"__D__", "__0__"}}
	case setupM:
		areaMsg := msg.Data().(setupM)
		return bh.MappedCells{{"area", areaMsg.area}}
	case nom.LinkAdded:
		link := nom.Link(dm)
		nf, _ := nom.ParsePortUID(link.From)
		k := string(nf)
		nt, _ := nom.ParsePortUID(link.To)
		k2 := string(nt)
		nf_area := FindAreaId(k)
		nt_area := FindAreaId(k2)
		if nt_area != nf_area {
			return bh.MappedCells{{"__D__", "__0__"}}
		} else {
			return bh.MappedCells{{"area", nf_area}}
		}
	case nom.PacketIn:
		ni := msg.Data().(nom.PacketIn)
		k := string(ni.Node)
		return bh.MappedCells{{"area", FindAreaId(k)}}
	}
	return bh.MappedCells{{"__D__", "__0__"}}
}
开发者ID:jyzhe,项目名称:beehive-netctrl,代码行数:33,代码来源:router-kenan.go

示例3: Rcv

func (c *Calculator) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	op := msg.Data().(Op)
	res := c.calc(op)
	fmt.Printf("%d %s %d = %d\n", op.Lhs, op.OpT, op.Rhs, res)
	ctx.Reply(msg, res)
	return nil
}
开发者ID:jyzhe,项目名称:beehive,代码行数:7,代码来源:calc.go

示例4: Rcv

func (h *intentHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	hrq := msg.Data().(http.HTTPRequest)
	if hrq.AppName == "intent" && hrq.Verb == "build" {
		spd := shortestPathData{}
		err := json.Unmarshal(hrq.Data, &spd)
		if err != nil {
			glog.Errorf("Host list JSON unmarshaling: %v", err)
			return err
		}
		fmt.Println(spd)
		fmt.Println(discovery.ShortestPathCentralized(spd.From, spd.To, ctx))

		hrs := http.HTTPResponse{
			AppName: "host",
			Data:    []byte{'A'},
		}

		err = ctx.Reply(msg, hrs)
		if err != nil {
			glog.Errorf("Replay error: %v", err)
			return err
		}
	}
	return nil

}
开发者ID:1995parham,项目名称:FlyNest,代码行数:26,代码来源:intent.go

示例5: BeeHandler

// The bee hander
func BeeHandler(
	beehiveMessage beehive.Msg,
	beeContext beehive.RcvContext) error {
	// beehiveMessage is an envelope around the Hello message.
	// You can retrieve the Hello, using msg.Data() and then
	// you need to assert that its a MessageToBee.
	message := beehiveMessage.Data().(MessageToBee)
	// Using ctx.Dict you can get (or create) a dictionary.
	dict := beeContext.Dict("beehive-app-dict")
	value, err := dict.Get(message.DestinationBee)

	logger.Trace.Printf("[BeeHandler] Message sent to bee with id (%s) \n",
		message.DestinationBee)

	count := 0
	if err == nil {
		// No error mean there is already an item with given key
		count = value.(int)
	}
	count++
	logger.Trace.Printf("[BeeHandler] Count = %d\n",
		count)

	logger.Trace.Printf("[BeeHandler] Calculate fib number %d\n",
		message.FibNumber)
	Fib(message.FibNumber)

	beeContext.Reply(beehiveMessage, count)
	return dict.Put(message.DestinationBee, count)
}
开发者ID:g2minhle,项目名称:bee-reallocation-beehive-2016,代码行数:31,代码来源:main.go

示例6: Rcvf

// 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)
}
开发者ID:jyzhe,项目名称:beehive,代码行数:27,代码来源:example_test.go

示例7: Rcv

func (h HealthChecker) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	db := msg.From()
	dict := ctx.Dict(driversDict)

	dict.ForEach(func(k string, v interface{}) {
		nd := v.(nodeDrivers)
		updated := false
		for i := range nd.Drivers {
			if nd.Drivers[i].BeeID == db {
				nd.Drivers[i].LastSeen = time.Now()
				// TODO(soheil): Maybe if outpings was more than MaxPings we
				// should emit a connected message.
				nd.Drivers[i].OutPings--
				updated = true
			}
		}

		if !updated {
			return
		}

		if err := dict.Put(k, nd); err != nil {
			glog.Warningf("error in encoding drivers: %v", err)
		}
	})

	return nil
}
开发者ID:jaminp,项目名称:beehive-netctrl,代码行数:28,代码来源:health.go

示例8: Rcv

func (b GraphBuilderCentralized) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	dict := ctx.Dict(GraphDict)
	var link nom.Link
	switch dm := msg.Data().(type) {
	case nom.LinkAdded:
		link = nom.Link(dm)
	case nom.LinkDeleted:
		link = nom.Link(dm)
	default:
		return fmt.Errorf("GraphBuilderCentralized: unsupported message type %v",
			msg.Type())
	}

	nf, _ := nom.ParsePortUID(link.From)
	nt, _ := nom.ParsePortUID(link.To)

	if nf == nt {
		return fmt.Errorf("%v is a loop", link)
	}

	k := string(nf)
	links := make(map[nom.UID][]nom.Link)
	if v, err := dict.Get(k); err == nil {
		links = v.(map[nom.UID][]nom.Link)
	}
	links[nt.UID()] = append(links[nt.UID()], link)
	return dict.Put(k, links)
}
开发者ID:dknyxh,项目名称:beehive-netctrl,代码行数:28,代码来源:graph.go

示例9: Rcv

func (h *arpPktInHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	pin := msg.Data().(nom.PacketIn)
	p := gopacket.NewPacket([]byte(pin.Packet), layers.LayerTypeEthernet, gopacket.Default)
	etherlayer := p.Layer(layers.LayerTypeEthernet)

	if etherlayer == nil {
		return nil
	}

	e, _ := etherlayer.(*layers.Ethernet)

	if e.EthernetType != layers.EthernetTypeARP {
		return nil
	}

	host, _, err := decodeARP([]byte(pin.Packet))
	host.Node = pin.Node

	if err != nil {
		glog.Errorf("ARP decoding error: %v", err)
		return err
	}
	glog.V(2).Infof("Host detected: %v", host)

	ctx.Emit(nom.HostConnected(host))

	return nil
}
开发者ID:1995parham,项目名称:FlyNest,代码行数:28,代码来源:host.go

示例10: Rcv

func (h *newLinkHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	l := nom.Link(msg.Data().(NewLink))
	n, _ := nom.ParsePortUID(l.From)
	d := ctx.Dict(nodeDict)
	k := string(n)
	v, err := d.Get(k)
	if err != nil {
		return nil
	}

	np := v.(nodePortsAndLinks)

	if oldl, ok := np.linkFrom(l.From); ok {
		if oldl.UID() == l.UID() {
			return nil
		}
		np.removeLink(oldl)
		ctx.Emit(nom.LinkDeleted(oldl))
	}

	glog.V(2).Infof("Link detected %v", l)
	ctx.Emit(nom.LinkAdded(l))
	np.L = append(np.L, l)
	return d.Put(k, np)
}
开发者ID:jyzhe,项目名称:beehive-netctrl,代码行数:25,代码来源:discovery.go

示例11: Rcv

func (d *Driver) Rcv(m beehive.Msg, ctx beehive.RcvContext) error {
	if m.NoReply() {
		return nil
	}

	q, ok := m.Data().(StatQuery)
	if !ok {
		return nil
	}

	s, ok := d.switches[q.Switch]
	if !ok {
		return fmt.Errorf("No switch stored in the driver: %+v", s)
	}

	for i, f := range s.Flows {
		f.Bytes += uint64(rand.Intn(maxSpike))
		s.Flows[i] = f
		glog.V(2).Infof("Emitting stat result for %+v", f)
		ctx.Emit(StatResult{q, f.Flow, f.Bytes})
	}

	d.switches[q.Switch] = s
	return nil
}
开发者ID:jyzhe,项目名称:beehive,代码行数:25,代码来源:driver.go

示例12: Map

func (h AckHandler) Map(msg beehive.Msg,
	ctx beehive.MapContext) beehive.MappedCells {

	// Send the Ack message to the bee that owns queues/q.
	q := string(msg.Data().(Ack).Queue)
	return beehive.MappedCells{{queues, q}}
}
开发者ID:jyzhe,项目名称:beehive,代码行数:7,代码来源:server.go

示例13: Rcv

func (c *Collector) Rcv(m beehive.Msg, ctx beehive.RcvContext) error {
	res := m.Data().(StatResult)
	glog.V(2).Infof("Stat results: %+v", res)
	matrix := ctx.Dict(matrixDict)
	key := res.Switch.Key()
	v, err := matrix.Get(key)
	if err != nil {
		return fmt.Errorf("No such switch in matrix: %+v", res)
	}

	c.poller.query <- StatQuery{res.Switch}

	sw := v.(SwitchStats)
	stat, ok := sw[res.Flow]
	sw[res.Flow] = res.Bytes

	glog.V(2).Infof("Previous stats: %+v, Now: %+v", stat, res.Bytes)
	if !ok || res.Bytes-stat > c.delta {
		glog.Infof("Found an elephent flow: %+v, %+v, %+v", res, stat,
			ctx.Hive().ID())
		ctx.Emit(MatrixUpdate(res))
	}

	matrix.Put(key, sw)
	return nil
}
开发者ID:jyzhe,项目名称:beehive,代码行数:26,代码来源:collect.go

示例14: Rcv

func (h portStatusHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	// FIXME(soheil): This implementation is very naive and cannot tolerate
	// faults. We need to first check if the driver is the mater, and then apply
	// the change. Otherwise, we need to enque this message for that driver and
	// make sure we apply the log to the port status
	data := msg.Data().(nom.PortStatusChanged)
	dict := ctx.Dict(driversDict)
	k := string(data.Port.Node)
	v, err := dict.Get(k)
	if err != nil {
		return fmt.Errorf("NOMController: node %v not found", data.Port.Node)
	}
	n := v.(nodeDrivers)

	if !n.isMaster(data.Driver) {
		glog.Warningf("NOMController: %v ignored, %v is not master, master is %v",
			data.Port, data.Driver, n.master())
		return nil
	}

	if p, ok := n.Ports.GetPort(data.Port.UID()); ok {
		if p == data.Port {
			return fmt.Errorf("NOMController: duplicate port status change for %v",
				data.Port)
		}

		n.Ports.DelPort(p)
	}

	n.Ports.AddPort(data.Port)
	ctx.Emit(nom.PortUpdated(data.Port))
	return nil
}
开发者ID:dknyxh,项目名称:beehive-netctrl,代码行数:33,代码来源:port.go

示例15: Rcv

func (h addHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	add := msg.Data().(nom.AddPath)

	if len(add.Path.Pathlets) == 0 {
		return errors.New("path: path has no pathlets")
	}

	flows := make([]nom.FlowEntry, 0, len(add.Path.Pathlets))
	// TODO(soheil): maybe detect loops in pathlets?
	var outports []nom.UID
	var newflows []nom.FlowEntry
	var err error
	for _, p := range add.Path.Pathlets {
		if len(outports) == 0 {
			newflows, outports, err = genFlowsForPathlet(p, nom.Nil,
				add.Path.Priority, ctx)
			if err != nil {
				return err
			}
			flows = append(flows, newflows...)
			continue
		}

		inps := inPortsFromOutPorts(outports, ctx)
		outports = outports[0:0]
		for _, inp := range inps {
			newflows, newoutports, err := genFlowsForPathlet(p, inp,
				add.Path.Priority, ctx)
			if err != nil {
				return err
			}
			outports = append(outports, newoutports...)
			flows = append(flows, newflows...)
		}
	}

	uniqueFlows := make([]nom.FlowEntry, 0, len(flows))
nextFlow:
	for i, fi := range flows {
		for j, fj := range flows {
			if i == j {
				continue
			}

			if fj.Subsumes(fi) {
				continue nextFlow
			}

			// TODO(soheil): check for subsumption and merge flows if possible.
			if j < i && fj.Equals(fi) {
				continue nextFlow
			}
		}
		uniqueFlows = append(uniqueFlows, fi)
	}
	addFlowEntriesForPath(add.Subscriber, add.Path, uniqueFlows, ctx)
	return nil
}
开发者ID:dknyxh,项目名称:beehive-netctrl,代码行数:58,代码来源:path.go


注:本文中的github.com/kandoo/beehive.Msg类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。