Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit e22b57d

Browse files
committed
Address PR review comments
1 parent 1c11493 commit e22b57d

File tree

4 files changed

+48
-39
lines changed

4 files changed

+48
-39
lines changed

src/main/java/io/netty/buffer/api/Buf.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package io.netty.buffer.api;
1717

18-
import io.netty.buffer.api.ComponentProcessor.OfReadable;
19-
import io.netty.buffer.api.ComponentProcessor.OfWritable;
18+
import io.netty.buffer.api.ComponentProcessor.ReadableComponentProcessor;
19+
import io.netty.buffer.api.ComponentProcessor.WritableComponentProcessor;
2020
import io.netty.buffer.api.ComponentProcessor.ReadableComponent;
2121
import io.netty.buffer.api.ComponentProcessor.WritableComponent;
2222

@@ -498,9 +498,9 @@ default void ensureWritable(int size) {
498498

499499
/**
500500
* Get the number of "components" in this buffer, that are readable. These are the components that would be
501-
* processed by {@link #forEachReadable(int, OfReadable)}. For composite buffers, this is the number of
502-
* transitive constituent buffers that are readable, while non-composite buffers only have at most one readable
503-
* component.
501+
* processed by {@link #forEachReadable(int, ReadableComponentProcessor)}. For composite buffers, this is the
502+
* number of transitive constituent buffers that are readable, while non-composite buffers only have at most one
503+
* readable component.
504504
* <p>
505505
* The number of readable components may be less than the {@link #countComponents() component count}, if not all of
506506
* them have readable data.
@@ -511,9 +511,9 @@ default void ensureWritable(int size) {
511511

512512
/**
513513
* Get the number of "components" in this buffer, that are writable. These are the components that would be
514-
* processed by {@link #forEachWritable(int, OfWritable)}. For composite buffers, this is the number of
515-
* transitive constituent buffers that are writable, while non-composite buffers only have at most one writable
516-
* component.
514+
* processed by {@link #forEachWritable(int, WritableComponentProcessor)}. For composite buffers, this is the
515+
* number of transitive constituent buffers that are writable, while non-composite buffers only have at most one
516+
* writable component.
517517
* <p>
518518
* The number of writable components may be less than the {@link #countComponents() component count}, if not all of
519519
* them have space for writing.
@@ -525,14 +525,15 @@ default void ensureWritable(int size) {
525525
/**
526526
* Process all readable components of this buffer, and return the number of components processed.
527527
* <p>
528-
* The given {@linkplain OfReadable processor} is called for each readable component in this buffer,
528+
* The given {@linkplain ReadableComponentProcessor processor} is called for each readable component in this buffer,
529529
* and passed a component index, for the given component in the iteration, and a {@link ReadableComponent} object
530530
* for accessing the data within the given component.
531531
* <p>
532532
* The component index is specific to the particular invokation of this method. The first call to the consumer will
533533
* be passed the given initial index, and the next call will be passed the initial index plus one, and so on.
534534
* <p>
535-
* The {@linkplain OfReadable component processor} may stop the iteration at any time by returning {@code false}.
535+
* The {@linkplain ReadableComponentProcessor component processor} may stop the iteration at any time by returning
536+
* {@code false}.
536537
* This will cause the number of components processed to be returned as a negative number (to signal early return),
537538
* and the number of components processed may then be less than the
538539
* {@linkplain #countReadableComponents() readable component count}.
@@ -545,7 +546,7 @@ default void ensureWritable(int size) {
545546
* such changes, are any method that requires the buffer to be {@linkplain #isOwned() owned}.
546547
* <p>
547548
* The best way to ensure this doesn't cause any trouble, is to use the buffers directly as part of the iteration,
548-
* or immediately after the iteration.
549+
* or immediately after the iteration while we are still in the scope of the method that triggered the iteration.
549550
* <p>
550551
* <strong>Note</strong> that the arrays, memory addresses, and byte buffers exposed as components by this method,
551552
* should not be used for changing the buffer contents. Doing so may cause undefined behaviour.
@@ -554,26 +555,27 @@ default void ensureWritable(int size) {
554555
* this buffer instance.
555556
*
556557
* @param initialIndex The initial index of the iteration, and the index that will be passed to the first call to
557-
* the {@linkplain OfReadable#process(int, ReadableComponent) processor}.
558+
* the {@linkplain ReadableComponentProcessor#process(int, ReadableComponent) processor}.
558559
* @param processor The processor that will be used to process the buffer components.
559560
* @return The number of readable components processed, as a positive number of all readable components were
560561
* processed, or as a negative number if the iteration was stopped because
561-
* {@link OfReadable#process(int, ReadableComponent)} returned {@code false}.
562+
* {@link ReadableComponentProcessor#process(int, ReadableComponent)} returned {@code false}.
562563
* In any case, the number of components processed may be less than {@link #countComponents()}.
563564
*/
564-
int forEachReadable(int initialIndex, OfReadable processor);
565+
int forEachReadable(int initialIndex, ReadableComponentProcessor processor);
565566

566567
/**
567568
* Process all writable components of this buffer, and return the number of components processed.
568569
* <p>
569-
* The given {@linkplain OfWritable processor} is called for each writable component in this buffer,
570+
* The given {@linkplain WritableComponentProcessor processor} is called for each writable component in this buffer,
570571
* and passed a component index, for the given component in the iteration, and a {@link WritableComponent} object
571572
* for accessing the data within the given component.
572573
* <p>
573574
* The component index is specific to the particular invokation of this method. The first call to the consumer will
574575
* be passed the given initial index, and the next call will be passed the initial index plus one, and so on.
575576
* <p>
576-
* The {@link OfWritable component processor} may stop the iteration at any time by returning {@code false}.
577+
* The {@link WritableComponentProcessor component processor} may stop the iteration at any time by returning
578+
* {@code false}.
577579
* This will cause the number of components processed to be returned as a negative number (to signal early return),
578580
* and the number of components processed may then be less than the
579581
* {@linkplain #countReadableComponents() readable component count}.
@@ -586,18 +588,18 @@ default void ensureWritable(int size) {
586588
* such changes, are any method that requires the buffer to be {@linkplain #isOwned() owned}.
587589
* <p>
588590
* The best way to ensure this doesn't cause any trouble, is to use the buffers directly as part of the iteration,
589-
* or immediately after the iteration.
591+
* or immediately after the iteration while we are still in the scope of the method that triggered the iteration.
590592
* <p>
591593
* Changes to position and limit of the byte buffers exposed via the processed components, are not reflected back to
592594
* this buffer instance.
593595
*
594596
* @param initialIndex The initial index of the iteration, and the index that will be passed to the first call to
595-
* the {@linkplain OfWritable#process(int, WritableComponent) processor}.
597+
* the {@linkplain WritableComponentProcessor#process(int, WritableComponent) processor}.
596598
* @param processor The processor that will be used to process the buffer components.
597599
* @return The number of writable components processed, as a positive number of all writable components were
598600
* processed, or as a negative number if the iteration was stopped because
599-
* {@link OfWritable#process(int, WritableComponent)} returned {@code false}.
601+
* {@link WritableComponentProcessor#process(int, WritableComponent)} returned {@code false}.
600602
* In any case, the number of components processed may be less than {@link #countComponents()}.
601603
*/
602-
int forEachWritable(int initialIndex, OfWritable processor);
604+
int forEachWritable(int initialIndex, WritableComponentProcessor processor);
603605
}

src/main/java/io/netty/buffer/api/ComponentProcessor.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@
1818
import java.nio.ByteBuffer;
1919

2020
/**
21-
* This interface contain a collection of APIs used in the {@link Buf#forEachReadable(int, OfReadable)} and
22-
* {@link Buf#forEachWritable(int, OfWritable)} methods.
21+
* This interface contain a collection of APIs used in the {@link Buf#forEachReadable(int, ReadableComponentProcessor)}
22+
* and {@link Buf#forEachWritable(int, WritableComponentProcessor)} methods.
2323
*/
2424
public interface ComponentProcessor {
2525
/**
2626
* A processor of {@linkplain ReadableComponent readable components}.
2727
*/
2828
@FunctionalInterface
29-
interface OfReadable extends ComponentProcessor {
29+
interface ReadableComponentProcessor extends ComponentProcessor {
3030
/**
31-
* Process the given component at the given index in the {@link Buf#forEachReadable(int, OfReadable) iteration}.
31+
* Process the given component at the given index in the
32+
* {@link Buf#forEachReadable(int, ReadableComponentProcessor) iteration}.
3233
* <p>
3334
* The component object itself is only valid during this call, but the {@link ByteBuffer byte buffers}, arrays,
3435
* and native address pointers obtained from it, will be valid until any
3536
* {@link Buf#isOwned() ownership} requiring operation is performed on the buffer.
3637
*
3738
* @param index The current index of the given buffer component, based on the initial index passed to the
38-
* {@link Buf#forEachReadable(int, OfReadable)} method.
39+
* {@link Buf#forEachReadable(int, ReadableComponentProcessor)} method.
3940
* @param component The current buffer component being processed.
4041
* @return {@code true} if the iteration should continue and more components should be processed, otherwise
4142
* {@code false} to stop the iteration early.
@@ -47,17 +48,17 @@ interface OfReadable extends ComponentProcessor {
4748
* A processor of {@linkplain WritableComponent writable components}.
4849
*/
4950
@FunctionalInterface
50-
interface OfWritable extends ComponentProcessor {
51+
interface WritableComponentProcessor extends ComponentProcessor {
5152
/**
5253
* Process the given component at the given index in the
53-
* {@link Buf#forEachWritable(int, OfWritable)} iteration}.
54+
* {@link Buf#forEachWritable(int, WritableComponentProcessor)} iteration}.
5455
* <p>
5556
* The component object itself is only valid during this call, but the {@link ByteBuffer byte buffers}, arrays,
5657
* and native address pointers obtained from it, will be valid until any
5758
* {@link Buf#isOwned() ownership} requiring operation is performed on the buffer.
5859
*
5960
* @param index The current index of the given buffer component, based on the initial index passed to the
60-
* {@link Buf#forEachWritable(int, OfWritable)} method.
61+
* {@link Buf#forEachWritable(int, WritableComponentProcessor)} method.
6162
* @param component The current buffer component being processed.
6263
* @return {@code true} if the iteration should continue and more components should be processed, otherwise
6364
* {@code false} to stop the iteration early.
@@ -67,7 +68,7 @@ interface OfWritable extends ComponentProcessor {
6768

6869
/**
6970
* A view onto the buffer component being processed in a given iteration of
70-
* {@link Buf#forEachReadable(int, OfReadable)}.
71+
* {@link Buf#forEachReadable(int, ReadableComponentProcessor)}.
7172
*/
7273
interface ReadableComponent {
7374

@@ -115,16 +116,16 @@ interface ReadableComponent {
115116
* Get a {@link ByteBuffer} instance for this memory component.
116117
* <p>
117118
* <strong>Note</strong> that the {@link ByteBuffer} is read-only, to prevent write accesses to the memory,
118-
* when the buffer component is obtained through {@link Buf#forEachReadable(int, OfReadable)}.
119+
* when the buffer component is obtained through {@link Buf#forEachReadable(int, ReadableComponentProcessor)}.
119120
*
120-
* @return A new {@link ByteBuffer} for this memory component.
121+
* @return A new {@link ByteBuffer}, with its own position and limit, for this memory component.
121122
*/
122123
ByteBuffer readableBuffer();
123124
}
124125

125126
/**
126127
* A view onto the buffer component being processed in a given iteration of
127-
* {@link Buf#forEachWritable(int, OfWritable)}.
128+
* {@link Buf#forEachWritable(int, WritableComponentProcessor)}.
128129
*/
129130
interface WritableComponent {
130131

@@ -162,7 +163,7 @@ interface WritableComponent {
162163
* Get a {@link ByteBuffer} instance for this memory component, which can be used for modifying the buffer
163164
* contents.
164165
*
165-
* @return A new {@link ByteBuffer} for this memory component.
166+
* @return A new {@link ByteBuffer}, with its own position and limit, for this memory component.
166167
*/
167168
ByteBuffer writableBuffer();
168169
}

src/main/java/io/netty/buffer/api/CompositeBuf.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package io.netty.buffer.api;
1717

18+
import io.netty.buffer.api.ComponentProcessor.ReadableComponentProcessor;
19+
import io.netty.buffer.api.ComponentProcessor.WritableComponentProcessor;
20+
1821
import java.nio.ByteBuffer;
1922
import java.nio.ByteOrder;
2023
import java.util.Arrays;
@@ -750,7 +753,7 @@ public int countWritableComponents() {
750753
}
751754

752755
@Override
753-
public int forEachReadable(int initialIndex, ComponentProcessor.OfReadable processor) {
756+
public int forEachReadable(int initialIndex, ReadableComponentProcessor processor) {
754757
checkReadBounds(readerOffset(), Math.max(1, readableBytes()));
755758
int visited = 0;
756759
for (Buf buf : bufs) {
@@ -768,7 +771,7 @@ public int forEachReadable(int initialIndex, ComponentProcessor.OfReadable proce
768771
}
769772

770773
@Override
771-
public int forEachWritable(int initialIndex, ComponentProcessor.OfWritable processor) {
774+
public int forEachWritable(int initialIndex, WritableComponentProcessor processor) {
772775
checkWriteBounds(writerOffset(), Math.max(1, writableBytes()));
773776
int visited = 0;
774777
for (Buf buf : bufs) {

src/main/java/io/netty/buffer/api/memseg/MemSegBuf.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
import io.netty.buffer.api.AllocatorControl;
2020
import io.netty.buffer.api.Buf;
2121
import io.netty.buffer.api.ByteCursor;
22-
import io.netty.buffer.api.ComponentProcessor;
2322
import io.netty.buffer.api.ComponentProcessor.ReadableComponent;
23+
import io.netty.buffer.api.ComponentProcessor.ReadableComponentProcessor;
2424
import io.netty.buffer.api.ComponentProcessor.WritableComponent;
25+
import io.netty.buffer.api.ComponentProcessor.WritableComponentProcessor;
2526
import io.netty.buffer.api.Drop;
2627
import io.netty.buffer.api.Owned;
2728
import io.netty.buffer.api.RcSupport;
@@ -61,7 +62,9 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf, ReadableCompon
6162

6263
private final AllocatorControl alloc;
6364
private final boolean isSendable;
64-
private final int baseOffset; // TODO remove this when JDK bug is fixed (slices of heap buffers)
65+
// TODO remove baseOffset when JDK bug is fixed (slices of heap buffers)
66+
// See https://mail.openjdk.java.net/pipermail/panama-dev/2021-January/011810.html
67+
private final int baseOffset;
6568
private MemorySegment seg;
6669
private MemorySegment wseg;
6770
private ByteOrder order;
@@ -551,13 +554,13 @@ public int countWritableComponents() {
551554
}
552555

553556
@Override
554-
public int forEachReadable(int initialIndex, ComponentProcessor.OfReadable processor) {
557+
public int forEachReadable(int initialIndex, ReadableComponentProcessor processor) {
555558
checkRead(readerOffset(), Math.max(1, readableBytes()));
556559
return processor.process(initialIndex, this)? 1 : -1;
557560
}
558561

559562
@Override
560-
public int forEachWritable(int initialIndex, ComponentProcessor.OfWritable processor) {
563+
public int forEachWritable(int initialIndex, WritableComponentProcessor processor) {
561564
checkWrite(writerOffset(), Math.max(1, writableBytes()));
562565
return processor.process(initialIndex, this)? 1 : -1;
563566
}

0 commit comments

Comments
 (0)