Rename the 'b2' package to 'api'

This commit is contained in:
Chris Vest 2020-11-17 15:38:11 +01:00
parent 0ad7f648ae
commit 3efa93841e
25 changed files with 46 additions and 49 deletions

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.nio.ByteOrder; import java.nio.ByteOrder;

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
/** /**
* Methods for accessing and controlling the internals of an allocator. * Methods for accessing and controlling the internals of an allocator.

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
/** /**
* This interface is just the primitive data accessor methods that {@link Buf} exposes. * This interface is just the primitive data accessor methods that {@link Buf} exposes.

View File

@ -12,7 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under * or implied. See the License for the specific language governing permissions and limitations under
* the License. * the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -27,7 +27,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
* non-composite copy of the buffer. * non-composite copy of the buffer.
*/ */
private static final int MAX_CAPACITY = Integer.MAX_VALUE - 8; private static final int MAX_CAPACITY = Integer.MAX_VALUE - 8;
private static final Drop<CompositeBuf> COMPOSITE_DROP = new Drop<CompositeBuf>() { private static final Drop<CompositeBuf>
COMPOSITE_DROP = new Drop<CompositeBuf>() {
@Override @Override
public void drop(CompositeBuf obj) { public void drop(CompositeBuf obj) {
for (Buf buf : obj.bufs) { for (Buf buf : obj.bufs) {

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.util.function.Consumer; import java.util.function.Consumer;

View File

@ -13,11 +13,11 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.lang.ref.Cleaner; import java.lang.ref.Cleaner;
import static io.netty.buffer.b2.Statics.NO_OP_DROP; import static io.netty.buffer.api.Statics.NO_OP_DROP;
class ManagedAllocator implements Allocator, AllocatorControl { class ManagedAllocator implements Allocator, AllocatorControl {
private final MemoryManager manager; private final MemoryManager manager;

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import jdk.incubator.foreign.MemorySegment; import jdk.incubator.foreign.MemorySegment;

View File

@ -13,8 +13,9 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import io.netty.buffer.api.MemSegBuf.RecoverableMemory;
import jdk.incubator.foreign.MemorySegment; import jdk.incubator.foreign.MemorySegment;
import java.lang.ref.Cleaner; import java.lang.ref.Cleaner;
@ -72,7 +73,7 @@ public interface MemoryManager {
@Override @Override
public Buf recoverMemory(Object recoverableMemory, Drop<Buf> drop) { public Buf recoverMemory(Object recoverableMemory, Drop<Buf> drop) {
var recovery = (MemSegBuf.RecoverableMemory) recoverableMemory; var recovery = (RecoverableMemory) recoverableMemory;
return recovery.recover(convert(drop)); return recovery.recover(convert(drop));
} }

View File

@ -13,15 +13,15 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.lang.invoke.VarHandle; import java.lang.invoke.VarHandle;
import java.lang.ref.Cleaner.Cleanable; import java.lang.ref.Cleaner.Cleanable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static io.netty.buffer.b2.Statics.CLEANER; import static io.netty.buffer.api.Statics.CLEANER;
import static io.netty.buffer.b2.Statics.findVarHandle; import static io.netty.buffer.api.Statics.findVarHandle;
import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodHandles.lookup;
class NativeMemoryCleanerDrop implements Drop<Buf> { class NativeMemoryCleanerDrop implements Drop<Buf> {

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
/** /**
* This interface encapsulates the ownership of an {@link Rc}, and exposes a method that may be used to transfer this * This interface encapsulates the ownership of an {@link Rc}, and exposes a method that may be used to transfer this

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
/** /**
* An Rc is a reference counted, thread-confined, resource of sorts. Because these resources are thread-confined, the * An Rc is a reference counted, thread-confined, resource of sorts. Because these resources are thread-confined, the

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
public abstract class RcSupport<I extends Rc<I>, T extends RcSupport<I, T>> implements Rc<I> { public abstract class RcSupport<I extends Rc<I>, T extends RcSupport<I, T>> implements Rc<I> {
private int acquires; // Closed if negative. private int acquires; // Closed if negative.

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
/** /**
* Thrown when resource disposal fails while closing a resource pool. * Thrown when resource disposal fails while closing a resource pool.

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.util.ArrayDeque; import java.util.ArrayDeque;

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
/** /**
* A Send object is a temporary holder of an {@link Rc}, used for transferring the ownership of the Rc from one thread * A Send object is a temporary holder of an {@link Rc}, used for transferring the ownership of the Rc from one thread

View File

@ -13,14 +13,14 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.lang.invoke.VarHandle; import java.lang.invoke.VarHandle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import static io.netty.buffer.b2.Statics.NO_OP_DROP; import static io.netty.buffer.api.Statics.NO_OP_DROP;
import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodHandles.lookup;
class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop<Buf> { class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop<Buf> {

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.VarHandle; import java.lang.invoke.VarHandle;

View File

@ -13,11 +13,11 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.lang.invoke.VarHandle; import java.lang.invoke.VarHandle;
import static io.netty.buffer.b2.Statics.findVarHandle; import static io.netty.buffer.api.Statics.findVarHandle;
import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodHandles.lookup;
class TransferSend<I extends Rc<I>, T extends Rc<I>> implements Send<I> { class TransferSend<I extends Rc<I>, T extends Rc<I>> implements Send<I> {

View File

@ -17,4 +17,4 @@
/** /**
* Experimental {@code Buf} implementation, based on MemorySegment, as a potential alternative to {@code ByteBuf}. * Experimental {@code Buf} implementation, based on MemorySegment, as a potential alternative to {@code ByteBuf}.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;

View File

@ -13,8 +13,9 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import io.netty.buffer.api.Fixture.Properties;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
@ -40,12 +41,6 @@ import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.Stream.Builder; import java.util.stream.Stream.Builder;
import static io.netty.buffer.b2.Fixture.Properties.CLEANER;
import static io.netty.buffer.b2.Fixture.Properties.COMPOSITE;
import static io.netty.buffer.b2.Fixture.Properties.DIRECT;
import static io.netty.buffer.b2.Fixture.Properties.HEAP;
import static io.netty.buffer.b2.Fixture.Properties.POOLED;
import static io.netty.buffer.b2.Fixture.Properties.SLICE;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
@ -90,12 +85,12 @@ public class BufTest {
return Arrays.stream(fxs); return Arrays.stream(fxs);
} }
List<Fixture> initFixtures = List.of( List<Fixture> initFixtures = List.of(
new Fixture("heap", Allocator::heap, HEAP), new Fixture("heap", Allocator::heap, Properties.HEAP),
new Fixture("direct", Allocator::direct, DIRECT), new Fixture("direct", Allocator::direct, Properties.DIRECT),
new Fixture("directWithCleaner", Allocator::directWithCleaner, DIRECT, CLEANER), new Fixture("directWithCleaner", Allocator::directWithCleaner, Properties.DIRECT, Properties.CLEANER),
new Fixture("pooledHeap", Allocator::pooledHeap, POOLED, HEAP), new Fixture("pooledHeap", Allocator::pooledHeap, Properties.POOLED, Properties.HEAP),
new Fixture("pooledDirect", Allocator::pooledDirect, POOLED, DIRECT), new Fixture("pooledDirect", Allocator::pooledDirect, Properties.POOLED, Properties.DIRECT),
new Fixture("pooledDirectWithCleaner", Allocator::pooledDirectWithCleaner, POOLED, DIRECT, CLEANER)); new Fixture("pooledDirectWithCleaner", Allocator::pooledDirectWithCleaner, Properties.POOLED, Properties.DIRECT, Properties.CLEANER));
Builder<Fixture> builder = Stream.builder(); Builder<Fixture> builder = Stream.builder();
initFixtures.forEach(builder); initFixtures.forEach(builder);
@ -121,7 +116,7 @@ public class BufTest {
b.close(); b.close();
} }
}; };
}, COMPOSITE)); }, Properties.COMPOSITE));
} }
} }
@ -144,7 +139,7 @@ public class BufTest {
alloc.close(); alloc.close();
} }
}; };
}, COMPOSITE)); }, Properties.COMPOSITE));
for (Fixture fixture : initFixtures) { for (Fixture fixture : initFixtures) {
builder.add(new Fixture(fixture + ".ensureWritable", () -> { builder.add(new Fixture(fixture + ".ensureWritable", () -> {
@ -184,7 +179,7 @@ public class BufTest {
allocator.close(); allocator.close();
} }
}; };
}, COMPOSITE)); }, Properties.COMPOSITE));
} }
return builder.build().flatMap(f -> { return builder.build().flatMap(f -> {
@ -206,7 +201,7 @@ public class BufTest {
allocatorBase.close(); allocatorBase.close();
} }
}; };
}, SLICE)); }, Properties.SLICE));
andSlices.add(new Fixture(f + ".slice(1, capacity() - 2)", () -> { andSlices.add(new Fixture(f + ".slice(1, capacity() - 2)", () -> {
var allocatorBase = f.get(); var allocatorBase = f.get();
return new Allocator() { return new Allocator() {
@ -222,7 +217,7 @@ public class BufTest {
allocatorBase.close(); allocatorBase.close();
} }
}; };
}, SLICE)); }, Properties.SLICE));
return andSlices.build(); return andSlices.build();
}); });
} }

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.BenchmarkMode;

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.buffer.b2; package io.netty.buffer.api;
import org.junit.Test; import org.junit.Test;