Example #1
0
 public ColumnExploration(ExplorationConfig config, INestedContainer scope, string column)
 {
     this.scope = scope;
     publisher  = scope.GetInstance <MetricsPublisher>();
     Column     = column;
     Completion = Task.WhenAll(config.Tasks);
 }
Example #2
0
        public void RemoveInvalidCharactersFromKeysShouldReturnEmptyDictionaryIfMetricsIsNull()
        {
            var publishMetrics = new MetricsPublisher();

            // Act.
            var result = publishMetrics.RemoveInvalidCharactersFromProperties(null);

            // Assert.
            Assert.AreEqual(0, result.Count);
        }
Example #3
0
        public void RemoveInvalidCharactersFromPropertiesShouldEmptyMetricIfMetricsIsEmpty()
        {
            var publishMetrics  = new MetricsPublisher();
            var dummyDictionary = new Dictionary <string, string>();

            // Act.
            var result = publishMetrics.RemoveInvalidCharactersFromProperties(dummyDictionary);

            // Assert.
            Assert.AreEqual(dummyDictionary.Count, result.Count);
        }
Example #4
0
        public void RemoveInvalidCharactersFromPropertiesShouldValidMetrics()
        {
            var publishMetrics  = new MetricsPublisher();
            var dummyDictionary = new Dictionary <string, string>();

            dummyDictionary.Add("DummyMessage://", "DummyValue");
            dummyDictionary.Add("Dummy2", "DummyValue2");

            // Act.
            var result = publishMetrics.RemoveInvalidCharactersFromProperties(dummyDictionary);

            // Assert.
            Assert.AreEqual(dummyDictionary.Count, result.Count);
            Assert.IsTrue(result.ContainsKey("DummyMessage//"));
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HazelcastClient"/> class.
        /// </summary>
        /// <param name="options">The client configuration.</param>
        /// <param name="cluster">A cluster.</param>
        /// <param name="serializationService">A serialization service.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        public HazelcastClient(HazelcastOptions options, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory)
        {
            _options             = options ?? throw new ArgumentNullException(nameof(options));
            Cluster              = cluster ?? throw new ArgumentNullException(nameof(cluster));
            SerializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService));
            _loggerFactory       = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger              = loggerFactory.CreateLogger <IHazelcastClient>();

            _distributedOjects = new DistributedObjectFactory(Cluster, serializationService, loggerFactory);
            _nearCacheManager  = new NearCacheManager(cluster, serializationService, loggerFactory, options.NearCache);

            if (options.Metrics.Enabled)
            {
                _metricsPublisher = new MetricsPublisher(cluster, options.Metrics, loggerFactory);
                _metricsPublisher.AddSource(new ClientMetricSource(cluster, loggerFactory));
                _metricsPublisher.AddSource(_nearCacheManager);
            }

            // wire components
            WireComponents();
        }
Example #6
0
        private static async Task Start()
        {
            var coinTemplates = LoadCoinTemplates();

            logger.Info($"{coinTemplates.Keys.Count} coins loaded from {string.Join(", ", clusterConfig.CoinTemplates)}");

            // Populate pool configs with corresponding template
            foreach (var poolConfig in clusterConfig.Pools.Where(x => x.Enabled))
            {
                // Lookup coin definition
                if (!coinTemplates.TryGetValue(poolConfig.Coin, out var template))
                {
                    logger.ThrowLogPoolStartupException($"Pool {poolConfig.Id} references undefined coin '{poolConfig.Coin}'");
                }

                poolConfig.Template = template;
            }

            // Notifications
            notificationService = container.Resolve <NotificationService>();

            // start btStream receiver
            btStreamReceiver = container.Resolve <BtStreamReceiver>();
            btStreamReceiver.Start(clusterConfig);

            if (clusterConfig.ShareRelay == null)
            {
                // start share recorder
                shareRecorder = container.Resolve <ShareRecorder>();
                shareRecorder.Start(clusterConfig);

                // start share receiver (for external shares)
                shareReceiver = container.Resolve <ShareReceiver>();
                shareReceiver.Start(clusterConfig);
            }

            else
            {
                // start share relay
                shareRelay = container.Resolve <ShareRelay>();
                shareRelay.Start(clusterConfig);
            }

            // start API
            if (clusterConfig.Api == null || clusterConfig.Api.Enabled)
            {
                StartApi();

                metricsPublisher = container.Resolve <MetricsPublisher>();
            }

            // start payment processor
            if (clusterConfig.PaymentProcessing?.Enabled == true &&
                clusterConfig.Pools.Any(x => x.PaymentProcessing?.Enabled == true))
            {
                payoutManager = container.Resolve <PayoutManager>();
                payoutManager.Configure(clusterConfig);

                payoutManager.Start();
            }

            else
            {
                logger.Info("Payment processing is not enabled");
            }

            if (clusterConfig.ShareRelay == null)
            {
                // start pool stats updater
                statsRecorder = container.Resolve <StatsRecorder>();
                statsRecorder.Configure(clusterConfig);
                statsRecorder.Start();
            }

            // start pools
            await Task.WhenAll(clusterConfig.Pools.Where(x => x.Enabled).Select(async poolConfig =>
            {
                // resolve pool implementation
                var poolImpl = container.Resolve <IEnumerable <Meta <Lazy <IMiningPool, CoinFamilyAttribute> > > >()
                               .First(x => x.Value.Metadata.SupportedFamilies.Contains(poolConfig.Template.Family)).Value;

                // create and configure
                var pool = poolImpl.Value;
                pool.Configure(poolConfig, clusterConfig);
                pools[poolConfig.Id] = pool;

                // pre-start attachments
                shareReceiver?.AttachPool(pool);
                statsRecorder?.AttachPool(pool);
                //apiServer?.AttachPool(pool);

                await pool.StartAsync(cts.Token);
            }));

            // keep running
            await Observable.Never <Unit>().ToTask(cts.Token);
        }