com.github.woostju:ssh-client-pool

pool for java ssh client

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.woostju
ArtifactId

ArtifactId

ssh-client-pool
Last Version

Last Version

1.0.1-RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

com.github.woostju:ssh-client-pool
pool for java ssh client
Project URL

Project URL

https://github.com/woostju/ssh-client-pool
Project Organization

Project Organization

Pivotal Software, Inc.
Source Code Management

Source Code Management

https://github.com/woostju/ssh-client-pool.git

Download ssh-client-pool

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.woostju/ssh-client-pool/ -->
<dependency>
    <groupId>com.github.woostju</groupId>
    <artifactId>ssh-client-pool</artifactId>
    <version>1.0.1-RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.woostju/ssh-client-pool/
implementation 'com.github.woostju:ssh-client-pool:1.0.1-RELEASE'
// https://jarcasting.com/artifacts/com.github.woostju/ssh-client-pool/
implementation ("com.github.woostju:ssh-client-pool:1.0.1-RELEASE")
'com.github.woostju:ssh-client-pool:jar:1.0.1-RELEASE'
<dependency org="com.github.woostju" name="ssh-client-pool" rev="1.0.1-RELEASE">
  <artifact name="ssh-client-pool" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.woostju', module='ssh-client-pool', version='1.0.1-RELEASE')
)
libraryDependencies += "com.github.woostju" % "ssh-client-pool" % "1.0.1-RELEASE"
[com.github.woostju/ssh-client-pool "1.0.1-RELEASE"]

Dependencies

compile (6)

Group / Artifact Type Version
com.hierynomus : sshj jar 0.26.0
org.bouncycastle : bcprov-jdk15on jar 1.60
com.fasterxml.uuid : java-uuid-generator jar 3.1.4
net.sf.expectit : expectit-core jar 0.9.0
org.apache.commons : commons-pool2 jar 2.8.0
org.springframework.boot : spring-boot-starter-test jar 1.5.10.RELEASE

Project Modules

There are no modules declared in this project.

ssh-client-pool

a java implementation of ssh clients object pool with sshj, apache common pool2, expectIt

usage

ssh-client-pool is available from Maven Central

<dependency>
  <groupId>com.github.woostju</groupId>
  <artifactId>ssh-client-pool</artifactId>
  <version>1.0.1-RELEASE</version>
</dependency>

Who is this for?

Anyone who wants to connect server instances through SSH, send commands to server and consume the output continuously.

Anyone who wants to cache the connected clients in an object pool, to reuse the client.

How do I use this?

The SshClientsPool is auto-configured, use it directly as:

@Autowired
SshClientsPool pool;

public void echo(){
	SshClientConfig clientConfig = new SshClientConfig("hostip", 22, "username", "password", null);
	SshClientWrapper client = pool.client(clientConfig);
	SshResponse response = client.executeCommand("echo 'hi'", 100);
	return response;
}

Can I configure the pool?

You can configure SshClientsPool in your SpringBoot properties file as:

woostju.ssh-client-pool.maxActive=16
woostju.ssh-client-pool.maxIdle=16
woostju.ssh-client-pool.idleTime=20000
woostju.ssh-client-pool.maxWait=20000

what's more, you can also register the SshClientsPool yourself:

@Bean
public SshClientsPool sshclientpool() {
   SshClientPoolConfig poolConfig = SshClientPoolConfig();
   poolConfig.setMaxTotalPerKey(maxTotal);
   poolConfig.setMaxIdlePerKey(maxIdle); 
   poolConfig.setBlockWhenExhausted(true);
   poolConfig.setMaxWaitMillis(1000L * maxWaitMillis); 
   	
   poolConfig.setMinEvictableIdleTimeMillis(1000L * idleTime); 
   poolConfig.setTimeBetweenEvictionRunsMillis(1000L * idleTime);
   poolConfig.setTestOnBorrow(true); 
   poolConfig.setTestOnReturn(true); 
   poolConfig.setTestWhileIdle(true);
   poolConfig.setJmxEnabled(false); //disbale jmx
   
   return new SshClientsPool(poolConfig);
}

SshClientPoolConfig is a subclass of GenericKeyedObjectPool in Apacha Common Pool2, learn more from apache common pool2 to configure the pool.

How does it work?

When you request a client from pool, it will pull an idle one, if there is no idle client, a created one return. After you execute a command, it will return the client to pool as an idle one. If you close the client explicitly, the client will be destroyed and remove from pool.

License

This code is under the Apache Licence v2.

Additional Resources

Versions

Version
1.0.1-RELEASE
1.0.0-RELEASE
0.9.1-RELEASE
0.9.0-RELEASE