Java源码示例:org.apache.sshd.common.io.IoWriteFuture
示例1
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);
}
}
}
示例2
@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;
}
示例3
@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;
}
示例4
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);
}
}
}
示例5
@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;
}
示例6
@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;
}
示例7
@Override
public IoWriteFuture sendDebugMessage(boolean display, Object msg, String lang) throws IOException {
throw new RuntimeException("Not implemented");
}
示例8
@Override
public IoWriteFuture sendIgnoreMessage(byte... data) throws IOException {
throw new RuntimeException("Not implemented");
}
示例9
@Override
public IoWriteFuture writePacket(Buffer buffer) throws IOException {
throw new RuntimeException("Not implemented");
}
示例10
@Override
public IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException {
throw new RuntimeException("Not implemented");
}