public static void Validate(AirlockConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (config.SendPeriod < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(config.SendPeriod));
            }

            if (config.SendPeriod > config.SendPeriodCap)
            {
                throw new ArgumentException($"{nameof(config.SendPeriod)} should be less or equal to {nameof(config.SendPeriodCap)}");
            }

            if (config.ClusterProvider == null)
            {
                throw new ArgumentNullException(nameof(config.ClusterProvider));
            }

            if (string.IsNullOrEmpty(config.ApiKey))
            {
                throw new ArgumentNullException(nameof(config.ApiKey));
            }

            if (config.MaximumRecordSize > config.MaximumBatchSizeToSend)
            {
                throw new ArgumentException($"Provided maximum record size ({config.MaximumRecordSize}) was greater than maximum batch size ({config.MaximumBatchSizeToSend}).");
            }
        }
예제 #2
0
        public ParallelAirlockClient(AirlockConfig config, int parallelism, ILog log = null)
        {
            clients = new AirlockClient[parallelism];

            for (var i = 0; i < parallelism; i++)
            {
                clients[i] = new AirlockClient(config, log);
            }
        }
예제 #3
0
        public DataSenderDaemon(
            IDataSender sender,
            AirlockConfig config,
            ILog log)
        {
            this.sender = sender;
            this.config = config;
            this.log    = log;

            routineCancellation = new TaskCompletionSource <byte>();
            routine             = Routine();
        }
예제 #4
0
        public RequestSender(AirlockConfig config, ILog log)
        {
            this.config = config;
            this.log    = log;

            client = new ClusterClient(log, configuration =>
            {
                configuration.ServiceName            = "airlock";
                configuration.ClusterProvider        = config.ClusterProvider;
                configuration.DefaultTimeout         = config.RequestTimeout;
                configuration.DefaultRequestStrategy = Strategy.Forking2;
                configuration.EnableTracing          = config.EnableTracing;

                configuration.SetupVostokHttpTransport();
                configuration.SetupWeighedReplicaOrdering(builder => builder.AddAdaptiveHealthModifierWithLinearDecay(10.Minutes()));
                configuration.SetupReplicaBudgeting(configuration.ServiceName);
                configuration.SetupAdaptiveThrottling(configuration.ServiceName);
            });
        }
예제 #5
0
        public AirlockClient(AirlockConfig config, ILog log = null)
        {
            AirlockConfigValidator.Validate(config);

            this.config = config;

            this.log = log = (log ?? new SilentLog()).ForContext(this);

            memoryManager = new MemoryManager(
                config.MaximumMemoryConsumption.Bytes,
                (int)config.InitialPooledBufferSize.Bytes
                );
            recordWriter     = new RecordWriter(new RecordSerializer(config.MaximumRecordSize, log));
            bufferPools      = new ConcurrentDictionary <string, IBufferPool>();
            lostItemsCounter = new AtomicLong(0);
            sentItemsCounter = new AtomicLong(0);

            var requestSender      = new RequestSender(config, log);
            var commonBatchBuffer  = new byte[config.MaximumBatchSizeToSend.Bytes];
            var bufferSliceFactory = new BufferSliceFactory();
            var dataBatchesFactory = new DataBatchesFactory(
                bufferPools,
                bufferSliceFactory,
                commonBatchBuffer
                );
            var dataSender = new DataSender(
                dataBatchesFactory,
                requestSender,
                log,
                lostItemsCounter,
                sentItemsCounter
                );

            dataSenderDaemon       = new DataSenderDaemon(dataSender, config, log);
            isDisposed             = new AtomicBoolean(false);
            pushAfterDisposeLogged = new AtomicBoolean(false);
        }