/** * Creates a new fastest {@link LongCounter} implementation for the current platform. */ public static LongCounter newLongCounter() { if (javaVersion() >= 8) { return new LongAdderCounter(); } else { return new AtomicLongCounter(); } }
/** * @param executor the {@link EventExecutor} which is used to notify the listeners of the {@link Future} returned * by {@link #resolve(SocketAddress)} * @param addressType the type of the {@link SocketAddress} supported by this resolver */ protected AbstractAddressResolver(EventExecutor executor, Class<? extends T> addressType) { this.executor = checkNotNull(executor, "executor"); matcher = TypeParameterMatcher.get(addressType); }
/** * @param executor the {@link EventExecutor} which is used to notify the listeners of the {@link Future} returned * by {@link #resolve(SocketAddress)} */ protected AbstractAddressResolver(EventExecutor executor) { this.executor = checkNotNull(executor, "executor"); matcher = TypeParameterMatcher.find(this, AbstractAddressResolver.class, "T"); }
@Override public void validateName(Object name) { checkNotNull(name, "name"); } };
/** * Determine if a subsection of an array is zero. * @param bytes The byte array. * @param startPos The starting index (inclusive) in {@code bytes}. * @param length The amount of bytes to check for zero. * @return {@code false} if {@code bytes[startPos:startsPos+length)} contains a value other than zero. */ public static boolean isZero(byte[] bytes, int startPos, int length) { return !hasUnsafe() || !unalignedAccess() ? isZeroSafe(bytes, startPos, length) : PlatformDependent0.isZero(bytes, startPos, length); }
/** * Calculate a hash code of a byte array assuming ASCII character encoding. * The resulting hash code will be case insensitive. * @param bytes The array which contains the data to hash. * @param startPos What index to start generating a hash code in {@code bytes} * @param length The amount of bytes that should be accounted for in the computation. * @return The hash code of {@code bytes} assuming ASCII character encoding. * The resulting hash code will be case insensitive. */ public static int hashCodeAscii(byte[] bytes, int startPos, int length) { return !hasUnsafe() || !unalignedAccess() ? hashCodeAsciiSafe(bytes, startPos, length) : PlatformDependent0.hashCodeAscii(bytes, startPos, length); }
/** * Raises an exception bypassing compiler checks for checked exceptions. */ public static void throwException(Throwable t) { if (hasUnsafe()) { PlatformDependent0.throwException(t); } else { PlatformDependent.<RuntimeException>throwException0(t); } }
private static int addressSize0() { if (!hasUnsafe()) { return -1; } return PlatformDependent0.addressSize(); }
private static long byteArrayBaseOffset0() { if (!hasUnsafe()) { return -1; } return PlatformDependent0.byteArrayBaseOffset(); }
static int majorVersionFromJavaSpecificationVersion() { return majorVersion(SystemPropertyUtil.get("java.specification.version", "1.6")); }
/** * Return {@code true} if direct memory cache alignment is supported, {@code false} otherwise. */ public static boolean isDirectMemoryCacheAlignmentSupported() { return PlatformDependent.hasUnsafe(); }
/** * Create a new instance. * * @param inboundMessageType The type of messages to decode * @param outboundMessageType The type of messages to encode */ protected MessageToMessageCodec( Class<? extends INBOUND_IN> inboundMessageType, Class<? extends OUTBOUND_IN> outboundMessageType) { inboundMsgMatcher = TypeParameterMatcher.get(inboundMessageType); outboundMsgMatcher = TypeParameterMatcher.get(outboundMessageType); }
MemoryRegionCache(int size, SizeClass sizeClass) { this.size = MathUtil.safeFindNextPositivePowerOfTwo(size); queue = PlatformDependent.newFixedMpscQueue(this.size); this.sizeClass = sizeClass; }
private static boolean explicitTryReflectionSetAccessible0() { // we disable reflective access return SystemPropertyUtil.getBoolean("io.netty.tryReflectionSetAccessible", javaVersion() < 9); }
ReadOnlyUnsafeDirectByteBuf(ByteBufAllocator allocator, ByteBuffer byteBuffer) { super(allocator, byteBuffer); // Use buffer as the super class will slice the passed in ByteBuffer which means the memoryAddress // may be different if the position != 0. memoryAddress = PlatformDependent.directBufferAddress(buffer); }
@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }
@Override public T poll() { if (size == 0) { return null; } T result = queue[0]; result.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); T last = queue[--size]; queue[size] = null; if (size != 0) { // Make sure we don't add the last element back. bubbleDown(0, last); } return result; }
/** * Create a new instance which will try to detect the types to match out of the type parameter of the class. * * @param preferDirect {@code true} if a direct {@link ByteBuf} should be tried to be used as target for * the encoded messages. If {@code false} is used it will allocate a heap * {@link ByteBuf}, which is backed by an byte array. */ protected MessageToByteEncoder(boolean preferDirect) { matcher = TypeParameterMatcher.find(this, MessageToByteEncoder.class, "I"); this.preferDirect = preferDirect; }
/** * Decode a 2-digit hex byte from within a string. */ public static byte decodeHexByte(CharSequence s, int pos) { return StringUtil.decodeHexByte(s, pos); }
@Override public boolean containsTyped(T node) { return contains(node, node.priorityQueueIndex(this)); }