private void Active() { ReactingToStatusMessages(); Receive <RequestCreateAgent>(msg => { _logger.Debug($"Spawning new agent"); var props = _playerAgentActorFactory.Build(_script); var agent = Context.ActorOf(props); var message = new GeneratedAgent(agent, _script.Id); Sender.Tell(message); }); Receive <AgentFailureState>(msg => { UpdateFailure(msg); DisconnectFromLobby(); UpdateState(CompetitorState.Faulted); Become(Faulted); throw new CompetitorFaultedException( Self , "agent failure" , _failureStateInfo.Exception , _script.Id); }); Receive <CompetitorScriptUpdated>(msg => { _script = msg.NewScript; _methodCallsFailureCounter.Reset(); UpdateFailure(AgentFailureState.Ok()); UpdateState(CompetitorState.Inconclusive); }); Receive <CompetitorResult>(msg => { UpdateState(CompetitorState.Active); var result = new Data.Entities.Messages.ScriptCompetitionResult(_script.Id, msg); _resultRepository.Tell(result); Sender.Tell(PoisonPill.Instance); }); ReceiveAny(msg => throw new InvalidOperationException($"Unknown message type received. Received object: {msg}")); }
private void Faulted() { ReactingToStatusMessages(); Receive <CompetitorScriptUpdated>(msg => { _script = msg.NewScript; _methodCallsFailureCounter.Reset(); UpdateFailure(AgentFailureState.Ok()); UpdateState(CompetitorState.Inconclusive); ConnectToLobby(); Become(Active); }); Receive <RequestCreateAgent>(msg => { var ex = new CompetitorFaultedException( Self , "Unable to create agent- competitor is faulted critically" , _failureStateInfo.Exception , _script.Id); Sender.Tell(ex); }); Receive <CompetitorResult>(msg => { //just in case Sender.Tell(PoisonPill.Instance); }); ReceiveAny(msg => throw new InvalidOperationException($"Unknown message type received. Received object: {msg}")); }