Пример #1
0
 public Bus(
     IModelFactory modelFactory,
     IConsumerFactory consumerFactory,
     IRequesterFactory requesterFactory,
     IPublisherFactory publisherFactory,
     ISubscriptionFactory subscriptionFactory)
 {
     this.modelFactory        = modelFactory;
     this.publisherFactory    = publisherFactory;
     this.requesterFactory    = requesterFactory;
     this.subscriptionFactory = subscriptionFactory;
     this.consumerFactory     = consumerFactory;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BackgroundRequesterFactory"/> class.
 /// </summary>
 /// <remarks>
 /// Upon instatiation, this class will spawn a Task that will asynchronously send any queued up request to Sentry.
 /// When the queue is empty, the task will sleep asynchronously.
 /// When cancellation is requested, the worker will continue to run until <param name="shutudownTimeout"></param> is reached or the queue is empty.
 /// </remarks>
 /// <param name="actualRequesterFactory">The decorated request factory</param>
 /// <param name="emptyQueueDelay">If the queue is empty, time to asynchonously wait until checking for requests again. Defaults to 1 second</param>
 /// <param name="shutudownTimeout">Time to keep sending events after (blocking Dispose). Defaults to 2 seconds.</param>
 public BackgroundRequesterFactory(
     IRequesterFactory actualRequesterFactory,
     TimeSpan?emptyQueueDelay  = null,
     TimeSpan?shutudownTimeout = null,
     int boundedCapacity       = 40)
     : this(
         actualRequesterFactory,
         new ConcurrentQueue <IRequester>(),
         new CancellationTokenSource(),
         emptyQueueDelay ?? TimeSpan.FromSeconds(1),
         shutudownTimeout ?? TimeSpan.FromSeconds(2),
         boundedCapacity)
 {
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RavenClient" /> class.
        /// </summary>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        /// <param name="jsonPacketFactory">The optional factory that will be used to create the <see cref="JsonPacket" /> that will be sent to Sentry.</param>
        /// <param name="sentryRequestFactory">The optional factory that will be used to create the <see cref="SentryRequest"/> that will be sent to Sentry.</param>
        /// <param name="sentryUserFactory">The optional factory that will be used to create the <see cref="SentryUser"/> that will be sent to Sentry.</param>
        /// <param name="requesterFactory">The optional factory that will be used to create the <see cref="IRequester"/> that will make the request to Sentry.</param>
        /// <exception cref="System.ArgumentNullException">dsn</exception>
        public RavenClient(Dsn dsn,
                           IJsonPacketFactory jsonPacketFactory       = null,
                           ISentryRequestFactory sentryRequestFactory = null,
                           ISentryUserFactory sentryUserFactory       = null,
                           IRequesterFactory requesterFactory         = null)
        {
            if (dsn == null)
            {
                throw new ArgumentNullException("dsn");
            }

            this.currentDsn           = dsn;
            this.jsonPacketFactory    = jsonPacketFactory ?? new JsonPacketFactory();
            this.sentryRequestFactory = sentryRequestFactory ?? new SentryRequestFactory();
            this.sentryUserFactory    = sentryUserFactory ?? new SentryUserFactory();
            this.requesterFactory     = requesterFactory ?? new HttpRequesterFactory();

            Logger           = "root";
            Timeout          = TimeSpan.FromSeconds(5);
            this.defaultTags = new Dictionary <string, string>();
            this.breadcrumbs = new CircularBuffer <Breadcrumb>();
        }
        internal BackgroundRequesterFactory(
            IRequesterFactory actualRequesterFactory,
            IProducerConsumerCollection <IRequester> queue,
            CancellationTokenSource cancellationTokenSource,
            TimeSpan emptyQueueDelay,
            TimeSpan shutudownTimeout,
            int boundedCapacity)
        {
            if (boundedCapacity <= 0)
            {
                throw new ArgumentOutOfRangeException("At least 1 item must be allowed in the queue.");
            }
            this.actualRequesterFactory = actualRequesterFactory ?? throw new ArgumentNullException(nameof(actualRequesterFactory));
            this.queue = new BlockingCollection <IRequester>(queue, boundedCapacity) ?? throw new ArgumentNullException(nameof(queue));
            this.cancellationTokenSource = cancellationTokenSource ?? throw new ArgumentNullException(nameof(cancellationTokenSource));

            this.QueueConsumer = Task.Run(
                async() => await Worker(
                    this.queue,
                    this.cancellationTokenSource.Token,
                    emptyQueueDelay,
                    shutudownTimeout));
        }