Beispiel #1
0
        private void ReconnectTo(NodeEndPoints endPoints)
        {
            IPEndPoint endPoint = _settings.UseSslConnection
                                          ? endPoints.SecureTcpEndPoint ?? endPoints.TcpEndPoint
                                          : endPoints.TcpEndPoint;

            if (endPoint == null)
            {
                CloseConnection("No end point is specified while trying to reconnect.");
                return;
            }

            if (_state != ConnectionState.Connected || _connection.RemoteEndPoint.Equals(endPoint))
            {
                return;
            }

            var msg = string.Format("EventStoreConnection '{0}': going to reconnect to [{1}]. Current endpoint: [{2}, L{3}].",
                                    _esConnection.ConnectionName, endPoint, _connection.RemoteEndPoint, _connection.LocalEndPoint);

            if (_settings.VerboseLogging)
            {
                _settings.Log.Info(msg);
            }
            CloseTcpConnection(msg);

            _state           = ConnectionState.Connecting;
            _connectingPhase = ConnectingPhase.EndPointDiscovery;
            EstablishTcpConnection(endPoints);
        }
        private void EstablishTcpConnection(NodeEndPoints endPoints)
        {
            var endPoint = _compatibilityMode.IsAutoCompatibilityModeEnabled() || _settings.UseSslConnection
                                ? endPoints.SecureTcpEndPoint ?? endPoints.TcpEndPoint
                                : endPoints.TcpEndPoint;

            if (endPoint == null)
            {
                CloseConnection("No end point to node specified.");
                return;
            }

            LogDebug("EstablishTcpConnection to [{0}]", endPoint);

            if (_state != ConnectionState.Connecting)
            {
                LogDebug("EstablishTcpConnection to [{0}] skipped because expected state 'Connecting', was '{1}'",
                         endPoint, _state);
                return;
            }

            if (_connectingPhase != ConnectingPhase.EndPointDiscovery)
            {
                LogDebug(
                    "EstablishTcpConnection to [{0}] skipped because expected connecting phase 'EndPointDiscovery', was '{1}'",
                    endPoint, _connectingPhase);
                return;
            }

            var useSsl = _compatibilityMode.IsAutoCompatibilityModeEnabled()
                                ? endPoints.SecureTcpEndPoint != null
                                : _settings.UseSslConnection;

            _connectingPhase = ConnectingPhase.ConnectionEstablishing;
            _connection      = new TcpPackageConnection(
                _settings.Log,
                endPoint,
                Guid.NewGuid(),
                useSsl,
                _settings.ValidateServer,
                _settings.ClientConnectionTimeout,
                (connection, package) => EnqueueMessage(new HandleTcpPackageMessage(connection, package)),
                (connection, exc) => EnqueueMessage(new TcpConnectionErrorMessage(connection, exc)),
                connection => EnqueueMessage(new TcpConnectionEstablishedMessage(connection)),
                (connection, error) => EnqueueMessage(new TcpConnectionClosedMessage(connection, error)));

            _connection.StartReceiving();
        }
Beispiel #3
0
        private void EstablishTcpConnection(NodeEndPoints endPoints)
        {
            var endPoint = _settings.UseSslConnection
                                ? endPoints.SecureTcpEndPoint ?? endPoints.TcpEndPoint
                                : endPoints.TcpEndPoint;

            if (endPoint == null)
            {
                CloseConnection("No end point to node specified.");
                return;
            }

            LogDebug("EstablishTcpConnection to [{0}]", endPoint);

            if (_state != ConnectionState.Connecting)
            {
                return;
            }
            if (_connectingPhase != ConnectingPhase.EndPointDiscovery)
            {
                return;
            }

            _connectingPhase = ConnectingPhase.ConnectionEstablishing;
            _connection      = new TcpPackageConnection(
                _settings.Log,
                endPoint,
                Guid.NewGuid(),
                _settings.UseSslConnection,
                _settings.TargetHost,
                _settings.ValidateServer,
                _settings.ClientConnectionTimeout,
                (connection, package) => EnqueueMessage(new HandleTcpPackageMessage(connection, package)),
                (connection, exc) => EnqueueMessage(new TcpConnectionErrorMessage(connection, exc)),
                connection => EnqueueMessage(new TcpConnectionEstablishedMessage(connection)),
                (connection, error) => EnqueueMessage(new TcpConnectionClosedMessage(connection, error)));
            _connection.StartReceiving();
        }
 public EstablishTcpConnectionMessage(NodeEndPoints endPoints)
 {
     EndPoints = endPoints;
 }