本文整理汇总了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);
}
}
示例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);
}
}