Пример #1
0
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
0
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)
	}
}
Пример #3
0
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")
	}
}
Пример #4
0
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{})
	}
}
Пример #5
0
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)
	}
}
Пример #6
0
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)
	}
}
Пример #7
0
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)
	}
}
Пример #8
0
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()
	}
}
Пример #9
0
func (state *HelloActor) Receive(context actor.Context) {
	switch msg := context.Message().(type) {
	case Hello:
		fmt.Printf("Hello %v\n", msg.Who)
	}
}
Пример #10
0
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)
	}
}