public class SshdSession extends java.lang.Object implements RemoteSession
RemoteSession
based on Apache MINA sshd.Modifier and Type | Class and Description |
---|---|
private static interface |
SshdSession.FtpOperation<T>
Helper interface like
Supplier , but possibly raising an
IOException . |
private static class |
SshdSession.SshdExecProcess |
private class |
SshdSession.SshdFtpChannel |
Modifier and Type | Field and Description |
---|---|
private org.apache.sshd.client.SshClient |
client |
private java.util.concurrent.CopyOnWriteArrayList<SessionCloseListener> |
listeners |
private static org.slf4j.Logger |
LOG |
private org.apache.sshd.client.session.ClientSession |
session |
private URIish |
uri |
Constructor and Description |
---|
SshdSession(URIish uri,
java.util.function.Supplier<org.apache.sshd.client.SshClient> clientFactory) |
Modifier and Type | Method and Description |
---|---|
void |
addCloseListener(SessionCloseListener listener)
Adds a
SessionCloseListener to this session. |
(package private) void |
connect(java.time.Duration timeout) |
void |
disconnect()
Disconnect the remote session
|
private void |
disconnect(java.lang.Throwable reason) |
java.lang.Process |
exec(java.lang.String commandName,
int timeout)
Generate a new remote process to execute the given command.
|
FtpChannel |
getFtpChannel()
Obtain an
FtpChannel to perform SFTP operations in this
SshdSession . |
private void |
notifyCloseListeners() |
void |
removeCloseListener(SessionCloseListener listener)
Removes the given
listener ; has no effect if the listener is not
currently registered with this session. |
private static final org.slf4j.Logger LOG
private final java.util.concurrent.CopyOnWriteArrayList<SessionCloseListener> listeners
private final URIish uri
private org.apache.sshd.client.SshClient client
private org.apache.sshd.client.session.ClientSession session
SshdSession(URIish uri, java.util.function.Supplier<org.apache.sshd.client.SshClient> clientFactory)
void connect(java.time.Duration timeout) throws java.io.IOException
java.io.IOException
public void addCloseListener(@NonNull SessionCloseListener listener)
SessionCloseListener
to this session. Has no effect if the
given listener
is already registered with this session.listener
- to addpublic void removeCloseListener(@NonNull SessionCloseListener listener)
listener
; has no effect if the listener is not
currently registered with this session.listener
- to removeprivate void notifyCloseListeners()
public java.lang.Process exec(java.lang.String commandName, int timeout) throws java.io.IOException
RemoteSession
exec
in interface RemoteSession
commandName
- command to executetimeout
- timeout value, in seconds, for command executionjava.io.IOException
- may be thrown in several cases. For example, on problems
opening input or output streams or on problems connecting or
communicating with the remote host. For the latter two cases,
a TransportException may be thrown (a subclass of
java.io.IOException).@NonNull public FtpChannel getFtpChannel()
FtpChannel
to perform SFTP operations in this
SshdSession
.getFtpChannel
in interface RemoteSession
FtpChannel
public void disconnect()
RemoteSession
disconnect
in interface RemoteSession
private void disconnect(java.lang.Throwable reason)