Exemplo n.º 1
0
 /// <summary>
 /// Adds error handling to IObserver.OnError
 /// </summary>
 /// <param name="self"></param>
 /// <param name="exception"></param>
 /// <param name="message"></param>
 /// <param name="logger"></param>
 /// <returns></returns>
 public static Unit SendError(this IBrokerObserver self, Exception exception, Maybe <BrokerMessage> message, Maybe <Log> logger) =>
 Try(() => self.OnError(exception, message))
 .Match(_ => _,
        e => logger.Error <Unit>(
            new AggregateException(
                exception,
                logger.Debug(e, $"{nameof(self.OnNext)} failed. Calling {nameof(self.OnError)}")).GetExceptionChainMessagesWithSql()));
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the RequestQueueAdapter class
 /// </summary>
 /// <param name="observer">indicating the broker observer</param>
 /// <param name="factory">indicating the broker queue factory</param>
 public ResponseQueueAdapter(IBrokerObserver observer, IBrokerQueueFactory factory, int serviceRequestPrefetchCount)
 {
     this.observer                    = observer;
     this.queueFactory                = factory;
     this.replyResponseCallback       = new ThreadHelper <IAsyncResult>(new AsyncCallback(this.ReplyResponse)).CallbackRoot;
     this.serviceRequestPrefetchCount = serviceRequestPrefetchCount;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the RequestQueueAdapter class
        /// </summary>
        /// <param name="observer">indicating the broker observer</param>
        /// <param name="factory">indicating the broker queue factory</param>
        public RequestQueueAdapter(IBrokerObserver observer, IBrokerQueueFactory factory)
        {
            Contract.Requires(observer != null);
            Contract.Requires(factory != null);

            this.observer     = observer;
            this.queueFactory = factory;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a new observer to receive future queue messages
        /// </summary>
        /// <remarks>Be aware that <see cref="IObserver{T}.OnNext(T)"/>, <see cref="IObserver{T}.OnError(Exception)"/>,
        /// and <see cref="IObserver{T}.OnCompleted()"/> are called asynchronously;
        /// so appropriate state sharing precautions should be taken to avoid race conditions.</remarks>
        /// <param name="observer">New addition that needs to implement <see cref="IBrokerObserver"/></param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.InvalidOperationException">When <paramref name="observer"/> is not an <see cref="IBrokerObserver"/></exception>
        /// <returns>A subscription that can be unsubscribed from by calling Dispose</returns>
        public IDisposable Subscribe(IBrokerObserver observer)
        {
            if (!_observers.Contains(observer.AssertValue()))
            {
                _observers.Add(observer);

                _logger.Debug($"Added {observer}");
            }

            return(new Subscription(_observers, observer, _logger));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Adds error handling to IObserver.OnNext
 /// </summary>
 /// <param name="self"></param>
 /// <param name="next"></param>
 /// <param name="logger"></param>
 /// <returns></returns>
 public static Unit SendNext(this IBrokerObserver self, BrokerMessage next, Maybe <Log> logger) =>
 Try(() => self.OnNext(next)).Match(
     _ => _,
     e => self.SendError(logger.Debug(e, $"{nameof(self.OnNext)} failed. Calling {nameof(self.OnError)}"), next, logger));
Exemplo n.º 6
0
 internal Subscription(IProducerConsumerCollection <IBrokerObserver> observers, IBrokerObserver observer, Maybe <Log> logger)
 {
     _observers = observers.AssertValue();
     _observer  = observer.AssertValue();
     _logger    = logger;
 }