本文整理汇总了Golang中github.com/kandoo/beehive.RcvContext类的典型用法代码示例。如果您正苦于以下问题:Golang RcvContext类的具体用法?Golang RcvContext怎么用?Golang RcvContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RcvContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: NodesCentralized
// NodesCentralized returns the nodes with outgoing links so far.
//
// Note that this methods should be used only when the GraphBuilderCentralized
// is in use.
func NodesCentralized(ctx bh.RcvContext) (nodes []nom.UID) {
ctx.Dict(GraphDict).ForEach(func(k string, v interface{}) bool {
nodes = append(nodes, nom.UID(k))
return true
})
return nodes
}
开发者ID:dknyxh,项目名称:beehive-netctrl,代码行数:11,代码来源:graph.go
示例8: 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
示例9: Rcv
// Rcv method of the composed handler.
func (c *ComposedHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
var err error
for i := range c.Handlers {
if c.Isolate {
rctx := composedRcvContext{RcvContext: ctx, prefix: strconv.Itoa(i)}
err = c.callRcv(c.Handlers[i], msg, rctx)
} else {
err = c.callRcv(c.Handlers[i], msg, ctx)
}
switch c.Composer(msg, ctx, err) {
case Abort:
ctx.AbortTx()
return nil
case Commit:
ctx.CommitTx()
return nil
case Continue:
if i == len(c.Handlers)-1 {
if err == nil {
ctx.CommitTx()
} else {
ctx.AbortTx()
}
return nil
}
case ContinueOrAbort:
if i == len(c.Handlers)-1 {
ctx.AbortTx()
return nil
}
}
}
return nil
}
开发者ID:jyzhe,项目名称:beehive,代码行数:36,代码来源:composition.go
示例10: 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
示例11: Rcv
func (h *httpHostListHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
hrq := msg.Data().(http.HTTPRequest)
if hrq.AppName == "host" && hrq.Verb == "list" {
dict := ctx.Dict(hostDict)
v, err := dict.Get("hsts")
hsts := []nom.Host{}
if err == nil {
hsts = v.([]nom.Host)
}
data, err := json.Marshal(hsts)
if err != nil {
glog.Errorf("Host list JSON marshaling: %v", err)
return err
}
fmt.Println(hsts)
hrs := http.HTTPResponse{
AppName: "host",
Data: data,
}
err = ctx.Reply(msg, hrs)
if err != nil {
glog.Errorf("Replay error: %v", err)
return err
}
}
return nil
}
开发者ID:1995parham,项目名称:FlyNest,代码行数:32,代码来源:host.go
示例12: 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
示例13: handleAck
func (h *ConnHandler) handleAck(req ReqID, ctx beehive.RcvContext,
r *bufio.Reader) error {
q, err := r.ReadString(' ')
if err != nil {
return err
}
q = q[:len(q)-1]
s, err := r.ReadString('\n')
if err != nil {
return err
}
s = dropNewLine(s)
tid, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return err
}
ctx.Emit(Ack{
ID: req,
Queue: Queue(q),
TaskID: TaskID(tid),
})
return nil
}
开发者ID:jyzhe,项目名称:beehive,代码行数:27,代码来源:server.go
示例14: 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
示例15: startOFConn
func (l *ofListener) startOFConn(conn net.Conn, ctx bh.RcvContext) {
ofc := &ofConn{
HeaderConn: of.NewHeaderConn(conn),
readBufLen: l.readBufLen,
}
ctx.StartDetached(ofc)
}
开发者ID:1995parham,项目名称:FlyNest,代码行数:8,代码来源:listener.go
示例16: neighbors
func (r Router) neighbors(node Node, ctx bh.RcvContext) Edges {
dict := ctx.Dict(neighDict)
var neighs Edges
if v, err := dict.Get(node.Key()); err == nil {
neighs = v.(Edges)
}
return neighs
}
开发者ID:jyzhe,项目名称:beehive,代码行数:8,代码来源:routing.go
示例17: Rcv
func (p Poller) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
ctx.Dict("Switches").ForEach(func(k string, v interface{}) {
fmt.Printf("poller: polling switch %v\n", k)
ctx.Emit(nom.FlowStatsQuery{
Node: nom.UID(k),
})
})
return nil
}
开发者ID:jaminp,项目名称:beehive-netctrl,代码行数:9,代码来源:detect.go
示例18: appendNieghbor
func (r Router) appendNieghbor(edge Edge, ctx bh.RcvContext) error {
neighs := r.neighbors(edge.To, ctx)
if neighs.Contains(edge) {
return fmt.Errorf("%v is already a neighbor", edge)
}
neighs = append(neighs, edge)
ctx.Dict(neighDict).Put(edge.To.Key(), neighs)
return nil
}
开发者ID:jyzhe,项目名称:beehive,代码行数:9,代码来源:routing.go
示例19: Rcv
func (h *nodeLeftHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
n := nom.Node(msg.Data().(nom.NodeLeft))
d := ctx.Dict(nodeDict)
k := string(n.UID())
if _, err := d.Get(k); err != nil {
return fmt.Errorf("%v is not joined", n)
}
d.Del(k)
return nil
}
开发者ID:1995parham,项目名称:FlyNest,代码行数:10,代码来源:nodelink.go
示例20: reservePathID
func reservePathID(ctx bh.RcvContext) uint64 {
d := ctx.Dict(dictID)
var id uint64
if v, err := d.Get("path"); err == nil {
id = v.(uint64)
}
id++
d.Put("path", id)
return id - 1
}
开发者ID:1995parham,项目名称:FlyNest,代码行数:10,代码来源:id.go
注:本文中的github.com/kandoo/beehive.RcvContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论