当前位置: 首页>>代码示例>>Java>>正文


Java Queues.isPowerOfTwo方法代码示例

本文整理汇总了Java中reactor.util.concurrent.Queues.isPowerOfTwo方法的典型用法代码示例。如果您正苦于以下问题:Java Queues.isPowerOfTwo方法的具体用法?Java Queues.isPowerOfTwo怎么用?Java Queues.isPowerOfTwo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reactor.util.concurrent.Queues的用法示例。


在下文中一共展示了Queues.isPowerOfTwo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSingleProducer

import reactor.util.concurrent.Queues; //导入方法依赖的package包/类
/**
 * Create a new single producer RingBuffer with the specified wait strategy.
    * <p>See {@code MultiProducerRingBuffer}.
    * @param <E> the element type
 * @param factory used to create the events within the ring buffer.
 * @param bufferSize number of elements to create within the ring buffer.
 * @param waitStrategy used to determine how to wait for new elements to become available.
 * @param spinObserver called each time the next claim is spinning and waiting for a slot
    * @return the new RingBuffer instance
 */
static <E> RingBuffer<E> createSingleProducer(Supplier<E> factory,
		int bufferSize,
		WaitStrategy waitStrategy,
		@Nullable Runnable spinObserver) {
	SingleProducerSequencer sequencer = new SingleProducerSequencer(bufferSize, waitStrategy, spinObserver);

	if (hasUnsafe() && Queues.isPowerOfTwo(bufferSize)) {
		return new UnsafeRingBuffer<>(factory, sequencer);
	}
	else {
		return new NotFunRingBuffer<>(factory, sequencer);
	}
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:24,代码来源:RingBuffer.java

示例2: EventLoopProcessor

import reactor.util.concurrent.Queues; //导入方法依赖的package包/类
EventLoopProcessor(
		int bufferSize,
		@Nullable ThreadFactory threadFactory,
		@Nullable ExecutorService executor,
		ExecutorService requestExecutor,
		boolean autoCancel,
		boolean multiproducers,
		Supplier<Slot<IN>> factory,
		WaitStrategy strategy) {

	if (!Queues.isPowerOfTwo(bufferSize)) {
		throw new IllegalArgumentException("bufferSize must be a power of 2 : " + bufferSize);
	}

	if (bufferSize < 1){
		throw new IllegalArgumentException("bufferSize must be strictly positive, " +
				"was: "+bufferSize);
	}

	this.autoCancel = autoCancel;

	contextClassLoader = new EventLoopContext(multiproducers);

	this.name = defaultName(threadFactory, getClass());

	this.requestTaskExecutor = Objects.requireNonNull(requestExecutor, "requestTaskExecutor");

	if (executor == null) {
		this.executor = Executors.newCachedThreadPool(threadFactory);
	}
	else {
		this.executor = executor;
	}

	if (multiproducers) {
		this.ringBuffer = RingBuffer.createMultiProducer(factory,
				bufferSize,
				strategy,
				this);
	}
	else {
		this.ringBuffer = RingBuffer.createSingleProducer(factory,
				bufferSize,
				strategy,
				this);
	}
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:48,代码来源:EventLoopProcessor.java


注:本文中的reactor.util.concurrent.Queues.isPowerOfTwo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。