Example #1
0
        internal CountersBatchOperation(CounterStore parent, string counterStorageName, CountersBatchOptions batchOptions = null)
            : base(parent, counterStorageName)
        {
            if (batchOptions != null && batchOptions.BatchSizeLimit < 1)
            {
                throw new ArgumentException("batchOptions.BatchSizeLimit cannot be negative", "batchOptions");
            }

            defaultOptions    = batchOptions ?? new CountersBatchOptions(); //defaults do exist
            streamingStarted  = new AsyncManualResetEvent();
            batchOperationTcs = new TaskCompletionSource <bool>();
            cts           = new CancellationTokenSource();
            changesQueue  = new BlockingCollection <CounterChange>(defaultOptions.BatchSizeLimit);
            singleAuthUrl = string.Format("{0}/cs/{1}/singleAuthToken", ServerUrl, counterStorageName);

            OperationId        = Guid.NewGuid();
            disposed           = false;
            batchOperationTask = StartBatchOperation();
            if (AsyncHelpers.RunSync(() => streamingStarted.WaitAsync(TimeSpan.FromMilliseconds(DefaultOptions.StreamingInitializeTimeout))) == false ||
                batchOperationTask.IsFaulted)
            {
                throw new InvalidOperationException("Failed to start streaming batch.", batchOperationTask.Exception);
            }
            closeAndReopenStreamingTimer = CreateNewTimer();
        }
Example #2
0
            public CountersBatchOperation NewBatch(CountersBatchOptions options = null)
            {
                if (parent.Name == null)
                {
                    throw new ArgumentException("Counter Storage isn't set!");
                }

                parent.AssertInitialized();

                return(new CountersBatchOperation(parent, parent.Name, options));
            }