Ejemplo n.º 1
0
        private InfluxDBClient(IInfluxDBHttpClient httpClient, string database, string?retentionPolicy,
                               Action <Exception>?errorCallback, int initialBufferSize,
                               int maxBufferSize, CancellationTokenSource cancellationTokenSource, TimeSpan?forceFlushInterval,
                               ArrayPool <byte> arrayPool)
        {
            _errorCallback = errorCallback;

            var path = retentionPolicy == null
                ? $"write?db={Uri.EscapeDataString(database)}&precision=ms"
                : $"write?db={Uri.EscapeDataString(database)}&precision=ms&rp={Uri.EscapeDataString(retentionPolicy)}";

            _bufferSize              = initialBufferSize;
            _maxBufferSize           = maxBufferSize;
            _arrayPool               = arrayPool;
            _cancellationTokenSource = cancellationTokenSource ?? new CancellationTokenSource();
            _memory = _arrayPool.Rent(initialBufferSize);

            if (forceFlushInterval != null)
            {
                _forceFlushInterval = forceFlushInterval.Value;
                _timer = new Timer(ForceFlush, null, _forceFlushInterval, _forceFlushInterval);
            }

            _output = new InfluxDBOutput(httpClient, path);
            _task   = Run(_cancellationTokenSource.Token);
        }