| | |
| | | |
| | | public int read(ByteBuffer byteBuffer) throws IOException |
| | | { |
| | | return clientChannel.read(byteBuffer); |
| | | int bytesRead = clientChannel.read(byteBuffer); |
| | | if (bytesRead > 0 && keepStats) |
| | | { |
| | | statTracker.updateBytesRead(bytesRead); |
| | | } |
| | | return bytesRead; |
| | | } |
| | | |
| | | public boolean isOpen() |
| | |
| | | try |
| | | { |
| | | int bytesToWrite = byteBuffer.remaining(); |
| | | clientChannel.write(byteBuffer); |
| | | int bytesWritten = clientChannel.write(byteBuffer); |
| | | if (bytesWritten > 0 && keepStats) |
| | | { |
| | | statTracker.updateBytesWritten(bytesWritten); |
| | | } |
| | | if (!byteBuffer.hasRemaining()) |
| | | { |
| | | return bytesToWrite; |
| | |
| | | while (byteBuffer.hasRemaining() |
| | | && (System.currentTimeMillis() < stopTime)) |
| | | { |
| | | if (clientChannel.write(byteBuffer) < 0) |
| | | bytesWritten = clientChannel.write(byteBuffer); |
| | | if (bytesWritten < 0) |
| | | { |
| | | // The client connection has been closed. |
| | | throw new ClosedChannelException(); |
| | | } |
| | | if (bytesWritten > 0 && keepStats) |
| | | { |
| | | statTracker.updateBytesWritten(bytesWritten); |
| | | } |
| | | } |
| | | |
| | | if (byteBuffer.hasRemaining()) |
| | |
| | | SelectionKey k = iterator.next(); |
| | | if (k.isWritable()) |
| | | { |
| | | int bytesWritten = clientChannel.write(byteBuffer); |
| | | bytesWritten = clientChannel.write(byteBuffer); |
| | | if (bytesWritten < 0) |
| | | { |
| | | // The client connection has been closed. |
| | | throw new ClosedChannelException(); |
| | | } |
| | | if (bytesWritten > 0 && keepStats) |
| | | { |
| | | statTracker.updateBytesWritten(bytesWritten); |
| | | } |
| | | |
| | | iterator.remove(); |
| | | } |
| | |
| | | |
| | | if (keepStats) |
| | | { |
| | | // TODO hard-coded for now, flush probably needs to |
| | | // return how many bytes were flushed. |
| | | statTracker.updateMessageWritten(message, 4096); |
| | | statTracker.updateMessageWritten(message); |
| | | } |
| | | } |
| | | catch (Exception e) |