Add a timed join() method to Channel, update Exec example

This commit is contained in:
Shikhar Bhushan
2011-02-12 20:23:58 +00:00
parent 75caa8bcf3
commit da2cec8fa2
3 changed files with 11 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/** This examples demonstrates how a remote command can be executed. */
public class Exec {
@@ -36,6 +37,7 @@ public class Exec {
try {
final Command cmd = session.exec("ping -c 1 google.com");
System.out.print(cmd.getOutputAsString());
cmd.join(5, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();

View File

@@ -272,6 +272,11 @@ public abstract class AbstractChannel
close.await();
}
public void join(int timeout, TimeUnit unit)
throws ConnectionException {
close.await(timeout, unit);
}
protected synchronized void sendClose()
throws TransportException {
try {

View File

@@ -23,6 +23,7 @@ import net.schmizz.sshj.transport.TransportException;
import java.io.Closeable;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.TimeUnit;
/** A channel is the basic medium for application-layer data on top of an SSH transport. */
public interface Channel
@@ -138,4 +139,7 @@ public interface Channel
void join()
throws ConnectionException;
void join(int timeout, TimeUnit unit)
throws ConnectionException;
}