org.apache.sshd.common.io.IoWriteFuture Java Examples

The following examples show how to use org.apache.sshd.common.io.IoWriteFuture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowAdjustTest.java    From termd with Apache License 2.0 6 votes vote down vote up
private void writeWithPendingDetection(final Buffer msg, final boolean wasPending) {
    try {
        asyncIn.write(msg).addListener(new SshFutureListener<IoWriteFuture>() {
            @SuppressWarnings("synthetic-access")
            @Override
            public void operationComplete(IoWriteFuture future) {
                if (future.isWritten()) {
                    if (wasPending) {
                        pending.remove();
                    }
                    writePendingIfAny();
                } else {
                    Throwable t = future.getException();
                    log.warn("Failed to write message", t);
                }
            }
        });
    } catch (final WritePendingException e) {
        if (!wasPending) {
            queueRequest(msg);
        }
    }
}
 
Example #2
Source File: NettyIoSession.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Override
public IoWriteFuture write(Buffer buffer) {
    ByteBuf buf = Unpooled.buffer(buffer.available());
    buf.writeBytes(buffer.array(), buffer.rpos(), buffer.available());
    NettyIoWriteFuture msg = new NettyIoWriteFuture();
    ChannelPromise next = context.newPromise();
    prev.addListener(whatever -> {
        if (context != null) {
            context.writeAndFlush(buf, next);
        }
    });
    prev = next;
    next.addListener(fut -> {
        if (fut.isSuccess()) {
            msg.setValue(Boolean.TRUE);
        } else {
            msg.setValue(fut.cause());
        }
    });
    return msg;
}
 
Example #3
Source File: NettyIoSession.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
public IoWriteFuture write(Buffer buffer) {
  ByteBuf buf = Unpooled.buffer(buffer.available());
  buf.writeBytes(buffer.array(), buffer.rpos(), buffer.available());
  NettyIoWriteFuture msg = new NettyIoWriteFuture();
  ChannelPromise next = context.newPromise();
  prev.addListener(whatever -> {
    if (context != null) {
      context.writeAndFlush(buf, next);
    }
  });
  prev = next;
  next.addListener(fut -> {
    if (fut.isSuccess()) {
      msg.setValue(Boolean.TRUE);
    } else {
      msg.setValue(fut.cause());
    }
  });
  return msg;
}
 
Example #4
Source File: WindowAdjustTest.java    From termd with Apache License 2.0 6 votes vote down vote up
private void writeWithPendingDetection(final Buffer msg, final boolean wasPending) {
    try {
        asyncIn.write(msg).addListener(new SshFutureListener<IoWriteFuture>() {
            @SuppressWarnings("synthetic-access")
            @Override
            public void operationComplete(IoWriteFuture future) {
                if (future.isWritten()) {
                    if (wasPending) {
                        pending.remove();
                    }
                    writePendingIfAny();
                } else {
                    Throwable t = future.getException();
                    log.warn("Failed to write message", t);
                }
            }
        });
    } catch (final WritePendingException e) {
        if (!wasPending) {
            queueRequest(msg);
        }
    }
}
 
Example #5
Source File: AsyncEchoShellFactory.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public int data(final ChannelSession channel, byte[] buf, int start, int len) throws IOException {
    buffer.append(new String(buf, start, len));
    for (int i = 0; i < buffer.length(); i++) {
        if (buffer.charAt(i) == '\n') {
            final String s = buffer.substring(0, i + 1);
            final byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
            out.write(new ByteArrayBuffer(bytes)).addListener(new SshFutureListener<IoWriteFuture>() {
                @Override
                public void operationComplete(IoWriteFuture future) {
                    Session session = channel.getSession();
                    if (future.isWritten()) {
                        try {
                            Window wLocal = channel.getLocalWindow();
                            wLocal.consumeAndCheck(bytes.length);
                        } catch (IOException e) {
                            session.exceptionCaught(e);
                        }
                    } else {
                        Throwable t = future.getException();
                        session.exceptionCaught(t);
                    }
                }
            });
            buffer = new StringBuilder(buffer.substring(i + 1));
            i = 0;
        }
    }
    return 0;
}
 
Example #6
Source File: AsyncEchoShellFactory.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public int data(final ChannelSession channel, byte[] buf, int start, int len) throws IOException {
    buffer.append(new String(buf, start, len));
    for (int i = 0; i < buffer.length(); i++) {
        if (buffer.charAt(i) == '\n') {
            final String s = buffer.substring(0, i + 1);
            final byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
            out.write(new ByteArrayBuffer(bytes)).addListener(new SshFutureListener<IoWriteFuture>() {
                @Override
                public void operationComplete(IoWriteFuture future) {
                    Session session = channel.getSession();
                    if (future.isWritten()) {
                        try {
                            Window wLocal = channel.getLocalWindow();
                            wLocal.consumeAndCheck(bytes.length);
                        } catch (IOException e) {
                            session.exceptionCaught(e);
                        }
                    } else {
                        Throwable t = future.getException();
                        session.exceptionCaught(t);
                    }
                }
            });
            buffer = new StringBuilder(buffer.substring(i + 1));
            i = 0;
        }
    }
    return 0;
}
 
Example #7
Source File: MockClientSession.java    From xenon with Apache License 2.0 4 votes vote down vote up
@Override
public IoWriteFuture sendDebugMessage(boolean display, Object msg, String lang) throws IOException {
    throw new RuntimeException("Not implemented");
}
 
Example #8
Source File: MockClientSession.java    From xenon with Apache License 2.0 4 votes vote down vote up
@Override
public IoWriteFuture sendIgnoreMessage(byte... data) throws IOException {
    throw new RuntimeException("Not implemented");
}
 
Example #9
Source File: MockClientSession.java    From xenon with Apache License 2.0 4 votes vote down vote up
@Override
public IoWriteFuture writePacket(Buffer buffer) throws IOException {
    throw new RuntimeException("Not implemented");
}
 
Example #10
Source File: MockClientSession.java    From xenon with Apache License 2.0 4 votes vote down vote up
@Override
public IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException {
    throw new RuntimeException("Not implemented");
}