@Override @Deprecated public void setHeartbeatInterval(int interval) { log.warn("**Deprecated**: Please use: sshClient.getConnection().getKeepAlive().setKeepAliveInterval()"); sshClient.getConnection().getKeepAlive().setKeepAliveInterval(interval); }
@Override @Deprecated public int getHeartbeatInterval() { log.warn("**Deprecated**: Please use: sshClient.getConnection().getKeepAlive().getKeepAliveInterval()"); return sshClient.getConnection().getKeepAlive().getKeepAliveInterval(); }
@Test @Category({SlowTests.class, KnownFailingTests.class}) public void shouldCorrectlyTerminateThreadOnDisconnect() throws IOException, InterruptedException { DefaultConfig defaultConfig = new DefaultConfig(); defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE); for (int i = 0; i < 10; i++) { SSHClient sshClient = fixture.setupClient(defaultConfig); fixture.connectClient(sshClient); sshClient.getConnection().getKeepAlive().setKeepAliveInterval(1); try { sshClient.authPassword("bad", "credentials"); fail("Should not auth."); } catch (UserAuthException e) { // OK } fixture.stopClient(); Thread.sleep(2000); } ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); for (long l : threadMXBean.getAllThreadIds()) { ThreadInfo threadInfo = threadMXBean.getThreadInfo(l); if (threadInfo.getThreadName().equals("keep-alive") && threadInfo.getThreadState() != Thread.State.TERMINATED) { fail("Found alive keep-alive thread in state " + threadInfo.getThreadState()); } } } }
@Override @Deprecated public int getHeartbeatInterval() { log.warn("**Deprecated**: Please use: sshClient.getConnection().getKeepAlive().getKeepAliveInterval()"); return sshClient.getConnection().getKeepAlive().getKeepAliveInterval(); }
@Override @Deprecated public void setHeartbeatInterval(int interval) { log.warn("**Deprecated**: Please use: sshClient.getConnection().getKeepAlive().setKeepAliveInterval()"); sshClient.getConnection().getKeepAlive().setKeepAliveInterval(interval); }
public class KeepAlive { public static void main(String... args) throws IOException, InterruptedException { DefaultConfig defaultConfig = new DefaultConfig(); defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE); final SSHClient ssh = new SSHClient(defaultConfig); try { ssh.addHostKeyVerifier(new PromiscuousVerifier()); ssh.connect(args[0]); ssh.getConnection().getKeepAlive().setKeepAliveInterval(5); //every 60sec ssh.authPassword(args[1], args[2]); Session session = ssh.startSession(); session.allocateDefaultPTY(); new CountDownLatch(1).await(); try { session.allocateDefaultPTY(); } finally { session.close(); } } finally { ssh.disconnect(); } } }
sshClient.setTimeout(this.readTimeout * 1000); sshClient.setConnectTimeout(this.connectTimeout * 1000); sshClient.getConnection().getKeepAlive().setKeepAliveInterval(this.keepAlive); if (StringUtils.isNotBlank(pemPath)) { log.info("Use key at [" + pemPath + "] to connect to the machine [" + ip + "]");
transport.setDisconnectListener(disconnectListener); connection.connect(HostnameConfiguratorFactory.get(host.getProtocol()).getHostname(host.getHostname()), host.getPort()); final KeepAlive keepalive = connection.getConnection().getKeepAlive(); keepalive.setKeepAliveInterval(preferences.getInteger("ssh.heartbeat.seconds")); return connection;