本文整理汇总了Java中com.trilead.ssh2.ChannelCondition类的典型用法代码示例。如果您正苦于以下问题:Java ChannelCondition类的具体用法?Java ChannelCondition怎么用?Java ChannelCondition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChannelCondition类属于com.trilead.ssh2包,在下文中一共展示了ChannelCondition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canEndTheSshConnectionTest
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
@Test
public void canEndTheSshConnectionTest() throws Exception {
PowerMockito.spy(SshHelper.class);
final Session mockedSession = Mockito.mock(Session.class);
PowerMockito.doReturn(true).when(SshHelper.class, "isChannelConditionEof", Mockito.anyInt());
Mockito.when(mockedSession.waitForCondition(ChannelCondition.EXIT_STATUS, 1l)).thenReturn(0);
PowerMockito.doNothing().when(SshHelper.class, "throwSshExceptionIfConditionsTimeout", Mockito.anyInt());
SshHelper.canEndTheSshConnection(1, mockedSession, 0);
PowerMockito.verifyStatic();
SshHelper.isChannelConditionEof(Mockito.anyInt());
SshHelper.throwSshExceptionIfConditionsTimeout(Mockito.anyInt());
Mockito.verify(mockedSession).waitForCondition(ChannelCondition.EXIT_STATUS, 1l);
}
示例2: getSessionOutcomeMessage
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
/**
* Find the exit code or exit status, which are differentiated in SSH protocol.
*/
private String getSessionOutcomeMessage(Session session, boolean isConnectionLost) throws InterruptedException {
session.waitForCondition(ChannelCondition.EXIT_STATUS | ChannelCondition.EXIT_SIGNAL, 3000);
Integer exitCode = session.getExitStatus();
if (exitCode != null)
return "Slave JVM has terminated. Exit code=" + exitCode;
String sig = session.getExitSignal();
if (sig != null)
return "Slave JVM has terminated. Exit signal=" + sig;
if (isConnectionLost)
return "Slave JVM has not reported exit code before the socket was lost";
return "Slave JVM has not reported exit code. Is it still running?";
}
示例3: canEndTheSshConnectionTest
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
@Test
public void canEndTheSshConnectionTest() throws Exception {
PowerMockito.spy(SshHelper.class);
Session mockedSession = Mockito.mock(Session.class);
PowerMockito.doReturn(true).when(SshHelper.class, "isChannelConditionEof", Mockito.anyInt());
Mockito.when(mockedSession.waitForCondition(ChannelCondition.EXIT_STATUS, 1l)).thenReturn(0);
PowerMockito.doNothing().when(SshHelper.class, "throwSshExceptionIfConditionsTimeout", Mockito.anyInt());
SshHelper.canEndTheSshConnection(1, mockedSession, 0);
PowerMockito.verifyStatic();
SshHelper.isChannelConditionEof(Mockito.anyInt());
SshHelper.throwSshExceptionIfConditionsTimeout(Mockito.anyInt());
Mockito.verify(mockedSession).waitForCondition(ChannelCondition.EXIT_STATUS, 1l);
}
示例4: read
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
@Override
public int read(byte[] buffer, int start, int len) throws IOException {
int bytesRead = 0;
if (session == null)
return 0;
int newConditions = session.waitForCondition(conditions, 0);
if ((newConditions & ChannelCondition.STDOUT_DATA) != 0) {
bytesRead = stdout.read(buffer, start, len);
}
if ((newConditions & ChannelCondition.STDERR_DATA) != 0) {
byte discard[] = new byte[256];
while (stderr.available() > 0) {
stderr.read(discard);
}
}
if ((newConditions & ChannelCondition.EOF) != 0) {
close();
onDisconnect();
throw new IOException("Remote end closed connection");
}
return bytesRead;
}
示例5: throwSshExceptionIfConditionsTimeout
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
/**
* It throws a {@link SshException} if the channel condition is {@link ChannelCondition#TIMEOUT}
*/
protected static void throwSshExceptionIfConditionsTimeout(final int conditions) throws SshException {
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
final String msg = "Timed out in waiting for SSH execution exit status";
s_logger.error(msg);
throw new SshException(msg);
}
}
示例6: canEndTheSshConnection
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
/**
* Handles the SSH connection in case of timeout or exit. If the session ends with a timeout
* condition, it throws an exception; if the channel reaches an end of file condition, but it
* does not have an exit status, it returns true to break the loop; otherwise, it returns
* false.
*/
protected static boolean canEndTheSshConnection(final int waitResultTimeoutInMs, final com.trilead.ssh2.Session sess, final int conditions) throws SshException {
if (isChannelConditionEof(conditions)) {
final int newConditions = sess.waitForCondition(ChannelCondition.EXIT_STATUS, waitResultTimeoutInMs);
throwSshExceptionIfConditionsTimeout(newConditions);
if ((newConditions & ChannelCondition.EXIT_STATUS) != 0) {
return true;
}
}
return false;
}
示例7: isChannelConditionEof
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
/**
* Checks if the channel condition mask is of {@link ChannelCondition#EOF} and not
* {@link ChannelCondition#STDERR_DATA} or {@link ChannelCondition#STDOUT_DATA}.
*/
protected static boolean isChannelConditionEof(final int conditions) {
if ((conditions & ChannelCondition.EOF) != 0) {
return true;
}
return false;
}
示例8: read
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
@Override
public int read(byte[] buffer, int start, int len) throws IOException {
int bytesRead = 0;
if (session == null)
return 0;
int newConditions = session.waitForCondition(conditions, 0);
if ((newConditions & ChannelCondition.STDOUT_DATA) != 0) {
bytesRead = stdout.read(buffer, start, len);
}
if ((newConditions & ChannelCondition.STDERR_DATA) != 0) {
byte discard[] = new byte[256];
while (stderr.available() > 0) {
stderr.read(discard);
}
}
if ((newConditions & ChannelCondition.EOF) != 0) {
onDisconnect();
throw new IOException("Remote end closed connection");
}
return bytesRead;
}
示例9: communicate
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
public static CommunicateResult communicate(Connection connection, Duration timeout, String... command) throws IOException {
checkNotNull(connection);
checkNotNull(timeout);
checkNotNull(command);
String commandString = quoteCommand(asList(command));
Session session = connection.openSession();
try {
session.execCommand(commandString);
StreamGobbler stderr = new StreamGobbler(session.getStderr());
StreamGobbler stdout = new StreamGobbler(session.getStdout());
try {
session.waitForCondition(ChannelCondition.EXIT_STATUS, timeout.getMillis());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return new CommunicateResult(
commandString,
readAll(stdout, Charsets.UTF_8),
readAll(stderr, Charsets.UTF_8),
firstNonNull(session.getExitStatus(), -1000)
);
} finally {
session.close();
}
}
示例10: canEndTheSshConnection
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
/**
* Handles the SSH connection in case of timeout or exit. If the session ends with a timeout
* condition, it throws an exception; if the channel reaches an end of file condition, but it
* does not have an exit status, it returns true to break the loop; otherwise, it returns
* false.
*/
protected static boolean canEndTheSshConnection(int waitResultTimeoutInMs, com.trilead.ssh2.Session sess, int conditions) throws SshException {
if (isChannelConditionEof(conditions)) {
int newConditions = sess.waitForCondition(ChannelCondition.EXIT_STATUS, waitResultTimeoutInMs);
throwSshExceptionIfConditionsTimeout(newConditions);
if ((newConditions & ChannelCondition.EXIT_STATUS) != 0) {
return true;
}
}
return false;
}
示例11: throwSshExceptionIfConditionsTimeout
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
/**
* It throws a {@link SshException} if the channel condition is {@link ChannelCondition#TIMEOUT}
*/
protected static void throwSshExceptionIfConditionsTimeout(int conditions) throws SshException {
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
String msg = "Timed out in waiting for SSH execution exit status";
s_logger.error(msg);
throw new SshException(msg);
}
}
示例12: isChannelConditionEof
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
/**
* Checks if the channel condition mask is of {@link ChannelCondition#EOF} and not
* {@link ChannelCondition#STDERR_DATA} or {@link ChannelCondition#STDOUT_DATA}.
*/
protected static boolean isChannelConditionEof(int conditions) {
if ((conditions & ChannelCondition.EOF) != 0) {
return true;
}
return false;
}
示例13: close
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
public void close() throws IOException {
this.flush();
this.session.waitForCondition(ChannelCondition.EOF, 1);
/* Now its hopefully safe to close the session */
this.session.close();
// Socket::close()
this.unused = true;
}
示例14: throwSshExceptionIfConditionsTimeout
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
@Test(expected = SshException.class)
public void throwSshExceptionIfConditionsTimeout() throws SshException {
SshHelper.throwSshExceptionIfConditionsTimeout(ChannelCondition.TIMEOUT);
}
示例15: doNotThrowSshExceptionIfConditionsClosed
import com.trilead.ssh2.ChannelCondition; //导入依赖的package包/类
@Test
public void doNotThrowSshExceptionIfConditionsClosed() throws SshException {
SshHelper.throwSshExceptionIfConditionsTimeout(ChannelCondition.CLOSED);
}