mirror of https://github.com/apache/jclouds.git
Close connection during ExecChannel
This commit is contained in:
parent
502d96d22b
commit
060b66a4f7
|
@ -48,9 +48,7 @@ public interface SshClient {
|
|||
ExecResponse exec(String command);
|
||||
|
||||
/**
|
||||
* Execute a process and allow the user to interact with it. Note that this will allow the
|
||||
* session to exist indefinitely, and its connection is not closed when {@link #disconnect()} is
|
||||
* called.
|
||||
* Execute a process and allow the user to interact with it.
|
||||
*
|
||||
* @param command
|
||||
* command line to invoke
|
||||
|
|
|
@ -511,8 +511,8 @@ public class SshjSshClient implements SshClient {
|
|||
|
||||
class ExecChannelConnection implements Connection<ExecChannel> {
|
||||
private final String command;
|
||||
private SessionChannel session;
|
||||
private Command output;
|
||||
private Connection<Session> connection;
|
||||
|
||||
ExecChannelConnection(String command) {
|
||||
this.command = checkNotNull(command, "command");
|
||||
|
@ -521,13 +521,19 @@ public class SshjSshClient implements SshClient {
|
|||
@Override
|
||||
public void clear() {
|
||||
Closeables2.closeQuietly(output);
|
||||
Closeables2.closeQuietly(session);
|
||||
try {
|
||||
if (connection != null) {
|
||||
connection.clear();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecChannel create() throws Exception {
|
||||
session = SessionChannel.class.cast(acquire(noPTYConnection()));
|
||||
output = session.exec(command);
|
||||
connection = noPTYConnection();
|
||||
output = SessionChannel.class.cast(acquire(connection)).exec(command);
|
||||
return new ExecChannel(output.getOutputStream(), output.getInputStream(), output.getErrorStream(),
|
||||
new Supplier<Integer>() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue