Пример #1
0
        /// <summary>
        /// Send a message towards the command handler
        /// </summary>
        /// <param name="message">Message to forward</param>
        public void SendDownstream(IDownstreamMessage message)
        {
            Message = message;
            _downEvent.Set();

            if (_down != null)
                _down(message);
        }
Пример #2
0
 /// <summary>
 /// Sends the downstream.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <exception cref="System.InvalidOperationException">Failed to find a next handler.</exception>
 public void SendDownstream(IDownstreamMessage message)
 {
     if (_next == null)
     {
         throw new InvalidOperationException("Failed to find a next handler.");
     }
     _next.Invoke(message);
 }
Пример #3
0
        /// <summary>
        /// Send something down the pipeline (usually the invoke command message)
        /// </summary>
        /// <param name="message">Message to send</param>
        /// <exception cref="System.ArgumentNullException">message</exception>
        public void Send(IDownstreamMessage message)
        {
            if (message == null) throw new ArgumentNullException("message");

            if (!_fixed)
                throw new InvalidOperationException("Start() must be called first.");
            _downstream[0].Invoke(message);
        }
Пример #4
0
 /// <summary>
 /// Send a message towards the command handler
 /// </summary>
 /// <param name="message">Message to forward</param>
 public void SendDownstream(IDownstreamMessage message)
 {
     Message = message;
     _event.Set();
     if (_down != null)
     {
         _down(message);
     }
 }
Пример #5
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        void IDownstreamHandler.HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            if (message is DispatchCommand)
                _upstream[0].Invoke(new CommandCompleted((DispatchCommand) message));
            else if (message is DispatchEvent)
                _upstream[0].Invoke(new EventCompleted((DispatchEvent) message));

            // just ignore everything else.
        }
Пример #6
0
 /// <summary>
 /// Invokes the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Invoke(IDownstreamMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     _mine.HandleDownstream(this, message);
     InvokeUpstream();
     InvokeDownstream();
 }
Пример #7
0
        /// <summary>
        /// Send something down the pipeline (usually the invoke command message)
        /// </summary>
        /// <param name="message">Message to send</param>
        /// <exception cref="System.ArgumentNullException">message</exception>
        public void Send(IDownstreamMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (!_fixed)
            {
                throw new InvalidOperationException("Start() must be called first.");
            }
            _downstream[0].Invoke(message);
        }
Пример #8
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        void IDownstreamHandler.HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            if (message is DispatchCommand)
            {
                _upstream[0].Invoke(new CommandCompleted((DispatchCommand)message));
            }
            else if (message is DispatchEvent)
            {
                _upstream[0].Invoke(new EventCompleted((DispatchEvent)message));
            }

            // just ignore everything else.
        }
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var msg = message as DispatchEvent;
            if (msg != null)
            {
                var batchId = _threadBatchIdMapper.GetBatchId();
                if (batchId != Guid.Empty)
                {
                    _storage.Hold(batchId, msg.DomainEvent);
                    return;
                }
            }


            context.SendDownstream(message);
        }
Пример #10
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var msg = message as DispatchEvent;

            if (msg != null)
            {
                var batchId = _threadBatchIdMapper.GetBatchId();
                if (batchId != Guid.Empty)
                {
                    _storage.Hold(batchId, msg.DomainEvent);
                    return;
                }
            }


            context.SendDownstream(message);
        }
Пример #11
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchEvent"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;
            var msg = message as DispatchEvent;
            if (msg != null)
            {
                _queue.Enqueue(msg);

                // Not very much thread safe.
                if (Interlocked.Read(ref _currentWorkers) < _maxWorkers)
                {
                    Interlocked.Increment(ref _currentWorkers);
                    ThreadPool.QueueUserWorkItem(DispatchEventsNow);
                }
            }
            else if (message is Shutdown)
            {
                Close();
            }
        }
Пример #12
0
        /// <summary>
        /// Send a message to the domainEvent handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public virtual void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var dispatchMsg = message as DispatchEvent;

            if (dispatchMsg != null)
            {
                try
                {
                    _method.MakeGenericMethod(dispatchMsg.DomainEvent.GetType()).Invoke(this,
                                                                                        new object[]
                                                                                        { dispatchMsg.DomainEvent });

                    return;
                }
                catch (Exception err)
                {
                    context.SendUpstream(new EventFailed(dispatchMsg, err));
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchEvent"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;
            var msg = message as DispatchEvent;

            if (msg != null)
            {
                _queue.Enqueue(msg);

                // Not very much thread safe.
                if (Interlocked.Read(ref _currentWorkers) < _maxWorkers)
                {
                    Interlocked.Increment(ref _currentWorkers);
                    ThreadPool.QueueUserWorkItem(DispatchEventsNow);
                }
            }
            else if (message is Shutdown)
            {
                Close();
            }
        }
Пример #14
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var msg = message as DispatchCommand;
            if (msg != null)
            {
                _storage.Add(msg);
            }
            if (message is StartHandlers)
            {
                context.SendDownstream(message);

                var commands = _storage.FindFailedCommands(DateTime.Now.AddSeconds(-5));
                foreach (var command in commands)
                {
                    context.SendDownstream(command);
                }

                return;
            }
            context.SendDownstream(message);
        }
Пример #15
0
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var sendCmd = message as DispatchCommand;
            if (sendCmd != null)
            {
                EnqueueCommand(sendCmd);
                return;
            }
            if (message is Shutdown)
            {
                Close();
            }
            if (message is StartHandlers)
            {
                StartWorker();
            }

            context.SendDownstream(message);
        }
Пример #16
0
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _context = context;

            var sendCmd = message as DispatchCommand;

            if (sendCmd != null)
            {
                EnqueueCommand(sendCmd);
                return;
            }
            if (message is Shutdown)
            {
                Close();
            }
            if (message is StartHandlers)
            {
                StartWorker();
            }

            context.SendDownstream(message);
        }
Пример #17
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var msg = message as DispatchCommand;

            if (msg != null)
            {
                _storage.Add(msg);
            }
            if (message is StartHandlers)
            {
                context.SendDownstream(message);

                var commands = _storage.FindFailedCommands(DateTime.Now.AddSeconds(-5));
                foreach (var command in commands)
                {
                    context.SendDownstream(command);
                }

                return;
            }
            context.SendDownstream(message);
        }
Пример #18
0
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            var msg = message as DispatchCommand;

            if (msg != null)
            {
                try
                {
                    _method.MakeGenericMethod(msg.Command.GetType()).Invoke(this, new object[] { msg.Command });
                    context.SendUpstream(new CommandCompleted(msg));
                }
                catch (Exception err)
                {
                    msg.AddFailedAttempt();
                    context.SendUpstream(new CommandFailed(msg, err));
                    return;
                }

                return;
            }

            context.SendDownstream(message);
        }
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _event.Set();

            _handler(context, message);
        }
Пример #20
0
 /// <summary>
 /// Try to send something down to the command handler again (or to a downstream handler on the way)
 /// </summary>
 /// <param name="message">Message to send</param>
 public void SendDownstream(IDownstreamMessage message)
 {
     _downMessages.Enqueue(message);
 }
        /// <summary>
        /// Send a message to the command handler
        /// </summary>
        /// <param name="context">my context</param>
        /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
        public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
        {
            _event.Set();

            _handler(context, message);
        }
 /// <summary>
 /// Send a message to the command handler
 /// </summary>
 /// <param name="context">my context</param>
 /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
 public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
 {
     Invoked = true;
     context.SendDownstream(message);
 }
 /// <summary>
 /// Send a message to the command handler
 /// </summary>
 /// <param name="context">my context</param>
 /// <param name="message">Message to send, typically <see cref="DispatchCommand"/>.</param>
 public void HandleDownstream(IDownstreamContext context, IDownstreamMessage message)
 {
     Invoked = true;
     context.SendDownstream(message);
 }
Пример #24
0
 /// <summary>
 /// Try to send something down to the command handler again (or to a downstream handler on the way)
 /// </summary>
 /// <param name="message">Message to send</param>
 public void SendDownstream(IDownstreamMessage message)
 {
     _downMessages.Enqueue(message);
 }
 /// <summary>
 /// Invokes the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Invoke(IDownstreamMessage message)
 {
     if (message == null) throw new ArgumentNullException("message");
     _mine.HandleDownstream(this, message);
     InvokeUpstream();
     InvokeDownstream();
 }
 /// <summary>
 /// Sends the downstream.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <exception cref="System.InvalidOperationException">Failed to find a next handler.</exception>
 public void SendDownstream(IDownstreamMessage message)
 {
     if (_next == null)
         throw new InvalidOperationException("Failed to find a next handler.");
     _next.Invoke(message);
 }