示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncTargetWrapper" /> class.
 /// </summary>
 /// <param name="wrappedTarget">The wrapped target.</param>
 /// <param name="queueLimit">Maximum number of requests in the queue.</param>
 /// <param name="overflowAction">The action to be taken when the queue overflows.</param>
 public AsyncTargetWrapper(Target wrappedTarget, int queueLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     this.RequestQueue = new AsyncRequestQueue(10000, AsyncTargetWrapperOverflowAction.Discard);
     this.TimeToSleepBetweenBatches = 50;
     this.BatchSize = 100;
     this.WrappedTarget = wrappedTarget;
     this.QueueLimit = queueLimit;
     this.OverflowAction = overflowAction;
 }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncTargetWrapper" /> class.
        /// </summary>
        /// <param name="wrappedTarget">The wrapped target.</param>
        /// <param name="queueLimit">Maximum number of requests in the queue.</param>
        /// <param name="overflowAction">The action to be taken when the queue overflows.</param>
        public AsyncTargetWrapper(Target wrappedTarget, int queueLimit, AsyncTargetWrapperOverflowAction overflowAction)
        {
#if NETSTANDARD2_0
            // NetStandard20 includes many optimizations for ConcurrentQueue:
            //  - See: https://blogs.msdn.microsoft.com/dotnet/2017/06/07/performance-improvements-in-net-core/
            // Net40 ConcurrencyQueue can seem to leak, because it doesn't clear properly on dequeue
            //  - See: https://blogs.msdn.microsoft.com/pfxteam/2012/05/08/concurrentqueuet-holding-on-to-a-few-dequeued-elements/
            _requestQueue = new ConcurrentRequestQueue(10000, AsyncTargetWrapperOverflowAction.Discard);
#else
            _requestQueue = new AsyncRequestQueue(10000, AsyncTargetWrapperOverflowAction.Discard);
#endif
            TimeToSleepBetweenBatches = 1;
            BatchSize = 200;
            FullBatchSizeWriteLimit = 5;
            WrappedTarget           = wrappedTarget;
            QueueLimit     = queueLimit;
            OverflowAction = overflowAction;
        }
        public void DequeueBatch_WithNonEmptyList_ReturnsValidCount(AsyncTargetWrapperOverflowAction overflowAction)
        {
            // Stage
            ConcurrentRequestQueue requestQueue = new ConcurrentRequestQueue(2, overflowAction);

            requestQueue.Enqueue(new AsyncLogEventInfo());
            requestQueue.Enqueue(new AsyncLogEventInfo());
            Assert.Equal(2, requestQueue.Count);

            // Act
            var batch = new List <AsyncLogEventInfo>();

            requestQueue.DequeueBatch(1, batch);    // Dequeue into empty-list
            Assert.Equal(1, requestQueue.Count);
            requestQueue.DequeueBatch(1, batch);    // Dequeue into non-empty-list

            // Assert
            Assert.Equal(0, requestQueue.Count);
            Assert.Equal(2, batch.Count);
        }
示例#4
0
 /// <summary>
 /// Creates a new instance of <see cref="AsyncRequestQueue"/> and
 /// sets the request limit and overflow action.
 /// </summary>
 /// <param name="requestLimit">Request limit.</param>
 /// <param name="overflowAction">The overflow action.</param>
 public AsyncRequestQueue(int requestLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     _requestLimit = requestLimit;
     _overflowAction = overflowAction;
 }
示例#5
0
 /// <summary>
 /// Creates a new instance of <see cref="AsyncTargetWrapper"/>
 /// which wraps the specified target.
 /// </summary>
 /// <param name="wrappedTarget">The target to be wrapped.</param>
 /// <param name="queueLimit">Maximum number of requests in the queue.</param>
 /// <param name="overflowAction">The action to be taken when the queue overflows.</param>
 public AsyncTargetWrapper(Target wrappedTarget, int queueLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     WrappedTarget = wrappedTarget;
     QueueLimit = queueLimit;
     OverflowAction = overflowAction;
 }
示例#6
0
 /// <summary>
 /// Creates a new instance of <see cref="AsyncRequestQueue"/> and
 /// sets the request limit and overflow action.
 /// </summary>
 /// <param name="requestLimit">Request limit.</param>
 /// <param name="overflowAction">The overflow action.</param>
 public AsyncRequestQueue(int requestLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     _requestLimit   = requestLimit;
     _overflowAction = overflowAction;
 }
示例#7
0
 /// <summary>
 /// Creates a new instance of <see cref="AsyncTargetWrapper"/>
 /// which wraps the specified target.
 /// </summary>
 /// <param name="wrappedTarget">The target to be wrapped.</param>
 /// <param name="queueLimit">Maximum number of requests in the queue.</param>
 /// <param name="overflowAction">The action to be taken when the queue overflows.</param>
 public AsyncTargetWrapper(Target wrappedTarget, int queueLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     WrappedTarget  = wrappedTarget;
     QueueLimit     = queueLimit;
     OverflowAction = overflowAction;
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the AsyncRequestQueue class.
 /// </summary>
 /// <param name="requestLimit">Request limit.</param>
 /// <param name="overflowAction">The overflow action.</param>
 public AsyncRequestQueue(int requestLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     this.RequestLimit = requestLimit;
     this.OnOverflow   = overflowAction;
 }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the AsyncRequestQueue class.
 /// </summary>
 /// <param name="requestLimit">Request limit.</param>
 /// <param name="overflowAction">The overflow action.</param>
 public ConcurrentRequestQueue(int requestLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     RequestLimit = requestLimit;
     OnOverflow   = overflowAction;
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the AsyncRequestQueue class.
 /// </summary>
 /// <param name="configuration">the logging configuration.</param>
 /// <param name="requestLimit">Request limit.</param>
 /// <param name="overflowAction">The overflow action.</param>
 public AsyncRequestQueue(LoggingConfiguration configuration, int requestLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     this.configuration = configuration;
     this.RequestLimit  = requestLimit;
     this.OnOverflow    = overflowAction;
 }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the AsyncRequestQueue class.
 /// </summary>
 /// <param name="requestLimit">Request limit.</param>
 /// <param name="overflowAction">The overflow action.</param>
 public AsyncRequestQueue(int requestLimit, AsyncTargetWrapperOverflowAction overflowAction)
 {
     this.RequestLimit = requestLimit;
     this.OnOverflow = overflowAction;
 }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncTargetWrapper" /> class.
 /// </summary>
 /// <param name="wrappedTarget">The wrapped target.</param>
 /// <param name="queueLimit">Maximum number of requests in the queue.</param>
 /// <param name="overflowAction">The action to be taken when the queue overflows.</param>
 public AsyncTargetWrapper(Target wrappedTarget, int queueLimit, AsyncTargetWrapperOverflowAction overflowAction)
     : this(wrappedTarget, queueLimit, overflowAction, null)
 {
 }