本文整理汇总了Java中com.lmax.disruptor.RingBuffer.addGatingSequences方法的典型用法代码示例。如果您正苦于以下问题:Java RingBuffer.addGatingSequences方法的具体用法?Java RingBuffer.addGatingSequences怎么用?Java RingBuffer.addGatingSequences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.RingBuffer
的用法示例。
在下文中一共展示了RingBuffer.addGatingSequences方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startup
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
public void startup() {
EventBus eventBus = disruptorDispatchThread.getEventBus();
executorService = new NonOrderedQueuePoolExecutor(poolName, excutorSize);
cycleEventHandler = new CycleEventHandler[excutorSize];
for(int i = 0; i < excutorSize; i++){
cycleEventHandler[i] = new CycleEventHandler(eventBus);
}
RingBuffer ringBuffer = disruptorDispatchThread.getRingBuffer();
workerPool = new WorkerPool(ringBuffer, ringBuffer.newBarrier(), new FatalExceptionHandler(), cycleEventHandler);
ringBuffer.addGatingSequences(workerPool.getWorkerSequences());
workerPool.start(executorService);
// BatchEventProcessor<CycleEvent>[] batchEventProcessors = new BatchEventProcessor[excutorSize];
// for(int i = 0; i < excutorSize; i++){
// batchEventProcessors[i] = new BatchEventProcessor<>(ringBuffer, sequenceBarrier, cycleEventHandler[i]);
// ringBuffer.addGatingSequences(batchEventProcessors[i].getSequence());
//// executorService.submit(batchEventProcessors[i]);
// }
}
示例2: RingBufferConsumer
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
RingBufferConsumer(@Nonnull final RingBuffer<T> buffer, @Nonnull final Object[] attachments) {
if (buffer == null) {
throw new NullPointerException("buffer == null");
}
if (attachments == null) {
throw new NullPointerException("attachments == null");
}
if (buffer.getBufferSize() != attachments.length) {
throw new IllegalArgumentException("buffer.getBufferSize() != attachments.length");
}
this.buffer = buffer;
this.attachments = attachments;
this.barrier = buffer.newBarrier();
this.sequence = new Sequence();
buffer.addGatingSequences(sequence);
this.cursor = sequence.get();
this.available = sequence.get();
}
示例3: BatchedPoller
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public BatchedPoller(RingBuffer<BatchedPoller.DataEvent<T>> ringBuffer, int batchSize)
{
this.poller = ringBuffer.newPoller();
ringBuffer.addGatingSequences(poller.getSequence());
if (batchSize < 1)
{
batchSize = 20;
}
this.maxBatchSize = batchSize;
this.polledData = new BatchedData<T>(this.maxBatchSize);
}
示例4: main
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static void main(String[] args) {
final List<ValueEventHandler1PMC> handlers = new ArrayList<>(NUMBER_CONSUMERS);
RingBuffer<ValueEvent> ringBuffer = RingBuffer.createSingleProducer(
ValueEvent.EVENT_FACTORY, RING_SIZE, new SleepingWaitStrategy());
start = System.nanoTime();
//Create consumers
for(int i = 0; i < NUMBER_CONSUMERS; i++) {
ValueEventHandler1PMC handler = new ValueEventHandler1PMC(start, handlers);
handlers.add(handler);
SequenceBarrier barrier = ringBuffer.newBarrier();
BatchEventProcessor<ValueEvent> eventProcessor = new BatchEventProcessor<ValueEvent>(
ringBuffer, barrier, handler);
ringBuffer.addGatingSequences(eventProcessor.getSequence());
// Each EventProcessor can run on a separate thread
EXECUTOR.submit(eventProcessor);
}
for(int i = 0; i < SAMPLES_SIZE; i++) {
// Publishers claim events in sequence
long sequence = ringBuffer.next();
ValueEvent event = ringBuffer.get(sequence);
event.setValue(i); // this could be more complex with multiple fields
// make the event available to EventProcessors
ringBuffer.publish(sequence);
}
}
示例5: main
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static void main(String[] args) {
RingBuffer<ValueEvent> ringBuffer = RingBuffer.createSingleProducer(
ValueEvent.EVENT_FACTORY, RING_SIZE, new SleepingWaitStrategy());
start = System.nanoTime();
//Create first consumer
ValueEventHandler1PMCSequenceFirst handler = new ValueEventHandler1PMCSequenceFirst(start);
SequenceBarrier barrier;
barrier = ringBuffer.newBarrier();
BatchEventProcessor<ValueEvent> firstEventProcessor = new BatchEventProcessor<ValueEvent>(
ringBuffer, barrier, handler);
// ringBuffer.addGatingSequences(firstEventProcessor.getSequence());
// Each EventProcessor can run on a separate thread
EXECUTOR.submit(firstEventProcessor);
//Create second consumer
ValueEventHandler1PMCSequenceSecond handler2 = new ValueEventHandler1PMCSequenceSecond(start);
SequenceBarrier barrier2 = ringBuffer.newBarrier(firstEventProcessor.getSequence());
BatchEventProcessor<ValueEvent> secondEventProcessor = new BatchEventProcessor<ValueEvent>(
ringBuffer, barrier2, handler2);
ringBuffer.addGatingSequences(secondEventProcessor.getSequence());
// Each EventProcessor can run on a separate thread
EXECUTOR.submit(secondEventProcessor);
for(int i = 0; i < SAMPLES_SIZE; i++) {
// Publishers claim events in sequence
long sequence = ringBuffer.next();
ValueEvent event = ringBuffer.get(sequence);
event.setValue(i); // this could be more complex with multiple fields
// make the event available to EventProcessors
ringBuffer.publish(sequence);
}
}