當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RcvContext.SendToCell方法代碼示例

本文整理匯總了Golang中github.com/kandoo/beehive.RcvContext.SendToCell方法的典型用法代碼示例。如果您正苦於以下問題:Golang RcvContext.SendToCell方法的具體用法?Golang RcvContext.SendToCell怎麽用?Golang RcvContext.SendToCell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/kandoo/beehive.RcvContext的用法示例。


在下文中一共展示了RcvContext.SendToCell方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: confirmFlowEntryForPath

func confirmFlowEntryForPath(flow nom.FlowEntry, ctx bh.RcvContext) error {
	d := ctx.Dict(dictPath)

	v, err := d.Get(flow.ID)
	if err != nil {
		return fmt.Errorf("path: flow not found: %v", err)
	}

	pf := v.(pathAndFlows)

	for i := range pf.Flows {
		if pf.Flows[i].Flow.Equals(flow) {
			if pf.Flows[i].Installed {
				return fmt.Errorf("%v is already installed", flow)
			}
			pf.Flows[i].Installed = true
			pf.Installed++
			break
		}
	}

	if pf.Installed == len(pf.Flows) {
		ctx.SendToCell(nom.PathAdded{Path: pf.Path}, pf.Subscriber.App,
			pf.Subscriber.Cell())
	}
	return d.Put(flow.ID, pf)
}
開發者ID:1995parham,項目名稱:FlyNest,代碼行數:27,代碼來源:flow.go

示例2: Rcv

func (h addFlowHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	add := msg.Data().(nom.AddFlowEntry)
	var nf nodeFlows
	if v, err := ctx.Dict(flowsDict).Get(string(add.Flow.Node)); err == nil {
		nf = v.(nodeFlows)
	}
	added := nom.FlowEntryAdded{Flow: add.Flow}
	if nf.maybeAddFlow(add) {
		ctx.Emit(added)
		sendToMaster(add, add.Flow.Node, ctx)
	}
	if !add.Subscriber.IsNil() {
		ctx.SendToCell(added, add.Subscriber.App, add.Subscriber.Cell())
	}
	return ctx.Dict(flowsDict).Put(string(add.Flow.Node), nf)
}
開發者ID:1995parham,項目名稱:FlyNest,代碼行數:16,代碼來源:flow.go

示例3: Rcv

func (c Consolidator) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	res := msg.Data().(nom.FlowStatsQueryResult)
	var nf nodeFlows
	if v, err := ctx.Dict(flowsDict).Get(string(res.Node)); err == nil {
		nf = v.(nodeFlows)
	}
	var nt nodeTriggers
	if v, err := ctx.Dict(triggersDict).Get(string(res.Node)); err == nil {
		nt = v.(nodeTriggers)
	}
	found := false
	matchedFlows := make(map[int]struct{})
	for _, stat := range res.Stats {
		for i := range nf.Flows {
			if nf.Flows[i].FlowEntry.Match.Equals(stat.Match) {
				found = true
				matchedFlows[i] = struct{}{}
				nf.Flows[i].updateStats(stat)
			}
		}
		if !found {
			nf.Flows = append(nf.Flows, flow{
				FlowEntry: nom.FlowEntry{
					Match: stat.Match,
				},
				Duration: stat.Duration,
				Packets:  stat.Packets,
				Bytes:    stat.Bytes,
			})
			// TODO(soheil): emit flow entry here.
		}

		for _, t := range nt.Triggers {
			if t.Fired(stat) {
				triggered := newTriggered(t, stat.Duration, stat.BW())
				sub := t.Subscriber
				if !sub.IsNil() {
					ctx.SendToCell(triggered, sub.App, sub.Cell())
				}
			}
		}
	}

	count := 0
	for i, f := range nf.Flows {
		if _, ok := matchedFlows[i]; ok {
			continue
		}

		i -= count
		nf.Flows = append(nf.Flows[:i], nf.Flows[i+1:]...)
		count++
		del := nom.FlowEntryDeleted{
			Flow: f.FlowEntry,
		}
		ctx.Emit(del)
		for _, sub := range f.FlowSubscribers {
			if !sub.IsNil() {
				ctx.SendToCell(del, sub.App, sub.Cell())
			}
		}
	}

	return ctx.Dict(flowsDict).Put(string(res.Node), nf)
}
開發者ID:jaminp,項目名稱:beehive-netctrl,代碼行數:65,代碼來源:consolidator.go


注:本文中的github.com/kandoo/beehive.RcvContext.SendToCell方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。