Repository: karaf Updated Branches: refs/heads/master 843909a89 -> 6948726cc
KARAF-4246 - Add support of idle timeout to the client Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/6948726c Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/6948726c Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/6948726c Branch: refs/heads/master Commit: 6948726ccb41cdfb23a749b30ad46b7a750ef758 Parents: 843909a Author: Jean-Baptiste Onofré <[email protected]> Authored: Tue Jan 5 18:34:31 2016 +0100 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Tue Jan 5 18:34:31 2016 +0100 ---------------------------------------------------------------------- .../org/apache/karaf/client/ClientConfig.java | 20 +++++++++++++++++--- .../main/java/org/apache/karaf/client/Main.java | 11 ++++------- 2 files changed, 21 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/6948726c/client/src/main/java/org/apache/karaf/client/ClientConfig.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/karaf/client/ClientConfig.java b/client/src/main/java/org/apache/karaf/client/ClientConfig.java index 2968c64..995ee01 100644 --- a/client/src/main/java/org/apache/karaf/client/ClientConfig.java +++ b/client/src/main/java/org/apache/karaf/client/ClientConfig.java @@ -41,6 +41,7 @@ public class ClientConfig { private int level; private int retryAttempts; private int retryDelay; + private long idleTimeout; private boolean batch; private String file = null; private String keyFile = null; @@ -67,6 +68,7 @@ public class ClientConfig { level = Integer.parseInt(shellCfg.getProperty("logLevel", "1")); retryAttempts = 0; retryDelay = 2; + idleTimeout = Long.parseLong(shellCfg.getProperty("sshIdleTimeout", "1800000")); batch = false; file = null; user = null; @@ -112,7 +114,6 @@ public class ClientConfig { level = levelValue; } } - } else if (args[i].equals("-r")) { if (args.length <= ++i) { System.err.println("miss the attempts"); @@ -143,6 +144,13 @@ public class ClientConfig { } else { keyFile = args[i]; } + } else if (args[i].equals("-t")) { + if (args.length <= ++i) { + System.err.println("miss the idle timeout"); + System.exit(1); + } else { + idleTimeout = Long.parseLong(args[i]); + } } else if (args[i].equals("--help")) { showHelp(); } else if (args[i].equals("--")) { @@ -187,12 +195,13 @@ public class ClientConfig { System.out.println(" -u [user] specify the user name"); System.out.println(" --help shows this help message"); System.out.println(" -v raise verbosity"); - System.out.println(" -l set client logging level. Set to 0 for ERROR logging and up to 4 for TRACE."); + System.out.println(" -l set client logging level. Set to 0 for ERROR logging and up to 4 for TRACE"); System.out.println(" -r [attempts] retry connection establishment (up to attempts times)"); System.out.println(" -d [delay] intra-retry delay (defaults to 2 seconds)"); System.out.println(" -b batch mode, specify multiple commands via standard input"); System.out.println(" -f [file] read commands from the specified file"); - System.out.println(" -k [keyFile] specify the private keyFile location when using key login, need have BouncyCastle registered as security provider using this flag"); + System.out.println(" -k [keyFile] specify the private keyFile location when using key login, need have BouncyCastle registered as security provider using this flag"); + System.out.println(" -t [timeout] define the client idle timeout"); System.out.println(" [commands] [--] commands to run"); System.out.println("If no commands are specified, the client will be put in an interactive mode"); System.exit(0); @@ -298,4 +307,9 @@ public class ClientConfig { public String getKeyFile() { return keyFile; } + + public long getIdleTimeout() { + return idleTimeout; + } + } http://git-wip-us.apache.org/repos/asf/karaf/blob/6948726c/client/src/main/java/org/apache/karaf/client/Main.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/karaf/client/Main.java b/client/src/main/java/org/apache/karaf/client/Main.java index 31b7c2f..7a01299 100644 --- a/client/src/main/java/org/apache/karaf/client/Main.java +++ b/client/src/main/java/org/apache/karaf/client/Main.java @@ -17,6 +17,7 @@ package org.apache.karaf.client; import java.io.*; +import java.io.Closeable; import java.lang.reflect.Field; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -51,12 +52,7 @@ import org.apache.sshd.client.future.ConnectFuture; import org.apache.sshd.client.kex.ECDHP256; import org.apache.sshd.client.kex.ECDHP384; import org.apache.sshd.client.kex.ECDHP521; -import org.apache.sshd.common.KeyExchange; -import org.apache.sshd.common.NamedFactory; -import org.apache.sshd.common.PtyMode; -import org.apache.sshd.common.RuntimeSshException; -import org.apache.sshd.common.Session; -import org.apache.sshd.common.SshConstants; +import org.apache.sshd.common.*; import org.apache.sshd.common.keyprovider.FileKeyPairProvider; import org.apache.sshd.common.util.Buffer; import org.fusesource.jansi.AnsiConsole; @@ -108,8 +104,9 @@ public class Main { ) ); - client = (SshClient)clientBuilder.build(); + client = clientBuilder.build(); setupAgent(config.getUser(), config.getKeyFile(), client); + client.getProperties().put(FactoryManager.IDLE_TIMEOUT, String.valueOf(config.getIdleTimeout())); final Console console = System.console(); if (console != null) { client.setUserInteraction(new UserInteraction() {
