示例#1
0
        /// <inheritdoc />
        public override void Run()
        {
            BeforeStart();

            _controllerNodes = NodeDefinition.ParseConnectionString(_settings.ConnectionString);

            // Find yourself
            _self = null;
            foreach (var def in _controllerNodes)
            {
                if (def.IsSelf(_settings.Port))
                {
                    _self = def;
                    break;
                }
            }

            if (_self == null)
            {
                Logger.Log("Could not find myself in the connection string, shutting down.", LogLevel.Error);
                AfterStop();
                return;
            }

            // If you get a JoinFailure from any other node, stop because this node's settings are wrong.
            foreach (var def in _controllerNodes)
            {
                if (!Equals(def, Self) && !ConnectToController(def))
                {
                    AfterStop();
                    return;
                }
            }

            if (_controllerNodes.Count == 1)
            {
                Logger.Log("Only controller in the network, becoming primary.", LogLevel.Info);
                Primary = Self;
            }

            _reconnectionThread = new Thread(ReconnectionThreadRun);
            _reconnectionThread.Start();

            _maintenanceThread = new Thread(MaintenanceThreadRun);
            _maintenanceThread.Start();

            while (Running)
            {
                Thread.Sleep(1);
            }

            AfterStop();
        }
示例#2
0
        /// <inheritdoc />
        public override void Run()
        {
            BeforeStart();

            _controllerNodes = NodeDefinition.ParseConnectionString(_settings.ConnectionString);

            if (_controllerNodes.Any(def => !ConnectToController(def)))
            {
                return;
            }

            _reconnectionThread = new Thread(ReconnectionThreadRun);
            _reconnectionThread.Start();

            while (Running)
            {
                Thread.Sleep(100);
            }

            AfterStop();
        }
示例#3
0
            /// <inheritdoc />
            public override void Run()
            {
                BeforeStart();

                List <NodeDefinition> controllerNodes = NodeDefinition.ParseConnectionString(_connectionString);

                foreach (var def in controllerNodes)
                {
                    Message message = new Message(def, new JoinAttempt(NodeType.Api, string.Empty, -1, _connectionString), true)
                    {
                        SendWithoutConfirmation = true
                    };

                    SendMessage(message);
                    message.BlockUntilDone();

                    if (message.Success)
                    {
                        if (message.Response.Data is JoinFailure)
                        {
                            _connected = false;
                            AfterStop();
                            return;
                        }

                        JoinSuccess successData = (JoinSuccess)message.Response.Data;
                        Connections[def].ConnectionEstablished(message.Address, NodeType.Controller);
                        if (successData.Data["PrimaryController"].ValueAsBoolean)
                        {
                            Primary    = message.Address;
                            _connected = true;
                        }

                        SendMessage(new Message(message.Response, new Acknowledgement(), false));
                    }
                }
            }