예제 #1
0
        public override async Task Receive(IAsyncStreamReader <MessageBatch> requestStream,
                                           IServerStreamWriter <Unit> responseStream, ServerCallContext context)
        {
            await requestStream.ForEachAsync(batch =>
            {
                var targetNames = new List <string>(batch.TargetNames);
                var typeNames   = new List <string>(batch.TypeNames);
                foreach (var envelope in batch.Envelopes)
                {
                    var targetName = targetNames[envelope.Target];
                    var target     = new PID(ProcessRegistry.Instance.Address, targetName);
                    var sender     = envelope.Sender;
                    var typeName   = typeNames[envelope.TypeId];
                    var message    = Serialization.Deserialize(typeName, envelope.MessageData);

                    if (message is Terminated msg)
                    {
                        var rt = new RemoteTerminate(target, msg.Who);
                        RemotingSystem.EndpointManagerPid.Tell(rt);
                    }
                    if (message is SystemMessage sys)
                    {
                        target.SendSystemMessage(sys);
                    }
                    else
                    {
                        target.Request(message, sender);
                    }
                }

                return(Actor.Done);
            });
        }
예제 #2
0
        public override async Task Receive(IAsyncStreamReader <MessageBatch> requestStream,
                                           IServerStreamWriter <Unit> responseStream, ServerCallContext context)
        {
            var targets = new PID[100];
            await requestStream.ForEachAsync(batch =>
            {
                if (_suspended)
                {
                    return(Actor.Done);
                }

                //only grow pid lookup if needed
                if (batch.TargetNames.Count > targets.Length)
                {
                    targets = new PID[batch.TargetNames.Count];
                }

                for (int i = 0; i < batch.TargetNames.Count; i++)
                {
                    targets[i] = new PID(ProcessRegistry.Instance.Address, batch.TargetNames[i]);
                }
                var typeNames = batch.TypeNames.ToArray();
                foreach (var envelope in batch.Envelopes)
                {
                    var target   = targets[envelope.Target];
                    var typeName = typeNames[envelope.TypeId];
                    var message  = Serialization.Deserialize(typeName, envelope.MessageData, envelope.SerializerId);

                    if (message is Terminated msg)
                    {
                        var rt = new RemoteTerminate(target, msg.Who);
                        EndpointManager.RemoteTerminate(rt);
                    }
                    else if (message is SystemMessage sys)
                    {
                        target.SendSystemMessage(sys);
                    }
                    else
                    {
                        Proto.MessageHeader header = null;
                        if (envelope.MessageHeader != null)
                        {
                            header = new Proto.MessageHeader();
                            foreach (var(k, v) in envelope.MessageHeader.HeaderData)
                            {
                                header.Add(k, v);
                            }
                        }
                        var localEnvelope = new Proto.MessageEnvelope(message, envelope.Sender, header);
                        target.Tell(localEnvelope);
                    }
                }

                return(Actor.Done);
            });
        }
예제 #3
0
        private void Terminated(Terminated msg, PID target)
        {
            // Logger.LogDebug(
            //     "[EndpointReader] Forwarding remote endpoint termination request for {Who}", msg.Who
            // );

            var rt       = new RemoteTerminate(target, msg.Who);
            var endpoint = _endpointManager.GetEndpoint(rt.Watchee.Address);

            if (endpoint is null)
            {
                return;
            }

            _system.Root.Send(endpoint, rt);
        }
예제 #4
0
        public static void RemoteTerminate(RemoteTerminate msg)
        {
            var endpoint = EnsureConnected(msg.Watchee.Address);

            endpoint.Watcher.Tell(msg);
        }
예제 #5
0
        public static void RemoteTerminate(RemoteTerminate msg)
        {
            var endpoint = EnsureConnected(msg.Watchee.Address);

            RootContext.Empty.Send(endpoint.Watcher, msg);
        }