Motivation: We need a new implementation of our new API that supports Java 11, since that is what Netty 5 will most likely baseline on. We also need an implementation that does not rely on Unsafe. This leaves us with ByteBuffer as the underlying currency of memory. Modification: - Add a NioBuffer implementation and associated supporting classes. - The entry-point for this is a new MemoryManagers API, which is used to pick the implementation and provide the on-/off-heap MemoryManager implementations. - Add a mechanism to configure/override which MemoryManagers implementation to use. - The MemoryManagers implementations are service-loadable, so new ones can be discovered at runtime. - The existing MemorySegment based implementation also get a MemoryManagers implementation. - Expand the BufferTest to include all combinations of all implementations. We now run 360.000 tests in BufferTest. - Some common infrastructure, like ArcDrop, is moved to its own package. - Add a module-info.java to control the service loading, and the visibility in the various packages. - Some pom.xml file updates to support our now module based project. Result: We have an implementation that should work on Java 11, but we currently don't build or test on 11. More work needs to happen before that is a reality.
75 lines
2.6 KiB
Java
75 lines
2.6 KiB
Java
/*
|
|
* Copyright 2020 The Netty Project
|
|
*
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
* with the License. You may obtain a copy of the License at:
|
|
*
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*/
|
|
package io.netty.buffer.api;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
/**
|
|
* A view onto the buffer component being processed in a given iteration of
|
|
* {@link Buffer#forEachWritable(int, WritableComponentProcessor)}.
|
|
*/
|
|
public interface WritableComponent {
|
|
|
|
/**
|
|
* Check if this component is backed by a cached byte array than can be accessed cheaply.
|
|
*
|
|
* @return {@code true} if {@link #writableArray()} is a cheap operation, otherwise {@code false}.
|
|
*/
|
|
boolean hasWritableArray();
|
|
|
|
/**
|
|
* Get a byte array of the contents of this component.
|
|
*
|
|
* @return A byte array of the contents of this component.
|
|
* @throws UnsupportedOperationException if {@link #hasWritableArray()} returns {@code false}.
|
|
* @see #writableArrayOffset()
|
|
* @see #writableArrayLength()
|
|
*/
|
|
byte[] writableArray();
|
|
|
|
/**
|
|
* An offset into the {@link #writableArray()} where this component starts.
|
|
*
|
|
* @return An offset into {@link #writableArray()}.
|
|
* @throws UnsupportedOperationException if {@link #hasWritableArray()} returns {@code false}.
|
|
*/
|
|
int writableArrayOffset();
|
|
|
|
/**
|
|
* The number of bytes in the {@link #writableArray()} that belong to this component.
|
|
*
|
|
* @return The number of bytes, from the {@link #writableArrayOffset()} into the {@link #writableArray()},
|
|
* that belong to this component.
|
|
* @throws UnsupportedOperationException if {@link #hasWritableArray()} returns {@code false}.
|
|
*/
|
|
int writableArrayLength();
|
|
|
|
/**
|
|
* Give the native memory address backing this buffer, or return 0 if this buffer has no native memory address.
|
|
*
|
|
* @return The native memory address, if any, otherwise 0.
|
|
*/
|
|
long writableNativeAddress();
|
|
|
|
/**
|
|
* Get a {@link ByteBuffer} instance for this memory component, which can be used for modifying the buffer
|
|
* contents.
|
|
*
|
|
* @return A new {@link ByteBuffer}, with its own position and limit, for this memory component.
|
|
*/
|
|
ByteBuffer writableBuffer();
|
|
}
|