Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9936df1
Add mark&reset methods and canUseByteBuffer&getByteBuffer methods to …
voidzcy Aug 17, 2020
aa93e1d
Default implementations.
voidzcy Aug 17, 2020
454e224
Wire new methods for forwarder
voidzcy Aug 17, 2020
3f47d5e
Support mark&reset and retrieving content via ByteBuffer for netty.
voidzcy Aug 17, 2020
b3c9974
Implementation for composite.
voidzcy Aug 17, 2020
2ede525
Define interface for accessing readable content via ByteBuffers.
voidzcy Aug 17, 2020
3dca312
Implement mark&reset for simple readable buffers.
voidzcy Aug 17, 2020
6249353
Use HasByteBuffer interface for accesing input stream's backing ByteB…
voidzcy Aug 17, 2020
29dce67
Eliminate the length argument for retrieving the ByteBuffer.
voidzcy Aug 17, 2020
22ea6c3
Do no require netty buffer to be direct from API's perspective.
voidzcy Aug 17, 2020
53e347c
Use Deque operations to avoid unncessary moves.
voidzcy Aug 17, 2020
27801fe
Make a list of ByteBuffers up-front instead of a running iterator.
voidzcy Aug 17, 2020
eb71a68
Add getByteBufferSupported method for HasByteBuffer so that it can be…
voidzcy Aug 17, 2020
5d3c657
It's not necessary to implement getByteBuffer for ByteReadbaleBufferW…
voidzcy Aug 17, 2020
9fd8d3c
Add test coverage for mark&reset and getByteBuffer for generic ByteBu…
voidzcy Aug 17, 2020
e3afe50
Add test coverage for netty's special get NIO bytebuffer operation.
voidzcy Aug 17, 2020
e2fdd07
Skip test for operations not supported by okhttp.
voidzcy Aug 17, 2020
033270b
Add test coverage for BufferInputStream with getByteBuffer operation.
voidzcy Aug 17, 2020
0622d51
Add test using a known-length input stream with getByteBuffer operati…
voidzcy Aug 17, 2020
0e8caee
Modify test method name.
voidzcy Aug 17, 2020
ba4e91b
Add test coverage for mark&reset and getByteBuffer for CompositeReada…
voidzcy Aug 17, 2020
69618b2
Add getByteBuffer support for ByteReadableBufferWrapper.
voidzcy Aug 20, 2020
437857d
Only pull ByteBuffers when message is large.
voidzcy Aug 21, 2020
1363505
Run ByteBuffer codepath only in Java 9+.
voidzcy Aug 28, 2020
c46eb73
Slight improvement for avoiding array creation if not necessary.
voidzcy Aug 28, 2020
7b4e070
Merge branch 'master' of github.com:grpc/grpc-java into impl/zero_cop…
voidzcy Aug 28, 2020
772b3ba
Change ReadableBuffer#canUseByteBuffer to hasByteBuffer.
voidzcy Sep 1, 2020
b1c99e5
Removed unnecessary reset.
voidzcy Sep 1, 2020
692076c
Simplify checking runtime java version.
voidzcy Sep 1, 2020
10c13b8
Add ExperimentalApi annotation.
voidzcy Sep 1, 2020
f13c165
Rename ReadableBuffer#hasByteBuffer to getByteBufferSupported.
voidzcy Sep 2, 2020
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
Prev Previous commit
Next Next commit
Change ReadableBuffer#canUseByteBuffer to hasByteBuffer.
  • Loading branch information
voidzcy committed Sep 1, 2020
commit 772b3bafdf98db2cc338a3acde17c8d3116bab6e
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void reset() {
}

@Override
public boolean canUseByteBuffer() {
public boolean hasByteBuffer() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ public void reset() {
}

@Override
public boolean canUseByteBuffer() {
public boolean hasByteBuffer() {
for (ReadableBuffer buffer : readableBuffers) {
if (!buffer.canUseByteBuffer()) {
if (!buffer.hasByteBuffer()) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void reset() {
}

@Override
public boolean canUseByteBuffer() {
return buf.canUseByteBuffer();
public boolean hasByteBuffer() {
return buf.hasByteBuffer();
}

@Nullable
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/grpc/internal/ReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public interface ReadableBuffer extends Closeable {
/**
* Indicates whether or not {@link #getByteBuffer} operation is supported for this buffer.
*/
boolean canUseByteBuffer();
boolean hasByteBuffer();

/**
* Gets a {@link ByteBuffer} that contains some bytes of the content next to be read, or {@code
Expand All @@ -150,7 +150,7 @@ public interface ReadableBuffer extends Closeable {
* mark may be changed. Operations for changing the position, limit, and mark of the returned
* buffer does not affect the position, limit, and mark of this buffer. Buffers returned by this
* method have independent position, limit and mark. This is an optional method, so callers
* should first check {@link #canUseByteBuffer}.
* should first check {@link #hasByteBuffer}.
*
* @throws UnsupportedOperationException the buffer does not support this method.
*/
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/grpc/internal/ReadableBuffers.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void reset() {
}

@Override
public boolean canUseByteBuffer() {
public boolean hasByteBuffer() {
return true;
}

Expand Down Expand Up @@ -387,7 +387,7 @@ public boolean markSupported() {

@Override
public boolean getByteBufferSupported() {
return buffer.canUseByteBuffer();
return buffer.hasByteBuffer();
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ public void canUseByteBufferOnlyAllComponentsSupportUsingByteBuffer() {
ReadableBuffer buffer1 = mock(ReadableBuffer.class);
ReadableBuffer buffer2 = mock(ReadableBuffer.class);
ReadableBuffer buffer3 = mock(ReadableBuffer.class);
when(buffer1.canUseByteBuffer()).thenReturn(true);
when(buffer2.canUseByteBuffer()).thenReturn(true);
when(buffer3.canUseByteBuffer()).thenReturn(false);
when(buffer1.hasByteBuffer()).thenReturn(true);
when(buffer2.hasByteBuffer()).thenReturn(true);
when(buffer3.hasByteBuffer()).thenReturn(false);
composite.addBuffer(buffer1);
assertTrue(composite.canUseByteBuffer());
assertTrue(composite.hasByteBuffer());
composite.addBuffer(buffer2);
assertTrue(composite.canUseByteBuffer());
assertTrue(composite.hasByteBuffer());
composite.addBuffer(buffer3);
assertFalse(composite.canUseByteBuffer());
assertFalse(composite.hasByteBuffer());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void markAndResetWithReadToReadableBufferShouldSucceed() {
@Test
public void getByteBufferDoesNotAffectBufferPosition() {
ReadableBuffer buffer = buffer();
Assume.assumeTrue(buffer.canUseByteBuffer());
Assume.assumeTrue(buffer.hasByteBuffer());
ByteBuffer byteBuffer = buffer.getByteBuffer();
assertEquals(msg.length(), buffer.readableBytes());
byteBuffer.get(new byte[byteBuffer.remaining()]);
Expand All @@ -163,7 +163,7 @@ public void getByteBufferDoesNotAffectBufferPosition() {
@Test
public void getByteBufferIsNotAffectedByBufferRead() {
ReadableBuffer buffer = buffer();
Assume.assumeTrue(buffer.canUseByteBuffer());
Assume.assumeTrue(buffer.hasByteBuffer());
ByteBuffer byteBuffer = buffer.getByteBuffer();
int initialRemaining = byteBuffer.remaining();
buffer.readBytes(new byte[100], 0, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void bufferInputStream_markAndReset() throws IOException {
@Test
public void bufferInputStream_getByteBufferDelegatesToBuffer() {
ReadableBuffer buffer = mock(ReadableBuffer.class);
when(buffer.canUseByteBuffer()).thenReturn(true);
when(buffer.hasByteBuffer()).thenReturn(true);
InputStream inputStream = ReadableBuffers.openStream(buffer, true);
assertTrue(((HasByteBuffer) inputStream).getByteBufferSupported());
((HasByteBuffer) inputStream).getByteBuffer();
Expand Down
2 changes: 1 addition & 1 deletion netty/src/main/java/io/grpc/netty/NettyReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void reset() {
}

@Override
public boolean canUseByteBuffer() {
public boolean hasByteBuffer() {
return buffer.nioBufferCount() > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void closeMultipleTimesShouldReleaseBufferOnce() {

@Test
public void getByteBufferFromSingleNioBufferBackedBuffer() {
assertTrue(buffer.canUseByteBuffer());
assertTrue(buffer.hasByteBuffer());
ByteBuffer byteBuffer = buffer.getByteBuffer();
byte[] arr = new byte[byteBuffer.remaining()];
byteBuffer.get(arr);
Expand Down