示例#1
0
        public Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case ActorPidRequest msg:
                var props = Remote.GetKnownKind(msg.Kind);
                var name  = msg.Name;
                if (string.IsNullOrEmpty(name))
                {
                    name = ProcessRegistry.Instance.NextId();
                }
                var pid      = Actor.SpawnNamed(props, name);
                var response = new ActorPidResponse
                {
                    Pid = pid
                };
                context.Respond(response);

                break;

            default:
                break;
            }
            return(Actor.Done);
        }
示例#2
0
        public Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case ActorPidRequest msg:
                var props = Remote.GetKnownKind(msg.Kind);
                var name  = msg.Name;
                if (string.IsNullOrEmpty(name))
                {
                    name = ProcessRegistry.Instance.NextId();
                }

                try
                {
                    var pid      = Actor.SpawnNamed(props, name);
                    var response = new ActorPidResponse {
                        Pid = pid
                    };
                    context.Respond(response);
                }
                catch (ActivatorException ex)
                {
                    var response = new ActorPidResponse
                    {
                        StatusCode = ex.Code
                    };
                    context.Respond(response);

                    if (!ex.DoNotThrow)
                    {
                        throw;
                    }
                }
                catch (ProcessNameExistException ex)
                {
                    var response = new ActorPidResponse
                    {
                        Pid        = ex.Pid,
                        StatusCode = (int)ResponseStatusCode.ProcessNameAlreadyExist
                    };
                    context.Respond(response);

                    throw;
                }
                catch
                {
                    var response = new ActorPidResponse
                    {
                        StatusCode = (int)ResponseStatusCode.Error
                    };
                    context.Respond(response);

                    throw;
                }
                break;
            }
            return(Actor.Done);
        }