Exemplo n.º 1
0
 public T Dequeue(CancellationContext cancellationContext)
 {
     if (cancellationContext == null)
     {
         this.consumerSemaphore.WaitOne();
     }
     else if (WaitHandle.WaitAny(new WaitHandle[]
     {
         cancellationContext.StopToken.WaitHandle,
         this.consumerSemaphore
     }) != 1)
     {
         ServiceLogger.LogDebug(ServiceLogger.Component.LogReader, LogUploaderEventLogConstants.Message.LogBatchEnqueue, string.Format("Enqueue: called : Type={0}, thread={1}, queueSize={2}, capacity={3} ?---InDequeueEmptySkip ", new object[]
         {
             typeof(T),
             Thread.CurrentThread.ManagedThreadId,
             this.queue.Count,
             this.Capacity
         }), "", "");
         return(default(T));
     }
     return(this.Dequeue());
 }
Exemplo n.º 2
0
 public InputBuffer(int batchSizeInBytes, long beginOffset, ILogFileInfo logFileInfoObj, ThreadSafeQueue <T> logDataBatchQueue, string prefix, ILogMonitorHelper <T> logMonitorHelper, int messageBatchFlushInterval, CancellationContext cancelContext, int maxBatchCount, string instanceName = null)
 {
     if (batchSizeInBytes <= 0)
     {
         throw new ArgumentOutOfRangeException("batchSizeInByte", "The batch size should be greater than 0.");
     }
     if (beginOffset < 0L)
     {
         throw new ArgumentOutOfRangeException("beginOffset", "The beginOffset should be equal or greater than 0.");
     }
     if (logDataBatchQueue == null)
     {
         throw new ArgumentNullException("logDataBatchQueue cannot be null.");
     }
     if (messageBatchFlushInterval < 0)
     {
         throw new ArgumentOutOfRangeException("messageBatchFlushInterval", "The messageBatchFlushInterval must not be a negative number.");
     }
     ArgumentValidator.ThrowIfNull("logFileInfoObj", logFileInfoObj);
     ArgumentValidator.ThrowIfNull("watermarkFileRef", logFileInfoObj.WatermarkFileObj);
     if (string.IsNullOrEmpty(logFileInfoObj.FullFileName))
     {
         throw new ArgumentException("fullLogName cannot be null or emtpy.");
     }
     ArgumentValidator.ThrowIfNull("cancelContext", cancelContext);
     this.cancellationContext       = cancelContext;
     this.messageBatchFlushInterval = messageBatchFlushInterval;
     this.batchSizeInBytes          = batchSizeInBytes;
     this.logDataBatchQueue         = logDataBatchQueue;
     this.watermarkFileRef          = logFileInfoObj.WatermarkFileObj;
     this.maximumBatchCount         = ((maxBatchCount <= 0) ? int.MaxValue : maxBatchCount);
     this.lastFluchCheckTime        = DateTime.UtcNow;
     this.logMonitorHelper          = logMonitorHelper;
     this.fullLogName         = logFileInfoObj.FullFileName;
     this.instance            = (string.IsNullOrEmpty(instanceName) ? prefix : instanceName);
     this.logPrefix           = prefix;
     this.perfCounterInstance = PerfCountersInstanceCache.GetInstance(this.instance);
     this.shouldBufferBatches = this.ShouldBufferBatches();
     this.CreateNewBatch(beginOffset);
     if (this.shouldBufferBatches)
     {
         MessageBatchBase messageBatchBase = this.activeBatch as MessageBatchBase;
         if (messageBatchBase != null)
         {
             messageBatchBase.MessageBatchFlushInterval = this.messageBatchFlushInterval;
         }
     }
 }