本文整理汇总了Java中com.lmax.disruptor.RingBuffer.createMultiProducer方法的典型用法代码示例。如果您正苦于以下问题:Java RingBuffer.createMultiProducer方法的具体用法?Java RingBuffer.createMultiProducer怎么用?Java RingBuffer.createMultiProducer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.RingBuffer
的用法示例。
在下文中一共展示了RingBuffer.createMultiProducer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SingleConsumerDisruptorQueue
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
/**
* Construct a blocking queue based on disruptor.
*
* @param bufferSize
* ring buffer size
* @param singleProducer
* whether only single thread produce events.
*/
public SingleConsumerDisruptorQueue(int bufferSize, boolean singleProducer) {
if (singleProducer) {
ringBuffer = RingBuffer.createSingleProducer(new Factory<T>(), normalizeBufferSize(bufferSize));
} else {
ringBuffer = RingBuffer.createMultiProducer(new Factory<T>(), normalizeBufferSize(bufferSize));
}
consumedSeq = new Sequence();
ringBuffer.addGatingSequences(consumedSeq);
barrier = ringBuffer.newBarrier();
long cursor = ringBuffer.getCursor();
consumedSeq.set(cursor);
knownPublishedSeq = cursor;
}
示例2: RingBufferProvider
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
RingBufferProvider(@Nonnegative final int capacity, @Nonnull final Factory<T> factory,
@Nonnull final MessageBufferConsumer<T> appIn) {
if (appIn == null) {
throw new NullPointerException("appIn == null");
}
this.waitOut = new WakeupWaitStrategy();
this.waitIn = null;
final EventFactory<T> evfactory = wrapFactory(factory);
this.out = RingBuffer.createMultiProducer(evfactory, capacity, waitOut);
this.in = null;
this.attachOut = new Object[capacity];
this.attachIn = null;
this.appOut = new RingBufferProducer<>(out, attachOut);
this.chnIn = new RingBufferConsumer<>(out, attachOut);
this.chnOut = appIn.createProducer();
this.appIn = appIn;
this.internalConsumer = false;
}
示例3: main
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
int batchSize = 40;
RingBuffer<BatchedPoller.DataEvent<Object>> ringBuffer = RingBuffer.createMultiProducer(BatchedPoller.DataEvent.factory(), 1024);
BatchedPoller<Object> poller = new BatchedPoller<Object>(ringBuffer, batchSize);
Object value = poller.poll();
// Value could be null if no events are available.
if (null != value)
{
// Process value.
}
}
示例4: main
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
RingBuffer<DataEvent<Object>> ringBuffer = RingBuffer.createMultiProducer(DataEvent.factory(), 1024);
final EventPoller<DataEvent<Object>> poller = ringBuffer.newPoller();
Object value = getNextValue(poller);
// Value could be null if no events are available.
if (null != value)
{
// Process value.
}
}
示例5: DisruptorMessageQueue
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
DisruptorMessageQueue(int bufferSize, WaitStrategy waitStrategy) {
ringBuffer = RingBuffer.createMultiProducer(EVENT_FACTORY, bufferSize, waitStrategy);
ringBuffer.addGatingSequences(sequence);
sequenceBarrier = ringBuffer.newBarrier();
mask = bufferSize - 1;
buffer = new Envelope[bufferSize];
}
示例6: initialize
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
public boolean initialize(EventsChannelConfig config)
{
super.initialize(config);
log.info("Initialize disruptor events channel " + config.getName() + " with " + config);
EventFactory<GridEvent> eventFactory = new DisruptorEventFactory();
int ringBufferSize = config.getBlockQueueMaxNumber();
int threadSize = config.getEventConsumerNumber();
int bufferSize = ringBufferSize;
if (Integer.bitCount(bufferSize) != 1)
{
bufferSize = (int) Math.pow(2, (int) (Math.log(ringBufferSize) / Math.log(2)));
log.warn("Change disruptor events channel " + config.getName() +
" buffer size from " + ringBufferSize + " to " + bufferSize);
}
if (bufferSize <= 0)
throw new GridException("Invalid disruptor ringbuffur size:" + ringBufferSize);
threadPool = Executors.newFixedThreadPool(threadSize);
ringBuffer = RingBuffer.createMultiProducer(eventFactory, bufferSize, new BlockingWaitStrategy());
SequenceBarrier sequenceBarrier = ringBuffer.newBarrier();
ExecutorService executor = Executors.newFixedThreadPool(10);
@SuppressWarnings("unchecked")
WorkHandler<GridEvent>[] workHandlers = new WorkHandler[threadSize];
for (int i = 0; i < threadSize; i++) {
WorkHandler<GridEvent> workHandler = new DisruptorEventsWorkHandler(getName());
workHandlers[i] = workHandler;
}
workerPool = new WorkerPool<GridEvent>(ringBuffer, sequenceBarrier,
new IgnoreExceptionHandler(), workHandlers);
workerPool.start(executor);
return true;
}
示例7: createConsumer
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static <T> RingBufferConsumer<T> createConsumer(@Nonnegative final int capacity,
@Nonnull final Factory<T> factory) {
final EventFactory<T> evfactory = wrapFactory(factory);
final RingBuffer<T> buffer = RingBuffer.createMultiProducer(evfactory, capacity);
final Object[] attachments = new Object[capacity];
final RingBufferConsumer<T> consumer = new RingBufferConsumer<>(buffer, attachments);
return consumer;
}
示例8: DisruptorEventExecutor
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public DisruptorEventExecutor() {
// ringBuffer = RingBuffer.createMultiProducer(WaitingEvent.EVENT_FACTORY, 128, PhasedBackoffWaitStrategy.withLock(1, 1, TimeUnit.MILLISECONDS));
ringBuffer = RingBuffer.createMultiProducer(WaitingEvent.EVENT_FACTORY, 8192, new BlockingWaitStrategy());
BatchEventProcessor<WaitingEvent> processor = new BatchEventProcessor<WaitingEvent>(ringBuffer, ringBuffer.newBarrier(), new DisruptorHandler());
ringBuffer.addGatingSequences(processor.getSequence());
executeThread = new Thread(processor);
executeThread.setName("disruptEventExecutor");
executeThread.start();
}
示例9: DisruptorExecutor
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public DisruptorExecutor(int threadCount, int bufferSize, WaitStrategy waitStrategy)
{
ringBuffer = RingBuffer.createMultiProducer(new EventFactory<RContainer>()
{
@Override
public RContainer newInstance()
{
return new RContainer();
}
}, bufferSize, waitStrategy);
SequenceBarrier sequenceBarrier = ringBuffer.newBarrier();
Sequence workSequence = new Sequence(-1);
workProcessors = new WorkProcessor[threadCount];
for (int i = 0 ; i < threadCount ; i++)
{
workProcessors[i] = new WorkProcessor<RContainer>(ringBuffer, sequenceBarrier,
handler, new IgnoreExceptionHandler(), workSequence);
}
workExec = Executors.newFixedThreadPool(workProcessors.length, new ThreadFactory()
{
public Thread newThread(Runnable r)
{
Thread t = new Thread(r);
t.setDaemon(true);
return t;
}
});
for (WorkProcessor p : workProcessors)
workExec.execute(p);
}
示例10: AsyncFSWAL
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public AsyncFSWAL(FileSystem fs, Path rootDir, String logDir, String archiveDir,
Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists,
String prefix, String suffix, EventLoopGroup eventLoopGroup,
Class<? extends Channel> channelClass) throws FailedLogCloseException, IOException {
super(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix, suffix);
this.eventLoopGroup = eventLoopGroup;
this.channelClass = channelClass;
Supplier<Boolean> hasConsumerTask;
if (conf.getBoolean(ASYNC_WAL_USE_SHARED_EVENT_LOOP, DEFAULT_ASYNC_WAL_USE_SHARED_EVENT_LOOP)) {
this.consumeExecutor = eventLoopGroup.next();
if (consumeExecutor instanceof SingleThreadEventExecutor) {
try {
Field field = SingleThreadEventExecutor.class.getDeclaredField("taskQueue");
field.setAccessible(true);
Queue<?> queue = (Queue<?>) field.get(consumeExecutor);
hasConsumerTask = () -> queue.peek() == consumer;
} catch (Exception e) {
LOG.warn("Can not get task queue of " + consumeExecutor +
", this is not necessary, just give up", e);
hasConsumerTask = () -> false;
}
} else {
hasConsumerTask = () -> false;
}
} else {
ThreadPoolExecutor threadPool =
new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),
new ThreadFactoryBuilder().setNameFormat("AsyncFSWAL-%d").setDaemon(true).build());
hasConsumerTask = () -> threadPool.getQueue().peek() == consumer;
this.consumeExecutor = threadPool;
}
this.hasConsumerTask = hasConsumerTask;
int preallocatedEventCount =
conf.getInt("hbase.regionserver.wal.disruptor.event.count", 1024 * 16);
waitingConsumePayloads =
RingBuffer.createMultiProducer(RingBufferTruck::new, preallocatedEventCount);
waitingConsumePayloadsGatingSequence = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);
waitingConsumePayloads.addGatingSequences(waitingConsumePayloadsGatingSequence);
// inrease the ringbuffer sequence so our txid is start from 1
waitingConsumePayloads.publish(waitingConsumePayloads.next());
waitingConsumePayloadsGatingSequence.set(waitingConsumePayloads.getCursor());
batchSize = conf.getLong(WAL_BATCH_SIZE, DEFAULT_WAL_BATCH_SIZE);
waitOnShutdownInSeconds = conf.getInt(ASYNC_WAL_WAIT_ON_SHUTDOWN_IN_SECONDS,
DEFAULT_ASYNC_WAL_WAIT_ON_SHUTDOWN_IN_SECONDS);
rollWriter();
}
示例11: RequestQueueProcessor
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
/**
* @param maxQueueSz
* @param numThreads
* @param name
*/
public RequestQueueProcessor(int maxQueueSz, int numThreads, String name) {
m_name = name;
m_maxQueueSz = maxQueueSz;
m_ringBuffer = RingBuffer.createMultiProducer(m_eventFactory,
normalizeBufferSize(m_maxQueueSz), new BlockingWaitStrategy());
m_barrier = m_ringBuffer.newBarrier();
m_numThreads = numThreads;
QueueProcessorWorkHandler[] handlers = new QueueProcessorWorkHandler[m_numThreads];
for (int i = 0; i < m_numThreads; i++) {
handlers[i] = new QueueProcessorWorkHandler();
}
m_worker = new WorkerPool(m_ringBuffer, m_barrier,
new QueueProcessorExceptionHandler(m_dropCounter, name),
handlers);
m_ringBuffer.addGatingSequences(m_worker.getWorkerSequences());
m_executor = Executors.newFixedThreadPool(m_numThreads,
new NameableThreadFactory(name));
m_ringBuffer = m_worker.start(m_executor);
}
示例12: Disruptor
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
/**
* Create a new Disruptor. Will default to {@link com.lmax.disruptor.BlockingWaitStrategy} and
* {@link ProducerType}.MULTI
*
* @param eventFactory the factory to create events in the ring buffer.
* @param ringBufferSize the size of the ring buffer.
* @param executor an {@link Executor} to execute event processors.
* @deprecated Use a {@link ThreadFactory} instead of an {@link Executor} as a the ThreadFactory
* is able to report errors then it is unable to construct a thread to run a producer.
*/
@Deprecated
public Disruptor(final EventFactory<T> eventFactory, final int ringBufferSize, final Executor executor) {
this(RingBuffer.createMultiProducer(eventFactory, ringBufferSize), executor);
}