Java Code Examples for io.netty.util.internal.ObjectUtil#checkPositive()

The following examples show how to use io.netty.util.internal.ObjectUtil#checkPositive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Lz4FrameEncoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
     * Creates a new customizable LZ4 encoder.创建一个新的可定制的LZ4编码器。
     *
     * @param factory         user customizable {@link LZ4Factory} instance
     *                        which may be JNI bindings to the original C implementation, a pure Java implementation
     *                        or a Java implementation that uses the {@link sun.misc.Unsafe}
     * @param highCompressor  if {@code true} codec will use compressor which requires more memory
     *                        and is slower but compresses more efficiently
     * @param blockSize       the maximum number of bytes to try to compress at once,
     *                        must be >= 64 and <= 32 M
     * @param checksum        the {@link Checksum} instance to use to check data for integrity
     * @param maxEncodeSize   the maximum size for an encode (compressed) buffer
     */
public Lz4FrameEncoder(LZ4Factory factory, boolean highCompressor, int blockSize,
                       Checksum checksum, int maxEncodeSize) {
    if (factory == null) {
        throw new NullPointerException("factory");
    }
    if (checksum == null) {
        throw new NullPointerException("checksum");
    }

    compressor = highCompressor ? factory.highCompressor() : factory.fastCompressor();
    this.checksum = ByteBufChecksum.wrapChecksum(checksum);

    compressionLevel = compressionLevel(blockSize);
    this.blockSize = blockSize;
    this.maxEncodeSize = ObjectUtil.checkPositive(maxEncodeSize, "maxEncodeSize");
    finished = false;
}
 
Example 2
Source File: RejectedExecutionHandlers.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to backoff when the task can not be added due restrictions for an configured amount of time. This
 * is only done if the task was added from outside of the event loop which means
 * {@link EventExecutor#inEventLoop()} returns {@code false}.
 * 尝试在任务无法被添加时进行回退,这是对已配置的时间的适当限制。这只在从事件循环外部添加任务时完成,这意味着EventExecutor.inEventLoop()返回false。
 */
public static RejectedExecutionHandler backoff(final int retries, long backoffAmount, TimeUnit unit) {
    ObjectUtil.checkPositive(retries, "retries");
    final long backOffNanos = unit.toNanos(backoffAmount);
    return new RejectedExecutionHandler() {
        @Override
        public void rejected(Runnable task, SingleThreadEventExecutor executor) {
            if (!executor.inEventLoop()) {
                for (int i = 0; i < retries; i++) {
                    // Try to wake up the executor so it will empty its task queue.
                    executor.wakeup(false);

                    LockSupport.parkNanos(backOffNanos);
                    if (executor.offerTask(task)) {
                        return;
                    }
                }
            }
            // Either we tried to add the task from within the EventLoop or we was not able to add it even with
            // backoff.
            throw new RejectedExecutionException();
        }
    };
}
 
Example 3
Source File: NettyRuntime.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the number of available processors.
 *
 * @param availableProcessors the number of available processors
 * @throws IllegalArgumentException if the specified number of available processors is non-positive
 * @throws IllegalStateException    if the number of available processors is already configured
 */
synchronized void setAvailableProcessors(final int availableProcessors) {
    ObjectUtil.checkPositive(availableProcessors, "availableProcessors");
    if (this.availableProcessors != 0) {
        final String message = String.format(
                Locale.ROOT,
                "availableProcessors is already set to [%d], rejecting [%d]",
                this.availableProcessors,
                availableProcessors);
        throw new IllegalStateException(message);
    }
    this.availableProcessors = availableProcessors;
}
 
Example 4
Source File: ZstdEncoder.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
public ZstdEncoder(int blockSize, int maxEncodeSize) {
    super(true);
    compressionLevel = compressionLevel(blockSize);
    this.blockSize = blockSize;
    this.maxEncodeSize = ObjectUtil.checkPositive(maxEncodeSize, "maxEncodeSize");
    finished = false;
}
 
Example 5
Source File: HpackHuffmanDecoder.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
DecoderProcessor(int initialCapacity) {
    this.initialCapacity = ObjectUtil.checkPositive(initialCapacity, "initialCapacity");
}
 
Example 6
Source File: Http2ControlFrameLimitEncoder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
Http2ControlFrameLimitEncoder(Http2ConnectionEncoder delegate, int maxOutstandingControlFrames) {
    super(delegate);
    this.maxOutstandingControlFrames = ObjectUtil.checkPositive(maxOutstandingControlFrames,
            "maxOutstandingControlFrames");
}
 
Example 7
Source File: NonStickyEventExecutorGroup.java    From netty-4.1.22 with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance. Be aware that the given {@link EventExecutorGroup} <strong>MUST NOT</strong> contain
 * any {@link OrderedEventExecutor}s.
 * 创建一个新的实例。请注意,给定的EventExecutorGroup不能包含任何orderedeventexecutor。
 */
public NonStickyEventExecutorGroup(EventExecutorGroup group, int maxTaskExecutePerRun) {
    this.group = verify(group);
    this.maxTaskExecutePerRun = ObjectUtil.checkPositive(maxTaskExecutePerRun, "maxTaskExecutePerRun");
}