private void ThreadProcedure()
        {
            _logger.Info("Started dedicated thread " + _name);
            Message pulse = new Message(Codes.Pulse, 0, null, 0);

            while (true)
            {
                bool mustExist = ProcessMessages();
                if (mustExist)
                {
                    break;
                }

                RunMessageHandler(pulse);
            }

            Runtime runtime = (Runtime)_runtime;

            runtime.RemoveThread(_actorId);

            _logger.Info("Finished dedicated thread " + _name);
        }
示例#2
0
        public int StartVoidCall(Func <Task> method, int callerId)
        {
            int  callId   = _data.RegisterCall(callerId);
            Task mainTask = method();

            mainTask.ContinueWith((t) =>
            {
                if (t.IsFaulted)
                {
                    _logger.Error(String.Format("Error. Caller id: {0}, call id: {1}.", callerId, callId), t.Exception);
                    SendResult(callerId, callId, CallResult.Error, t.Exception, 0);
                }
                else if (t.IsCanceled)
                {
                    _logger.Info(String.Format("Cancelled. Caller id: {0}, call id: {1}.", callerId, callId));
                    SendResult(callerId, callId, CallResult.Cancelled, null, 0);
                }
                else
                {
                    SendResult(callerId, callId, CallResult.Completed, null, 0);
                }
            }, TaskContinuationOptions.AttachedToParent);
            return(callId);
        }
 private void RunMessageHandler(Parcel parcel)
 {
     try
     {
         parcel.Actor.OnMessage(parcel.Message.Code, _runtime, parcel.ActorId, parcel.Message);
     }
     catch (Exception ex)
     {
         _logger.Error("Exception in actor OnMessage", ex);
         IActor newActor = _errorHandler.OnError(_runtime, parcel.ActorId, parcel.Actor, ex);
         if (newActor != null)
         {
             _logger.Info(String.Format("Replacing actor {0}, type: {1}", parcel.ActorId, newActor.GetType().Name));
             ReplaceActor(parcel.ActorId, newActor);
         }
     }
 }