public final class PlatformDependent
extends Object
This class is forked from the netty project and modified to suit our needs.
| Modifier and Type | Method and Description |
|---|---|
static long |
allocateMemory(long size)
Allocates direct memory.
|
static void |
freeMemory(long address)
Deallocates direct memory.
|
static boolean |
hasUnsafe()
Deprecated.
This method is not used by internal ServiceTalk code anymore and will be removed in future releases.
|
static ByteBuffer |
newDirectBuffer(long address,
long size,
int capacity)
Creates a new
ByteBuffer for the specified pre-allocated direct memory. |
static <T> Queue<T> |
newMpscQueue(int maxCapacity)
Create a new
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!). |
static <T> Queue<T> |
newMpscQueue(int initialCapacity,
int maxCapacity)
Create a new
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!). |
static <T> Queue<T> |
newSpscQueue(int maxCapacity)
Create a new
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!). |
static <T> Queue<T> |
newSpscQueue(int initialCapacity,
int maxCapacity)
Create a new
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!). |
static <T> Queue<T> |
newUnboundedLinkedMpscQueue()
Create a new MPSC
Queue that will use a linked data structure and supports Collection.remove(Object). |
static <T> Queue<T> |
newUnboundedMpscQueue()
Create a new
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!). |
static <T> Queue<T> |
newUnboundedMpscQueue(int initialCapacity)
Create a new
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!). |
static <T> Queue<T> |
newUnboundedSpscQueue(int initialCapacity)
Create a new unbounded
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!). |
static void |
reserveMemory(long size,
int capacity)
Reserves direct memory for the specified size and capacity.
|
static <T> T |
throwException(Throwable t)
Deprecated.
|
static void |
unreserveMemory(long size,
int capacity)
Unreserves direct memory for the specified size and capacity.
|
static boolean |
useDirectBufferWithoutZeroing()
Checks if it is possible to create a new direct
ByteBuffer without zeroing the direct memory. |
@Deprecated public static boolean hasUnsafe()
sun.misc.Unsafe is available and has not been disabled.true if sun.misc.Unsafe is available.public static boolean useDirectBufferWithoutZeroing()
ByteBuffer without zeroing the direct memory.true if it is possible to create a new direct ByteBuffer without zeroing the direct
memory; false otherwise.public static void reserveMemory(long size,
int capacity)
size - The size of direct memory to reserve.capacity - The capacity of direct memory to reserve.public static void unreserveMemory(long size,
int capacity)
size - The size of direct memory to unreserve.capacity - The capacity of direct memory to unreserve.public static long allocateMemory(long size)
size - The size of direct memory to allocate.public static void freeMemory(long address)
address - The address of direct memory to free.public static ByteBuffer newDirectBuffer(long address,
long size,
int capacity)
ByteBuffer for the specified pre-allocated direct memory.address - The address of pre-allocated direct memory.size - The size of pre-allocated direct memory.capacity - The capacity of pre-allocated direct memory.ByteBuffer.@Deprecated public static <T> T throwException(Throwable t)
ThrowableUtils.throwException(Throwable).T - The expected typet - The Throwable to throw.public static <T> Queue<T> newUnboundedMpscQueue()
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).T - Type of items stored in the queue.Queue.public static <T> Queue<T> newUnboundedMpscQueue(int initialCapacity)
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).T - Type of items stored in the queue.initialCapacity - of the returned queue.Queue.public static <T> Queue<T> newMpscQueue(int maxCapacity)
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).T - Type of items stored in the queue.maxCapacity - of the queue.Queue with max capacity of maxCapacity.public static <T> Queue<T> newMpscQueue(int initialCapacity,
int maxCapacity)
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).T - Type of items stored in the queue.initialCapacity - Initial capacity for the queue.maxCapacity - of the queue.Queue with max capacity of maxCapacity.public static <T> Queue<T> newUnboundedLinkedMpscQueue()
Queue that will use a linked data structure and supports Collection.remove(Object).
Some reasons to use this queue as opposed to newUnboundedMpscQueue() include the following:
ConcurrentLinkedQueue only has 24 bytes of initial overhead so
this maybe a viable alternative if memory pressure exists and the size is expected to be small.Collection.remove(Object) support - Current only the linked variants support this operation.T - The data type of the queue.Queue that will use a linked data structure and supports Collection.remove(Object).public static <T> Queue<T> newSpscQueue(int maxCapacity)
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!).T - Type of items stored in the queue.maxCapacity - of the queue.Queue with max capacity of maxCapacity.public static <T> Queue<T> newSpscQueue(int initialCapacity,
int maxCapacity)
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!).T - Type of items stored in the queue.initialCapacity - Initial capacity for the queue.maxCapacity - of the queue.Queue with max capacity of maxCapacity.public static <T> Queue<T> newUnboundedSpscQueue(int initialCapacity)
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!).T - Type of items stored in the queue.initialCapacity - of the returned queue.Queue.