Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case ActorPidRequest msg:
                var props = _remoteConfig.GetRemoteKind(msg.Kind);
                var name  = msg.Name;
                if (string.IsNullOrEmpty(name))
                {
                    name = _system.ProcessRegistry.NextId();
                }

                try
                {
                    var pid = _system.Root.SpawnNamed(props, name);
                    context.System.Metrics.Get <RemoteMetrics>().RemoteActorSpawnCount.Inc(new[] { _system.Id, _system.Address, msg.Kind });
                    var response = new ActorPidResponse {
                        Pid = pid
                    };
                    context.Respond(response);
                }
                catch (ProcessNameExistException ex)
                {
                    var response = new ActorPidResponse
                    {
                        Pid        = ex.Pid,
                        StatusCode = (int)ResponseStatusCode.ProcessNameAlreadyExist
                    };
                    context.Respond(response);
                }
                catch
                {
                    var response = new ActorPidResponse
                    {
                        StatusCode = (int)ResponseStatusCode.Error
                    };
                    context.Respond(response);

                    throw;
                }

                break;
            }

            return(Task.CompletedTask);
        }