本文整理汇总了Golang中github.com/rogeralsing/gam/actor.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Receive
func (state *BecomeActor) Receive(context actor.Context) {
switch msg := context.Message().(type) {
case Hello:
fmt.Printf("Hello %v\n", msg.Who)
context.Become(state.Other)
}
}
示例2: sendEnvelopes
func (state *endpointWriter) sendEnvelopes(msg []interface{}, ctx actor.Context) {
envelopes := make([]*messages.MessageEnvelope, len(msg))
for i, tmp := range msg {
envelopes[i] = tmp.(*messages.MessageEnvelope)
}
batch := &messages.MessageBatch{
Envelopes: envelopes,
}
err := state.stream.Send(batch)
if err != nil {
ctx.Stash()
log.Println("Failed to send to host", state.host)
panic("restart")
}
}
示例3: Receive
func (*remoteActor) Receive(context actor.Context) {
switch msg := context.Message().(type) {
case *messages.StartRemote:
log.Println("Starting")
msg.Sender.Tell(&messages.Start{})
case *messages.Ping:
msg.Sender.Tell(&messages.Pong{})
}
}
示例4: Receive
func (state *endpointWriter) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
case actor.Started:
state.initialize()
case actor.Stopped:
state.conn.Close()
case actor.Restarting:
state.conn.Close()
case []interface{}:
state.sendEnvelopes(msg, ctx)
default:
log.Fatal("Unknown message", msg)
}
}
示例5: Receive
func (state *endpointManager) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
case actor.Started:
state.connections = make(map[string]*actor.PID)
log.Println("Started EndpointManager")
case *messages.MessageEnvelope:
pid, ok := state.connections[msg.Target.Host]
if !ok {
props := actor.
FromProducer(newEndpointWriter(msg.Target.Host, state.config)).
WithMailbox(newEndpointWriterMailbox(state.config.batchSize, 1000000))
pid = actor.Spawn(props)
state.connections[msg.Target.Host] = pid
}
pid.Tell(msg)
}
}
示例6: Other
func (state *BecomeActor) Other(context actor.Context) {
switch msg := context.Message().(type) {
case Hello:
fmt.Printf("%v, ey we are now handling messages in another behavior", msg.Who)
}
}