Search in sources :

Example 6 with RuntimeSshException

use of org.apache.sshd.common.RuntimeSshException in project tesb-studio-se by Talend.

the class RuntimeClient method connectWithRetries.

private static ClientSession connectWithRetries(SshClient client, ClientConfig config) throws Exception, InterruptedException {
    ClientSession session = null;
    int retries = 0;
    do {
        try {
            ConnectFuture future = client.connect(config.getUser(), config.getHost(), config.getPort());
            future.await();
            session = future.getSession();
        } catch (RuntimeSshException ex) {
            if (++retries < 10) {
                TimeUnit.SECONDS.sleep(2);
            } else {
                throw ex;
            }
        }
    } while (session == null);
    return session;
}
Also used : ClientSession(org.apache.sshd.client.session.ClientSession) ConnectFuture(org.apache.sshd.client.future.ConnectFuture) RuntimeSshException(org.apache.sshd.common.RuntimeSshException)

Example 7 with RuntimeSshException

use of org.apache.sshd.common.RuntimeSshException in project karaf by apache.

the class ClientMojo method connect.

private ClientSession connect(SshClient client) throws IOException, InterruptedException {
    int retries = 0;
    ClientSession session = null;
    do {
        final ConnectFuture future = client.connect(user, host, port);
        future.await();
        try {
            session = future.getSession();
        } catch (RuntimeSshException ex) {
            if (retries++ < attempts) {
                Thread.sleep(TimeUnit.SECONDS.toMillis(delay));
                getLog().info("retrying (attempt " + retries + ") ...");
            } else {
                throw ex;
            }
        }
    } while (session == null);
    return session;
}
Also used : ClientSession(org.apache.sshd.client.session.ClientSession) ConnectFuture(org.apache.sshd.client.future.ConnectFuture) RuntimeSshException(org.apache.sshd.common.RuntimeSshException)

Aggregations

RuntimeSshException (org.apache.sshd.common.RuntimeSshException)7 ConnectFuture (org.apache.sshd.client.future.ConnectFuture)4 ClientSession (org.apache.sshd.client.session.ClientSession)4 SshException (org.platformlayer.ops.ssh.SshException)3 TimeSpan (com.fathomdb.TimeSpan)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)1