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) } }
func (state *ParentActor) Receive(context actor.Context) { switch msg := context.Message().(type) { case Hello: props := actor.FromProducer(NewChildActor) child := context.Spawn(props) child.Tell(msg) } }
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{}) } }
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) } }
func (state *HelloActor) Receive(context actor.Context) { switch msg := context.Message().(type) { case actor.Started: fmt.Println("Started, initialize actor here") case actor.Stopping: fmt.Println("Stopping, actor is about shut down") case actor.Stopped: fmt.Println("Stopped, actor and it's children are stopped") case actor.Restarting: fmt.Println("Restarting, actor is about restart") case Hello: fmt.Printf("Hello %v\n", msg.Who) } }
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) } }
func (state *localActor) Receive(context actor.Context) { switch context.Message().(type) { case actor.Started: state.wgStart.Add(1) state.wgStop.Add(1) case *messages.Pong: state.count++ if state.count%50000 == 0 { log.Println(state.count) } if state.count == state.messageCount { state.wgStop.Done() } case *messages.Start: state.wgStart.Done() } }
func (state *HelloActor) Receive(context actor.Context) { switch msg := context.Message().(type) { case Hello: fmt.Printf("Hello %v\n", msg.Who) } }
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) } }