java.nio.channels.InterruptedByTimeoutException Java Examples
The following examples show how to use
java.nio.channels.InterruptedByTimeoutException.
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: AsynchronousTlsChannelGroup.java From pgadba with BSD 2-Clause "Simplified" License | 5 votes |
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; }
Example #2
Source File: AsynchronousTlsChannelGroup.java From pgadba with BSD 2-Clause "Simplified" License | 5 votes |
WriteOperation startWrite( RegisteredSocket socket, ByteBufferSet buffer, long timeout, TimeUnit unit, LongConsumer onSuccess, Consumer<Throwable> onFailure) throws WritePendingException { checkTerminated(); Util.assertTrue(buffer.hasRemaining()); waitForSocketRegistration(socket); WriteOperation op; socket.writeLock.lock(); try { if (socket.writeOperation != null) { throw new WritePendingException(); } op = new WriteOperation(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 = doCancelWrite(socket, op); if (success) { op.onFailure.accept(new InterruptedByTimeoutException()); } }, timeout, unit); } socket.writeOperation = op; } finally { socket.writeLock.unlock(); } selector.wakeup(); startedWrites.increment(); currentWrites.increment(); return op; }
Example #3
Source File: InterruptedByTimeoutExceptionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.nio.channels.InterruptedByTimeoutException#InterruptedByTimeoutException() */ public void test_empty() { InterruptedByTimeoutException e = new InterruptedByTimeoutException(); assertTrue(e instanceof IOException); assertNull(e.getMessage()); assertNull(e.getLocalizedMessage()); assertNull(e.getCause()); }
Example #4
Source File: AsynchronousTlsChannelGroup.java From tls-channel with MIT License | 4 votes |
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; }
Example #5
Source File: AsynchronousTlsChannelGroup.java From tls-channel with MIT License | 4 votes |
WriteOperation startWrite( RegisteredSocket socket, ByteBufferSet buffer, long timeout, TimeUnit unit, LongConsumer onSuccess, Consumer<Throwable> onFailure) throws WritePendingException { checkTerminated(); Util.assertTrue(buffer.hasRemaining()); waitForSocketRegistration(socket); WriteOperation op; socket.writeLock.lock(); try { if (socket.writeOperation != null) { throw new WritePendingException(); } op = new WriteOperation(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 = doCancelWrite(socket, op); if (success) { op.onFailure.accept(new InterruptedByTimeoutException()); } }, timeout, unit); } socket.writeOperation = op; } finally { socket.writeLock.unlock(); } selector.wakeup(); startedWrites.increment(); currentWrites.increment(); return op; }