public DummyController()
 {
     _timer = new FixedRateTimer(
         async() => { await NotifyAsync(null, new Parameters()); },
         1000, 1000
         );
 }
    public AirVRInputStream()
    {
        senders   = new Dictionary <string, AirVRInputSender>();
        receivers = new Dictionary <string, AirVRInputReceiver>();

        _timer = new FixedRateTimer();
    }
Esempio n. 3
0
        public async Task OpenAsync(string correlationId)
        {
            if (IsOpened())
            {
                return;
            }

            var connection = await _connectionResolver.ResolveAsync(correlationId);

            var uri = new Uri(connection.Uri);

            try
            {
                // Create client
                var settings = new ConnectionConfiguration(uri)
                               .RequestTimeout(TimeSpan.FromMinutes(2))
                               .ThrowExceptions(true);
                _client = new ElasticLowLevelClient(settings);

                // Create index if it doesn't exist
                await CreateIndex(correlationId, true);

                if (_timer == null)
                {
                    _timer = new FixedRateTimer(OnTimer, _interval, _interval);
                    _timer.Start();
                }
            }
            catch
            {
                // Do nothing if elastic search client was not initialized
                _errorConsoleLogger.Error(correlationId, $"Failed to initialize Elastic Search Logger with uri='{uri}'");
            }
        }
        public async Task OpenAsync(string correlationId)
        {
            if (_opened == true)
            {
                return;
            }

            // Create filter if it doesn't exist
            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }

            // Restart cleanup process
            if (_cleanupInterval != null)
            {
                _cleanupInterval.Stop();
            }

            _cleanupInterval = new FixedRateTimer(
                () => { Cleanup(null); },
                (int)_cleanupTimeout, (int)_cleanupTimeout
                );
            _cleanupInterval.Start();

            _opened = true;

            await Task.Delay(0);
        }
        public async Task CloseAsync(string correlationId)
        {
            // Stop cleanup process
            if (_cleanupInterval != null)
            {
                _cleanupInterval.Stop();
                _cleanupInterval = null;
            }

            _opened = false;

            await Task.Delay(0);
        }
Esempio n. 6
0
        /// <summary>
        /// Closes component and frees used resources.
        /// </summary>
        /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param>
        public async Task CloseAsync(string correlationId)
        {
            // Log all remaining messages before closing
            Dump();

            if (_timer != null)
            {
                _timer.Stop();
                _timer = null;
            }

            _client = null;

            await Task.Delay(0);
        }
Esempio n. 7
0
        public virtual void Configure(ConfigParams config)
        {
            Enabled       = config.GetAsBooleanWithDefault("parameters.enabled", true);
            TimerInterval = config.GetAsNullableInteger("parameters.timer_interval") ?? DefaultTimerInterval;
            DelayInterval = config.GetAsNullableInteger("parameters.delay_interval") ?? DefaultDelayInterval;

            MinimumThroughput = config.GetAsNullableInteger("parameters.minimum_throughput") ?? DefaultMinimumThroughput;
            MaximumThroughput = config.GetAsNullableInteger("parameters.maximum_throughput") ?? DefaultMaximumThroughput;
            GrowthRate        = config.GetAsNullableDouble("parameters.growth_rate") ?? DefaultGrowthRate;

            ResourceGroup = config.GetAsString("parameters.resource_group");
            ConnectionUri = config.GetAsString("parameters.connection_uri");

            var mongoDbConnectionUrl = new MongoUrlBuilder(ConnectionUri);

            AccountName  = mongoDbConnectionUrl.Username;
            AccessKey    = mongoDbConnectionUrl.Password;
            DatabaseName = mongoDbConnectionUrl.DatabaseName;

            _timer = new FixedRateTimer(PerformMonitorAsync, TimerInterval, DelayInterval);
        }
        public virtual void SetReferences(IReferences references)
        {
            try
            {
                _logger.SetReferences(references);

                var mongoDbConnectionUrl = new MongoUrlBuilder(ConnectionUri);
                AccountName  = mongoDbConnectionUrl.Username;
                AccessKey    = mongoDbConnectionUrl.Password;
                DatabaseName = mongoDbConnectionUrl.DatabaseName;

                _metricsService = references.GetOneRequired <ICosmosDbMetricsService>(new Descriptor("pip-services", "metrics-service", "*", "*", "*"));
                _lock           = references.GetOneRequired <ILock>(new Descriptor("pip-services", "lock", "*", "*", "*"));

                _timer = new FixedRateTimer(PerformMonitorAsync, TimerInterval, DelayInterval);
            }
            catch (Exception exception)
            {
                _logger.Error("AbstractCosmosDbPersistenceThroughputMonitor", exception,
                              $"Failed to configure the CosmosDb persistence throughput monitor with parameters '{_configParams}'.");
            }
        }
Esempio n. 9
0
    public AirVRInputStream()
    {
        _timer = new FixedRateTimer();

        senders = new Dictionary <byte, AirVRInputSender>();
    }
        /// <summary>
        /// Opens the component.
        /// </summary>
        /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param>
        public async Task OpenAsync(string correlationId)
        {
            if (IsOpen())
            {
                return;
            }

            var awsConnection = await _connectionResolver.ResolveAsync(correlationId);

            // Assign service name
            awsConnection.Service      = "logs";
            awsConnection.ResourceType = "log-group";

            if (!string.IsNullOrEmpty(awsConnection.Resource))
            {
                _group = awsConnection.Resource;
            }

            // Undefined stream creates a random stream on every connect
            if (string.IsNullOrEmpty(_stream))
            {
                _stream = IdGenerator.NextLong();
            }

            // Validate connection params
            var err = awsConnection.Validate(correlationId);

            if (err != null)
            {
                throw err;
            }

            // Create client
            var region = RegionEndpoint.GetBySystemName(awsConnection.Region);
            var config = new AmazonCloudWatchLogsConfig()
            {
                RegionEndpoint = region
            };

            _client = new AmazonCloudWatchLogsClient(awsConnection.AccessId, awsConnection.AccessKey, config);

            // Create a log group if needed
            try
            {
                await _client.CreateLogGroupAsync(
                    new CreateLogGroupRequest
                {
                    LogGroupName = _group
                }
                    );
            }
            catch (ResourceAlreadyExistsException)
            {
                // Ignore. Everything is ok
            }

            // Create or read log stream
            try
            {
                await _client.CreateLogStreamAsync(
                    new CreateLogStreamRequest
                {
                    LogGroupName  = _group,
                    LogStreamName = _stream
                }
                    );

                _lastToken = null;
            }
            catch (ResourceAlreadyExistsException)
            {
                var response = await _client.DescribeLogStreamsAsync(
                    new DescribeLogStreamsRequest
                {
                    LogGroupName        = _group,
                    LogStreamNamePrefix = _stream
                }
                    );

                if (response.LogStreams.Count > 0)
                {
                    _lastToken = response.LogStreams[0].UploadSequenceToken;
                }
            }

            if (_timer == null)
            {
                _timer = new FixedRateTimer(OnTimer, _interval, _interval);
                _timer.Start();
            }
        }