下面列出了怎么用java.nio.channels.ReadPendingException的API类实例代码及写法,或者点击链接到github查看源代码。
ReadOperation startRead(
RegisteredSocket socket,
ByteBufferSet buffer,
long timeout, TimeUnit unit,
LongConsumer onSuccess, Consumer<Throwable> onFailure)
throws ReadPendingException {
checkTerminated();
Util.assertTrue(buffer.hasRemaining());
waitForSocketRegistration(socket);
ReadOperation op;
socket.readLock.lock();
try {
if (socket.readOperation != null) {
throw new ReadPendingException();
}
op = new ReadOperation(buffer, onSuccess, onFailure);
/*
* we do not try to outsmart the TLS state machine and register for both IO operations for each new socket
* operation
*/
socket.pendingOps.set(SelectionKey.OP_WRITE | SelectionKey.OP_READ);
if (timeout != 0) {
op.timeoutFuture = timeoutExecutor.schedule(() -> {
boolean success = doCancelRead(socket, op);
if (success) {
op.onFailure.accept(new InterruptedByTimeoutException());
}
}, timeout, unit);
}
socket.readOperation = op;
} finally {
socket.readLock.unlock();
}
selector.wakeup();
startedReads.increment();
currentReads.increment();
return op;
}
/**
* java.nio.channels.ReadPendingException#ReadPendingException()
*/
public void test_empty() {
ReadPendingException e = new ReadPendingException();
assertTrue(e instanceof IllegalStateException);
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
@Override
public void fillInterested(final Callback callback) throws ReadPendingException
{
_underlying.fillInterested(callback);
}
ReadOperation startRead(
RegisteredSocket socket,
ByteBufferSet buffer,
long timeout,
TimeUnit unit,
LongConsumer onSuccess,
Consumer<Throwable> onFailure)
throws ReadPendingException {
checkTerminated();
Util.assertTrue(buffer.hasRemaining());
waitForSocketRegistration(socket);
ReadOperation op;
socket.readLock.lock();
try {
if (socket.readOperation != null) {
throw new ReadPendingException();
}
op = new ReadOperation(buffer, onSuccess, onFailure);
/*
* we do not try to outsmart the TLS state machine and register for both IO operations for each new socket
* operation
*/
socket.pendingOps.set(SelectionKey.OP_WRITE | SelectionKey.OP_READ);
if (timeout != 0) {
op.timeoutFuture =
timeoutExecutor.schedule(
() -> {
boolean success = doCancelRead(socket, op);
if (success) {
op.onFailure.accept(new InterruptedByTimeoutException());
}
},
timeout,
unit);
}
socket.readOperation = op;
} finally {
socket.readLock.unlock();
}
selector.wakeup();
startedReads.increment();
currentReads.increment();
return op;
}