private void handleReadTimeout(final long ret) throws IOException { if (!connection.isOpen()) { cleanup(); return; } if(ret == -1) { cleanup(); return; } if (ret == 0 && handle != null) { return; } Integer timeout = getTimeout(); if (timeout == null || timeout <= 0) { return; } long currentTime = System.currentTimeMillis(); long expireTimeVar = expireTime; if (expireTimeVar != -1 && currentTime > expireTimeVar) { IoUtils.safeClose(connection); throw new ClosedChannelException(); } expireTime = currentTime + timeout; }
@Override public long transferTo(final long position, final long count, final FileChannel target) throws IOException { long ret = super.transferTo(position, count, target); handleReadTimeout(ret); return ret; }
@Override public void wakeupReads() { super.wakeupReads(); handleResumeTimeout(); }
channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
@Override public void awaitReadable(long time, TimeUnit timeUnit) throws IOException { Integer timeout = getTimeout(); if (timeout != null && timeout > 0) { long millis = timeUnit.toMillis(time); super.awaitReadable(Math.min(millis, timeout + FUZZ_FACTOR), TimeUnit.MILLISECONDS); } else { super.awaitReadable(time, timeUnit); } }
@Override public void terminateReads() throws IOException { super.terminateReads(); cleanup(); }
channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
private void handleResumeTimeout() { Integer timeout = getTimeout(); if (timeout == null || timeout <= 0) { return; } long currentTime = System.currentTimeMillis(); expireTime = currentTime + timeout; XnioExecutor.Key key = handle; if (key == null) { handle = connection.getIoThread().executeAfter(timeoutCommand, timeout, TimeUnit.MILLISECONDS); } } }
@Override public void terminateReads() throws IOException { super.terminateReads(); cleanup(); }
channel.getSourceChannel() .setConduit( new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
@Override public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException { long ret = super.transferTo(count, throughBuffer, target); handleReadTimeout(ret); return ret; }
private void handleReadTimeout(final long ret) throws IOException { if (!connection.isOpen()) { cleanup(); return; } if(ret == -1) { cleanup(); return; } if (ret == 0 && handle != null) { return; } Integer timeout = getTimeout(); if (timeout == null || timeout <= 0) { return; } long currentTime = System.currentTimeMillis(); long expireTimeVar = expireTime; if (expireTimeVar != -1 && currentTime > expireTimeVar) { IoUtils.safeClose(connection); throw new ClosedChannelException(); } expireTime = currentTime + timeout; }
@Override public void awaitReadable() throws IOException { Integer timeout = getTimeout(); if (timeout != null && timeout > 0) { super.awaitReadable(timeout + FUZZ_FACTOR, TimeUnit.MILLISECONDS); } else { super.awaitReadable(); } }
@Override public void resumeReads() { super.resumeReads(); handleResumeTimeout(); }
@Override public void terminateReads() throws IOException { super.terminateReads(); cleanup(); }
channel.getSourceChannel() .setConduit( new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
@Override public long read(final ByteBuffer[] dsts, final int offset, final int length) throws IOException { long ret = super.read(dsts, offset, length); handleReadTimeout(ret); return ret; }
private void handleReadTimeout(final long ret) throws IOException { if (!connection.isOpen()) { cleanup(); return; } if(ret == -1) { cleanup(); return; } if (ret == 0 && handle != null) { return; } Integer timeout = getTimeout(); if (timeout == null || timeout <= 0) { return; } long currentTime = System.currentTimeMillis(); long expireTimeVar = expireTime; if (expireTimeVar != -1 && currentTime > expireTimeVar) { IoUtils.safeClose(connection); throw new ClosedChannelException(); } expireTime = currentTime + timeout; }
@Override public void awaitReadable(long time, TimeUnit timeUnit) throws IOException { Integer timeout = getTimeout(); if (timeout != null && timeout > 0) { long millis = timeUnit.toMillis(time); super.awaitReadable(Math.min(millis, timeout + FUZZ_FACTOR), TimeUnit.MILLISECONDS); } else { super.awaitReadable(time, timeUnit); } }
@Override public void resumeReads() { super.resumeReads(); handleResumeTimeout(); }