/** * Creates a new instance. * * @param frameLength the length of the frame */ public FixedLengthFrameDecoder(int frameLength) { checkPositive(frameLength, "frameLength"); this.frameLength = frameLength; }
/** * Set the number of reads after which {@link ByteBuf#discardSomeReadBytes()} are called and so free up memory. * The default is {@code 16}. */ public void setDiscardAfterReads(int discardAfterReads) { checkPositive(discardAfterReads, "discardAfterReads"); this.discardAfterReads = discardAfterReads; }
/** * Creates a new predictor that always returns the same prediction of * the specified buffer size. */ public FixedRecvByteBufAllocator(int bufferSize) { checkPositive(bufferSize, "bufferSize"); this.bufferSize = bufferSize; }
@Override public MaxMessagesRecvByteBufAllocator maxMessagesPerRead(int maxMessagesPerRead) { checkPositive(maxMessagesPerRead, "maxMessagesPerRead"); this.maxMessagesPerRead = maxMessagesPerRead; return this; }
@Override public ChannelConfig setWriteSpinCount(int writeSpinCount) { checkPositive(writeSpinCount, "writeSpinCount"); // Integer.MAX_VALUE is used as a special value in the channel implementations to indicate the channel cannot // accept any more data, and results in the writeOp being set on the selector (or execute a runnable which tries // to flush later because the writeSpinCount quantum has been exhausted). This strategy prevents additional // conditional logic in the channel implementations, and shouldn't be noticeable in practice. if (writeSpinCount == Integer.MAX_VALUE) { --writeSpinCount; } this.writeSpinCount = writeSpinCount; return this; }
private static void validateMaxFrameLength(int maxFrameLength) { checkPositive(maxFrameLength, "maxFrameLength"); } }
/** * Create a new instance * * @param hasDisconnect {@code true} if and only if the channel has the {@code disconnect()} operation * that allows a user to disconnect and then call {@link Channel#connect(SocketAddress)} * again, such as UDP/IP. * @param defaultMaxMessagesPerRead If a {@link MaxMessagesRecvByteBufAllocator} is in use, then this value will be * set for {@link MaxMessagesRecvByteBufAllocator#maxMessagesPerRead()}. Must be {@code > 0}. */ public ChannelMetadata(boolean hasDisconnect, int defaultMaxMessagesPerRead) { checkPositive(defaultMaxMessagesPerRead, "defaultMaxMessagesPerRead"); this.hasDisconnect = hasDisconnect; this.defaultMaxMessagesPerRead = defaultMaxMessagesPerRead; }
private static void checkMaxBytesPerReadPair(int maxBytesPerRead, int maxBytesPerIndividualRead) { checkPositive(maxBytesPerRead, "maxBytesPerRead"); checkPositive(maxBytesPerIndividualRead, "maxBytesPerIndividualRead"); if (maxBytesPerRead < maxBytesPerIndividualRead) { throw new IllegalArgumentException( "maxBytesPerRead cannot be less than " + "maxBytesPerIndividualRead (" + maxBytesPerIndividualRead + "): " + maxBytesPerRead); } }
/** * Creates a new instance. Be aware that the given {@link EventExecutorGroup} <strong>MUST NOT</strong> contain * any {@link OrderedEventExecutor}s. */ public NonStickyEventExecutorGroup(EventExecutorGroup group, int maxTaskExecutePerRun) { this.group = verify(group); this.maxTaskExecutePerRun = ObjectUtil.checkPositive(maxTaskExecutePerRun, "maxTaskExecutePerRun"); }
/** * Checks that the given argument is neither null nor empty. * If it is, throws {@link NullPointerException} or {@link IllegalArgumentException}. * Otherwise, returns the argument. */ public static <T> T[] checkNonEmpty(T[] array, String name) { checkNotNull(array, name); checkPositive(array.length, name + ".length"); return array; }
/** * Checks that the given argument is neither null nor empty. * If it is, throws {@link NullPointerException} or {@link IllegalArgumentException}. * Otherwise, returns the argument. */ public static <T extends Collection<?>> T checkNonEmpty(T collection, String name) { checkNotNull(collection, name); checkPositive(collection.size(), name + ".size"); return collection; }
@Override public ByteBuf retain(int increment) { return retain0(checkPositive(increment, "increment")); }
@Override public boolean release(int decrement) { return release0(checkPositive(decrement, "decrement")); }
@Override public ReferenceCounted retain(int increment) { return retain0(checkPositive(increment, "increment")); }
@Override public boolean release(int decrement) { return release0(checkPositive(decrement, "decrement")); }
@Override public DefaultMaxBytesRecvByteBufAllocator maxBytesPerRead(int maxBytesPerRead) { checkPositive(maxBytesPerRead, "maxBytesPerRead"); // There is a dependency between this.maxBytesPerRead and this.maxBytesPerIndividualRead (a < b). // Write operations must be synchronized, but independent read operations can just be volatile. synchronized (this) { final int maxBytesPerIndividualRead = maxBytesPerIndividualRead(); if (maxBytesPerRead < maxBytesPerIndividualRead) { throw new IllegalArgumentException( "maxBytesPerRead cannot be less than " + "maxBytesPerIndividualRead (" + maxBytesPerIndividualRead + "): " + maxBytesPerRead); } this.maxBytesPerRead = maxBytesPerRead; } return this; }
@Override public DefaultMaxBytesRecvByteBufAllocator maxBytesPerIndividualRead(int maxBytesPerIndividualRead) { checkPositive(maxBytesPerIndividualRead, "maxBytesPerIndividualRead"); // There is a dependency between this.maxBytesPerRead and this.maxBytesPerIndividualRead (a < b). // Write operations must be synchronized, but independent read operations can just be volatile. synchronized (this) { final int maxBytesPerRead = maxBytesPerRead(); if (maxBytesPerIndividualRead > maxBytesPerRead) { throw new IllegalArgumentException( "maxBytesPerIndividualRead cannot be greater than " + "maxBytesPerRead (" + maxBytesPerRead + "): " + maxBytesPerIndividualRead); } this.maxBytesPerIndividualRead = maxBytesPerIndividualRead; } return this; }
/** * Checks that the given argument is neither null nor empty. * If it is, throws {@link NullPointerException} or {@link IllegalArgumentException}. * Otherwise, returns the argument. */ public static <T extends Collection<?>> T checkNonEmpty(T collection, String name) { checkNotNull(collection, name); checkPositive(collection.size(), name + ".size"); return collection; }
/** * Checks that the given argument is neither null nor empty. * If it is, throws {@link NullPointerException} or {@link IllegalArgumentException}. * Otherwise, returns the argument. */ public static <T> T[] checkNonEmpty(T[] array, String name) { checkNotNull(array, name); checkPositive(array.length, name + ".length"); return array; }
/** * Creates a new instance. Be aware that the given {@link EventExecutorGroup} <strong>MUST NOT</strong> contain * any {@link OrderedEventExecutor}s. */ public NonStickyEventExecutorGroup(EventExecutorGroup group, int maxTaskExecutePerRun) { this.group = verify(group); this.maxTaskExecutePerRun = ObjectUtil.checkPositive(maxTaskExecutePerRun, "maxTaskExecutePerRun"); }