Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.logging.Level;
Expand Down Expand Up @@ -167,9 +168,9 @@ public final void receive(@NonNull ByteBuffer data) throws IOException, Interrup
} else {
readCommandSizes[readCommandIndex] += readFrameRemaining;
int oldLimit = data.limit();
data.limit(data.position() + readFrameRemaining);
((Buffer) data).limit(data.position() + readFrameRemaining);
receiveQueue.put(data);
data.limit(oldLimit);
((Buffer) data).limit(oldLimit);
readFrameRemaining = 0;
if (ChunkHeader.isLast(readFrameHeader)) {
readState = READ_STATE_COMMAND_READY;
Expand Down Expand Up @@ -292,13 +293,13 @@ public final void write(Command cmd, boolean last) throws IOException {
int frame = remaining > transportFrameSize
? transportFrameSize
: (int) remaining; // # of bytes we send in this chunk
writeChunkHeader.clear();
((Buffer) writeChunkHeader).clear();
ChunkHeader.write(writeChunkHeader, frame, remaining > transportFrameSize);
writeChunkHeader.flip();
writeChunkBody.clear();
writeChunkBody.limit(frame);
((Buffer) writeChunkHeader).flip();
((Buffer) writeChunkBody).clear();
((Buffer) writeChunkBody).limit(frame);
sendStaging.get(writeChunkBody);
writeChunkBody.flip();
((Buffer) writeChunkBody).flip();
write(writeChunkHeader, writeChunkBody);
remaining -= frame;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.OverrideMustInvoke;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.LogRecord;
Expand Down Expand Up @@ -215,9 +216,9 @@ protected final void flushRecv(ByteBufferQueue queue) throws IOException {
}
ByteBuffer tmp = queue.newByteBuffer();
while (queue.hasRemaining()) {
tmp.clear();
((Buffer) tmp).clear();
queue.get(tmp);
tmp.flip();
((Buffer) tmp).flip();
try {
ptr.onRecv(tmp);
} catch (IOException e) {
Expand Down Expand Up @@ -246,9 +247,9 @@ protected final void flushSend(ByteBufferQueue queue) throws IOException {
}
ByteBuffer tmp = queue.newByteBuffer();
while (queue.hasRemaining()) {
tmp.clear();
((Buffer) tmp).clear();
queue.get(tmp);
tmp.flip();
((Buffer) tmp).flip();
try {
ptr.doSend(tmp);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.OverrideMustInvoke;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.util.logging.Level;
Expand Down Expand Up @@ -187,9 +188,9 @@ private void flushRecvQueue() throws IOException {
}
ByteBuffer tmp = recvQueue.newByteBuffer();
while (recvQueue.hasRemaining()) {
tmp.clear();
((Buffer) tmp).clear();
recvQueue.get(tmp);
tmp.flip();
((Buffer) tmp).flip();
ptr.onRecv(tmp);
}
recvQueue = null;
Expand All @@ -206,9 +207,9 @@ private void flushSendQueue() throws IOException {
}
ByteBuffer tmp = sendQueue.newByteBuffer();
while (sendQueue.hasRemaining()) {
tmp.clear();
((Buffer) tmp).clear();
sendQueue.get(tmp);
tmp.flip();
((Buffer) tmp).flip();
while (tmp.hasRemaining()) {
try {
write(tmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.concurrent.Future;
import java.util.logging.Level;
Expand Down Expand Up @@ -105,8 +106,8 @@ public AckFilterLayer(String ack) {

private static String toHexString(ByteBuffer buffer) {
ByteBuffer expectAck = buffer.duplicate();
expectAck.position(0);
expectAck.limit(buffer.position());
((Buffer) expectAck).position(0);
((Buffer) expectAck).limit(buffer.position());
StringBuilder expectHex = new StringBuilder(expectAck.remaining() * 2);
while (expectAck.hasRemaining()) {
int b = expectAck.get() & 0xff;
Expand Down Expand Up @@ -139,8 +140,8 @@ private boolean receivedAck() {
}
ByteBuffer expectAck = sendAck.duplicate();
ByteBuffer actualAck = recvAck.duplicate();
expectAck.rewind();
actualAck.rewind();
((Buffer) expectAck).rewind();
((Buffer) actualAck).rewind();
receivedAck = expectAck.equals(actualAck);
return receivedAck;
}
Expand All @@ -151,10 +152,10 @@ private boolean receivedPartialAck() {
}
ByteBuffer expectAck = sendAck.duplicate();
ByteBuffer actualAck = recvAck.duplicate();
expectAck.position(0);
expectAck.limit(sendAck.position());
actualAck.position(0);
actualAck.limit(recvAck.position());
((Buffer) expectAck).position(0);
((Buffer) expectAck).limit(sendAck.position());
((Buffer) actualAck).position(0);
((Buffer) actualAck).limit(recvAck.position());
while (expectAck.hasRemaining() && actualAck.hasRemaining()) {
byte e = expectAck.get();
byte a = actualAck.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.jenkinsci.remoting.protocol.impl;

import java.net.SocketTimeoutException;
import java.nio.Buffer;
import java.util.logging.LogRecord;
import java.io.EOFException;
import java.io.IOException;
Expand Down Expand Up @@ -189,12 +190,12 @@ public synchronized void run() {
try {
boolean done = false;
while (getIoHub().isOpen() && out.isOpen() && !done) {
data.clear();
((Buffer) data).clear();
synchronized (writeQueue) {
writeQueue.get(data);
done = !writeQueue.hasRemaining();
}
data.flip();
((Buffer) data).flip();
while (data.remaining() > 0) {
try {
if (out.write(data) == -1) {
Expand Down Expand Up @@ -282,7 +283,7 @@ public void run() {
onRecvClosed();
return;
}
buffer.flip();
((Buffer) buffer).flip();
if (buffer.hasRemaining() && LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "[{0}] RECV: {1} bytes",
new Object[]{stack().name(), buffer.remaining()});
Expand All @@ -295,7 +296,7 @@ public void run() {
return;
}
}
buffer.clear();
((Buffer) buffer).clear();
}
} finally {
release(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.ObjectOutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -157,7 +158,7 @@ public void onRead(@NonNull ByteBuffer data) throws IOException {
return;
}
byte[] capabilityBytes = new byte[capabilityContent.capacity()];
capabilityContent.flip();
((Buffer) capabilityContent).flip();
capabilityContent.get(capabilityBytes);
if (capabilityContent.hasRemaining()) {
return;
Expand Down Expand Up @@ -200,12 +201,12 @@ public void onRead(@NonNull ByteBuffer data) throws IOException {
} catch (InterruptedException e) {
InterruptedIOException ie = new InterruptedIOException();
ie.bytesTransferred = data.remaining();
data.position(data.limit());
((Buffer) data).position(data.limit());
Thread.currentThread().interrupt();
throw ie;
} catch (ExecutionException e) {
// should never get here as futureChannel.isDone(), but just in case we do throw away
data.position(data.limit()); // dump any remaining data as nobody will ever receive it
((Buffer) data).position(data.limit()); // dump any remaining data as nobody will ever receive it
throw new IOException(e);
}
}
Expand All @@ -214,15 +215,15 @@ public void onRead(@NonNull ByteBuffer data) throws IOException {
transport.receive(data);
} catch (IOException e) {
channel.terminate(e); // we are done if there is an I/O error
data.position(data.limit()); // dump any remaining data as nobody will ever receive it
((Buffer) data).position(data.limit()); // dump any remaining data as nobody will ever receive it
throw e;
} catch (InterruptedException e) {
// if the channel receive was interrupted we cannot guarantee that the partial state has been correctly
// stored, thus we cannot trust the channel instance any more and it needs to be closed.
InterruptedIOException reason = new InterruptedIOException();
reason.bytesTransferred = data.remaining();
channel.terminate(reason);
data.position(data.limit()); // dump any remaining data as nobody will ever receive it
((Buffer) data).position(data.limit()); // dump any remaining data as nobody will ever receive it
Thread.currentThread().interrupt();
throw reason;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.jenkinsci.remoting.protocol.impl;

import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -159,9 +160,9 @@ public void onRecv(@NonNull ByteBuffer data) throws IOException {
}
return;
}
headerInputLength.flip();
((Buffer) headerInputLength).flip();
int length = this.headerInputLength.asShortBuffer().get() & 0xffff;
headerInputLength.position(2);
((Buffer) headerInputLength).position(2);
headerInputContent = ByteBuffer.allocate(length);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "[{0}] Expecting {1} bytes of headers",
Expand All @@ -182,7 +183,7 @@ public void onRecv(@NonNull ByteBuffer data) throws IOException {
return;
}
byte[] headerBytes = new byte[headerInputContent.capacity()];
headerInputContent.flip();
((Buffer) headerInputContent).flip();
headerInputContent.get(headerBytes, 0, headerInputContent.remaining());
final String headerAsString = new String(headerBytes, StandardCharsets.UTF_8);
if (LOGGER.isLoggable(Level.FINER)) {
Expand Down Expand Up @@ -275,9 +276,9 @@ public void onRecv(@NonNull ByteBuffer data) throws IOException {
if (responseInputLength.hasRemaining()) {
return;
}
this.responseInputLength.flip();
((Buffer) this.responseInputLength).flip();
int length = this.responseInputLength.asShortBuffer().get() & 0xffff;
this.responseInputLength.position(2);
((Buffer) this.responseInputLength).position(2);
responseInputContent = ByteBuffer.allocate(length);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "[{0}] Expecting {1} bytes of response",
Expand All @@ -298,7 +299,7 @@ public void onRecv(@NonNull ByteBuffer data) throws IOException {
return;
}
byte[] responseBytes = new byte[responseInputContent.capacity()];
responseInputContent.flip();
((Buffer) responseInputContent).flip();
responseInputContent.get(responseBytes, 0, responseInputContent.remaining());
String response = new String(responseBytes, StandardCharsets.UTF_8);
if (LOGGER.isLoggable(Level.FINE)) {
Expand Down Expand Up @@ -488,7 +489,7 @@ public void doSend(@NonNull ByteBuffer data) throws IOException {
}
if (abortCause != null) {
// throw on the floor
data.clear();
((Buffer) data).clear();
} else if (finished) {
// we can just send through
if (sendQueue.hasRemaining()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jenkinsci.remoting.protocol.NetworkLayer;
import org.jenkinsci.remoting.util.ByteBufferQueue;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ReadableByteChannel;
Expand Down Expand Up @@ -151,7 +152,7 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write)
}
break READ;
default:
recv.flip();
((Buffer) recv).flip();
if (logFinest) {
LOGGER.log(Level.FINEST, "[{0}] RECV: {1} bytes",
new Object[]{stack().name(), recv.remaining()});
Expand All @@ -160,7 +161,7 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write)
onRead(recv);
}
// it's always clear when we get from acquire, so clear again for re-use
recv.clear();
((Buffer) recv).clear();
break;
}
}
Expand Down Expand Up @@ -215,7 +216,7 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write)
LOGGER.log(Level.FINEST, "[{0}] sendHasRemaining - has remaining: {1}",
new Object[] { Thread.currentThread().getName(), sendHasRemaining });
}
send.flip();
((Buffer) send).flip();
try {
final int sentBytes = out.write(send);
if (LOGGER.isLoggable(Level.FINEST)) {
Expand Down
Loading