Class SshSession
Encapsulates connect, command execution, bulk SCP transfer, SFTP metadata operations, and graceful shutdown,
exposing async methods returning CompletableFutures and routing connection/control,
transfer, and long-running command work to separate execution resources. Session state is protected by a short-held
lifecycle lock; network and file operations never execute while holding it.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA bounded operation performed against the remote Apache MINA SFTP file system. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSshSession(ConnectionConfig conn, ExecutorService executor) This Constructor initializes all values.SshSession(ConnectionConfig conn, ExecutorService executor, int diagnosticBytes) This constructor initializes all values with an explicit diagnostic limit.SshSession(ConnectionConfig conn, ExecutorService controlExecutor, ExecutorService transferExecutor, ExecutorService commandExecutor, int diagnosticBytes) This constructor assigns separate execution resources to control, transfer, and long-running commands.SshSession(ConnectionConfig conn, ExecutorService controlExecutor, ExecutorService transferExecutor, ExecutorService commandExecutor, int diagnosticBytes, int copyBufferBytes) This constructor assigns separate execution resources and an explicit SCP copy buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoidCancel all currently running operations without permanently closing this session.copyFileAsync(String srcPath, String dstPath, long timeoutSeconds) Copy one local file to an exact remote path with bulk SCP.copyFileAsync(String srcPath, String dstPath, long timeoutSeconds, LongConsumer copyProgress) Copy one local file to an exact remote path and report transferred bytes.createSessionAsync(long timeoutSeconds) This method Creates Sessions.Return the numeric controller address selected by the authenticated SSH route.Return the authenticated network endpoint used by this SSH session.runBenchmarkCommandAsync(String cmd, byte[] input, Boolean isOutput, long timeoutSeconds) Run a remote command that remains active for the duration of a benchmark on a virtual thread.runCommandAsync(String cmd, byte[] input, Boolean isOutput, long timeoutSeconds) Run a remote command with a binary stdin request.runCommandAsync(String cmd, Boolean isOutput, long timeoutSeconds) This method is responsible for running commands but throws ConnectException if it occurs.<T> CompletableFuture<T> runRemoteFileOperationAsync(SshSession.RemoteFileOperation<T> operation, long timeoutSeconds) Execute a remote file-system operation through Apache MINA SFTP.<T> CompletableFuture<T> runRemoteTransferOperationAsync(SshSession.RemoteFileOperation<T> operation, long timeoutSeconds) Execute deployment data movement through Apache MINA SFTP on the bounded transfer executor.voidstop()This method is responsible for closing session and stopping the client.
-
Field Details
-
connection
public SshConnection connection.
-
-
Constructor Details
-
SshSession
This Constructor initializes all values.- Parameters:
conn- SshConnectionexecutor- ExecutorService
-
SshSession
This constructor initializes all values with an explicit diagnostic limit.- Parameters:
conn- SSH connectionexecutor- orchestration executordiagnosticBytes- maximum stdout/stderr bytes retained per command
-
SshSession
public SshSession(ConnectionConfig conn, ExecutorService controlExecutor, ExecutorService transferExecutor, ExecutorService commandExecutor, int diagnosticBytes) This constructor assigns separate execution resources to control, transfer, and long-running commands.- Parameters:
conn- SSH connectioncontrolExecutor- bounded connection and control-operation executortransferExecutor- bounded deployment transfer executorcommandExecutor- virtual-thread executor for long-running remote commandsdiagnosticBytes- maximum stdout/stderr bytes retained per command
-
SshSession
public SshSession(ConnectionConfig conn, ExecutorService controlExecutor, ExecutorService transferExecutor, ExecutorService commandExecutor, int diagnosticBytes, int copyBufferBytes) This constructor assigns separate execution resources and an explicit SCP copy buffer.- Parameters:
conn- SSH connectioncontrolExecutor- bounded connection and control-operation executortransferExecutor- bounded deployment transfer executorcommandExecutor- virtual-thread executor for long-running remote commandsdiagnosticBytes- maximum stdout/stderr bytes retained per commandcopyBufferBytes- read buffer bytes used by each bulk SCP upload- Throws:
IllegalArgumentException- whencopyBufferBytesis not positive
-
-
Method Details
-
createSessionAsync
This method Creates Sessions.- Parameters:
timeoutSeconds- long- Returns:
- CompletableFuture
-
getRemoteEndpointIdentity
Return the authenticated network endpoint used by this SSH session.The numeric address lets orchestration collapse aliases such as
localhostand127.0.0.1before performing physical deployment work. The configured host name remains available throughconnectionfor user-facing diagnostics.- Returns:
- normalized numeric address, or the normalized endpoint text when unavailable
- Throws:
ConnectException- when the SSH session is unavailable
-
getLocalRouteAddress
Return the numeric controller address selected by the authenticated SSH route.This address is suitable for advertising controller services back to the same remote host and avoids depending on remote DNS resolution of the controller hostname.
- Returns:
- numeric local address of the SSH connection
- Throws:
ConnectException- when the SSH session is unavailable or has no resolved IP address
-
runCommandAsync
public CompletableFuture<SshResponse> runCommandAsync(String cmd, Boolean isOutput, long timeoutSeconds) throws ConnectException This method is responsible for running commands but throws ConnectException if it occurs.- Parameters:
cmd- StringisOutput- Is stdout output is requiredtimeoutSeconds- long- Returns:
- CompletableFuture
- Throws:
ConnectException- If connection exception occurs.
-
runCommandAsync
public CompletableFuture<SshResponse> runCommandAsync(String cmd, byte[] input, Boolean isOutput, long timeoutSeconds) throws ConnectException Run a remote command with a binary stdin request.- Parameters:
cmd- commandinput- command standard inputisOutput- whether output should be retainedtimeoutSeconds- command timeout- Returns:
- asynchronous response
- Throws:
ConnectException- when the SSH session is unavailable
-
runBenchmarkCommandAsync
public CompletableFuture<SshResponse> runBenchmarkCommandAsync(String cmd, byte[] input, Boolean isOutput, long timeoutSeconds) throws ConnectException Run a remote command that remains active for the duration of a benchmark on a virtual thread.- Parameters:
cmd- commandinput- command standard inputisOutput- whether output should be retainedtimeoutSeconds- command timeout- Returns:
- asynchronous response
- Throws:
ConnectException- when the SSH session is unavailable
-
copyFileAsync
public CompletableFuture<Void> copyFileAsync(String srcPath, String dstPath, long timeoutSeconds) throws ConnectException Copy one local file to an exact remote path with bulk SCP.- Parameters:
srcPath- local source filedstPath- remote destination filetimeoutSeconds- maximum copy duration in seconds- Returns:
- copy completion
- Throws:
ConnectException- when no SSH session is available
-
copyFileAsync
public CompletableFuture<Void> copyFileAsync(String srcPath, String dstPath, long timeoutSeconds, LongConsumer copyProgress) throws ConnectException Copy one local file to an exact remote path and report transferred bytes.- Parameters:
srcPath- local source filedstPath- remote destination filetimeoutSeconds- maximum copy duration in secondscopyProgress- callback receiving each completed byte increment- Returns:
- copy completion
- Throws:
ConnectException- when no SSH session is available
-
runRemoteFileOperationAsync
public <T> CompletableFuture<T> runRemoteFileOperationAsync(SshSession.RemoteFileOperation<T> operation, long timeoutSeconds) throws ConnectException Execute a remote file-system operation through Apache MINA SFTP.- Type Parameters:
T- result type- Parameters:
operation- remote file-system operationtimeoutSeconds- maximum operation duration- Returns:
- asynchronous operation result
- Throws:
ConnectException- when no SSH session is available
-
runRemoteTransferOperationAsync
public <T> CompletableFuture<T> runRemoteTransferOperationAsync(SshSession.RemoteFileOperation<T> operation, long timeoutSeconds) throws ConnectException Execute deployment data movement through Apache MINA SFTP on the bounded transfer executor.- Type Parameters:
T- result type- Parameters:
operation- remote file-system transfer operationtimeoutSeconds- maximum operation duration- Returns:
- asynchronous operation result
- Throws:
ConnectException- when no SSH session is available
-
cancelActiveOperations
public void cancelActiveOperations()Cancel all currently running operations without permanently closing this session. -
stop
public void stop()This method is responsible for closing session and stopping the client.
-