public synchronized void start()

in server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnector.java [125:181]


    public synchronized void start() throws RemoteServerNotFoundException, RemoteServerTimeoutException {
        LOG.info("Starting XMPP server connector to {}", remoteServer);

        boolean successfullyConnected = false;

        XmppEndpointResolver resolver = new XmppEndpointResolver();
        List<ResolvedAddress> addresses = resolver.resolveXmppServer(remoteServer.getDomain());

        Throwable lastException = null;

        if (!addresses.isEmpty()) {
            LOG.info("resolved {} address(es) for {}", addresses.size(), remoteServer);
            for (ResolvedAddress address : addresses) {
                final InetSocketAddress ipAddress = address.getAddress();
                LOG.info("Connecting to XMPP server {} at {}", remoteServer, ipAddress);

                connector = createConnector();
                ConnectFuture connectFuture = connector.connect(ipAddress);
                if (connectFuture.awaitUninterruptibly(connectTimeout) && connectFuture.isConnected()) {
                    // success on the TCP/IP level, now wait for the XMPP handshake
                    LOG.info("XMPP server {} connected at {}", remoteServer, ipAddress);
                    try {
                        if (authenticatedLatch.await(xmppHandshakeTimeout, TimeUnit.MILLISECONDS)) {
                            // success, break out of connect loop
                            successfullyConnected = true;
                            break;
                        } else {
                            // attempt next
                            LOG.warn("XMPP handshake with {} at {} timed out", remoteServer, ipAddress);
                        }
                    } catch (InterruptedException e) {
                        throw new RemoteServerTimeoutException("XMPPConnection to " + remoteServer + " was interrupted",
                                e);
                    }
                }

                lastException = connectFuture.getException();
                LOG.warn("Failed connecting to XMPP server " + remoteServer + " at " + ipAddress,
                        connectFuture.getException());
                disposeAndNullifyConnector();
            }
        } else {
            // should never happen
            throw new RemoteServerNotFoundException("DNS lookup of remote server failed");
        }

        if (!successfullyConnected) {
            String exceptionMsg = "Failed to connect to XMPP server at " + remoteServer;

            if (lastException instanceof UnresolvedAddressException) {
                throw new RemoteServerNotFoundException(exceptionMsg);
            } else {
                throw new RemoteServerTimeoutException(exceptionMsg);
            }

        }
    }