private async void ProcessStandardMessage (Envelope envelope, Actor actor) { Debug.Assert (envelope != null); Debug.Assert (actor != null); // We're processing an standard message. try { actor.ExecutionContext = new ExecutionContext { EnvelopeProcessor = this, Message = envelope.Message, Sender = envelope.Sender, TaskCompletionSource = envelope.TaskCompletionSource }; actor.Self.State = ActorStates.Processing; await actor.ProcessMessage (); // Sanity checks. // When we finish processing a message there should be no pending replies. if (actor.Self.PendingReplies != 0) { throw new Exception ($"Actor {actor} has {actor.Self.PendingReplies} pending replies after finishing processing message [{envelope.Message}]"); } if (actor.ExecutionContext.TaskCompletionSource != null) { throw new Exception($"Actor {actor.Self} has not replied to {actor.ExecutionContext.Sender} after processing message [{envelope.Message}]"); } } finally { // Make sure that we clear the execution context and move back the actor to its mailbox queue. actor.ExecutionContext = null; actor.Self.State = ActorStates.Idle; ActorSystem.EnqueueActorBackToMailbox (envelope.Target.Mailbox, actor); } }
public void EnqueueActor(Actor actor) { Actors.Enqueue (actor); }