Ejemplo n.º 1
0
        public ClusterObjectKey(ClusterNodeKey hostNode, Int128 id)
        {
            VxArgs.NotNull(hostNode, nameof(hostNode));

            HostNode = hostNode;

            Id = id;
        }
Ejemplo n.º 2
0
        private ClusterNode(
            IIxHost indirectXHost,
            IWebHostBuilder webHostBuilder,
            IConfigurationRoot configRoot,
            IJsonLogger logger)
        {
            Log         = new ClassJsonLogger <ClusterNode>(logger);
            _executeCts = new CancellationTokenSource();
            _executeCancellationToken = _executeCts.Token;

            _indirectXHost = indirectXHost;
            _configRoot    = configRoot;

            Log.Info(_ => _("Starting Asp.Net core..."));

            _webHost = webHostBuilder
                       .UseStartup <ClusterNodeStartup>()
                       .Build();

            _webHost.Start();
            _hostLifetimeService = _webHost.Services.GetRequiredService <IApplicationLifetime>();

            Key = new ClusterNodeKey(_configRoot.GetValue(ClusterNodeIdKey, "single-node"));

            var addressesFeature = _webHost.ServerFeatures.Get <IServerAddressesFeature>();

            foreach (string addressesFeatureAddress in addressesFeature.Addresses)
            {
                Log.Info(
                    addressesFeatureAddress,
                    (_, addr) => _($"NodeId = '{Key.Code}' listening on: {addr}").Data(new { ListenAddress = addr }));
            }

            Console.CancelKeyPress += (sender, e) =>
            {
                if (!_executeCancellationToken.IsCancellationRequested)
                {
                    Log.Trace(_ => _("Termination raised by system."));
                    _executeCts.Cancel();
                }

                e.Cancel = true;
            };
        }