Beispiel #1
0
        public Task <TCommandResult> Send <TCommandResult>(string targetId, ICommand message, TimeSpan timeout) where TCommandResult : ICommandResult
        {
            var targetProcess = _registry.Get(targetId);

            EnsureCanSend(targetProcess);

            var taskSource = new TaskCompletionSource <ICommandResult>();

            message.CommandId = Guid.NewGuid();

            _pendingCommands.Add(message.CommandId, taskSource);

            targetProcess.Post(message, _actorProcess);

            var cancel = new CancellationTokenSource(timeout);

            cancel.Token.Register(() => taskSource.TrySetCanceled(), false);

            return(taskSource.Task.ContinueWith(task =>
            {
                if (task.IsCompletedSuccessfully)
                {
                    return (TCommandResult)task.Result;
                }
                if (task.IsCanceled)
                {
                    throw new Exception("timeout");
                }

                throw task.Exception;
            }, cancel.Token));
        }
Beispiel #2
0
        private (IEvent message, ICanPost sender) Deserialize(MessageEnvelope envelope)
        {
            var message = _serializer.Deserialize(envelope.MessageData.ToByteArray(), Type.GetType(envelope.MessageType)) as IEvent;
            var sender  = envelope.Sender == null ? null : _registry.Get(envelope.Sender.Address);

            return(message, sender);
        }
Beispiel #3
0
        public void Emit(string target, IMessage message)
        {
            var process = _registry.Get(target);

            process.Post(message, _process);
        }
        public void Emit(string targetId, IEvent message)
        {
            var process = _registry.Get(targetId);

            process.Post(message, null);
        }
 public LocalReader(ActorId actorId, IActorRegistry registry, IActorProcess sender)
 {
     _target = registry.Get(actorId.Value);
     _sender = sender;
 }