public BatchAsyncBatcher(
            int maxBatchOperationCount,
            int maxBatchByteSize,
            CosmosSerializerCore serializerCore,
            BatchAsyncBatcherExecuteDelegate executor,
            BatchAsyncBatcherRetryDelegate retrier,
            CosmosClientContext clientContext)
        {
            if (maxBatchOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchOperationCount));
            }

            if (maxBatchByteSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
            }

            this.batchOperations        = new List <ItemBatchOperation>(maxBatchOperationCount);
            this.executor               = executor ?? throw new ArgumentNullException(nameof(executor));
            this.retrier                = retrier ?? throw new ArgumentNullException(nameof(retrier));
            this.maxBatchByteSize       = maxBatchByteSize;
            this.maxBatchOperationCount = maxBatchOperationCount;
            this.serializerCore         = serializerCore ?? throw new ArgumentNullException(nameof(serializerCore));
            this.clientContext          = clientContext;
        }
 public BatchAsyncBatcherThatOverflows(
     int maxBatchOperationCount,
     int maxBatchByteSize,
     CosmosSerializerCore serializerCore,
     BatchAsyncBatcherExecuteDelegate executor,
     BatchAsyncBatcherRetryDelegate retrier) : base(maxBatchOperationCount, maxBatchByteSize, serializerCore, executor, retrier, BatchAsyncBatcherTests.MockClientContext())
 {
 }
 public BatchAsyncBatcherThatOverflows(
     int maxBatchOperationCount,
     int maxBatchByteSize,
     CosmosSerializer cosmosSerializer,
     BatchAsyncBatcherExecuteDelegate executor,
     BatchAsyncBatcherRetryDelegate retrier) : base(maxBatchOperationCount, maxBatchByteSize, cosmosSerializer, executor, retrier)
 {
 }
        public BatchAsyncStreamer(
            int maxBatchOperationCount,
            int maxBatchByteSize,
            int dispatchTimerInSeconds,
            TimerPool timerPool,
            CosmosSerializer cosmosSerializer,
            BatchAsyncBatcherExecuteDelegate executor,
            BatchAsyncBatcherRetryDelegate retrier)
        {
            if (maxBatchOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchOperationCount));
            }

            if (maxBatchByteSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
            }

            if (dispatchTimerInSeconds < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(dispatchTimerInSeconds));
            }

            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            if (retrier == null)
            {
                throw new ArgumentNullException(nameof(retrier));
            }

            if (cosmosSerializer == null)
            {
                throw new ArgumentNullException(nameof(cosmosSerializer));
            }

            this.maxBatchOperationCount = maxBatchOperationCount;
            this.maxBatchByteSize       = maxBatchByteSize;
            this.executor = executor;
            this.retrier  = retrier;
            this.dispatchTimerInSeconds = dispatchTimerInSeconds;
            this.timerPool        = timerPool;
            this.cosmosSerializer = cosmosSerializer;
            this.currentBatcher   = this.CreateBatchAsyncBatcher();

            this.ResetTimer();
        }
        public BatchAsyncBatcher(
            int maxBatchOperationCount,
            int maxBatchByteSize,
            CosmosSerializer cosmosSerializer,
            BatchAsyncBatcherExecuteDelegate executor,
            BatchAsyncBatcherRetryDelegate retrier)
        {
            if (maxBatchOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchOperationCount));
            }

            if (maxBatchByteSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
            }

            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            if (retrier == null)
            {
                throw new ArgumentNullException(nameof(retrier));
            }

            if (cosmosSerializer == null)
            {
                throw new ArgumentNullException(nameof(cosmosSerializer));
            }

            this.batchOperations        = new List <ItemBatchOperation>(maxBatchOperationCount);
            this.executor               = executor;
            this.retrier                = retrier;
            this.maxBatchByteSize       = maxBatchByteSize;
            this.maxBatchOperationCount = maxBatchOperationCount;
            this.cosmosSerializer       = cosmosSerializer;
        }
        public BatchAsyncStreamer(
            int maxBatchOperationCount,
            int maxBatchByteSize,
            TimerWheel timerWheel,
            SemaphoreSlim limiter,
            int maxDegreeOfConcurrency,
            CosmosSerializerCore serializerCore,
            BatchAsyncBatcherExecuteDelegate executor,
            BatchAsyncBatcherRetryDelegate retrier)
        {
            if (maxBatchOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchOperationCount));
            }

            if (maxBatchByteSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
            }

            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            if (retrier == null)
            {
                throw new ArgumentNullException(nameof(retrier));
            }

            if (serializerCore == null)
            {
                throw new ArgumentNullException(nameof(serializerCore));
            }

            if (limiter == null)
            {
                throw new ArgumentNullException(nameof(limiter));
            }

            if (maxDegreeOfConcurrency < 1)
            {
                throw new ArgumentNullException(nameof(maxDegreeOfConcurrency));
            }

            this.maxBatchOperationCount = maxBatchOperationCount;
            this.maxBatchByteSize       = maxBatchByteSize;
            this.executor       = executor;
            this.retrier        = retrier;
            this.timerWheel     = timerWheel;
            this.serializerCore = serializerCore;
            this.currentBatcher = this.CreateBatchAsyncBatcher();
            this.ResetTimer();

            this.limiter                = limiter;
            this.oldPartitionMetric     = new BatchPartitionMetric();
            this.partitionMetric        = new BatchPartitionMetric();
            this.maxDegreeOfConcurrency = maxDegreeOfConcurrency;

            this.StartCongestionControlTimer();
        }