本文整理汇总了Java中com.lmax.disruptor.RingBuffer类的典型用法代码示例。如果您正苦于以下问题:Java RingBuffer类的具体用法?Java RingBuffer怎么用?Java RingBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RingBuffer类属于com.lmax.disruptor包,在下文中一共展示了RingBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelRead0
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, O msg) throws Exception {
UUID uuid = CHANNEL_UUID.get(ctx.channel());
if (null != uuid) {
Session session = SESSIONS.get(uuid);
if (null != session) {
RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer();
long next = ringBuffer.next();
try {
ConcurrentEvent commandEvent = ringBuffer.get(next);
commandEvent.setValues(newExecutor(session, msg));
} finally {
ringBuffer.publish(next);
}
}
}
}
示例2: channelRead0
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, O msg) throws Exception {
UUID uuid = CHANNEL_UUID.get(ctx.channel());
if (null != uuid) {
NetSession session = SESSIONS.get(uuid);
if (null != session) {
RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer();
long next = ringBuffer.next();
try {
ConcurrentEvent commandEvent = ringBuffer.get(next);
commandEvent.setValues(newExecutor(session, msg));
} finally {
ringBuffer.publish(next);
}
}
}
}
示例3: 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]);
// }
}
示例4: shouldSupportCustomProcessorsAsDependencies
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@Test
public void shouldSupportCustomProcessorsAsDependencies()
throws Exception
{
RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
CountDownLatch countDownLatch = new CountDownLatch(2);
EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
final BatchEventProcessor<TestEvent> processor =
new BatchEventProcessor<TestEvent>(ringBuffer, ringBuffer.newBarrier(), delayedEventHandler);
disruptor.handleEventsWith(processor);
disruptor.after(processor).handleEventsWith(handlerWithBarrier);
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
示例5: shouldSupportHandlersAsDependenciesToCustomProcessors
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@Test
public void shouldSupportHandlersAsDependenciesToCustomProcessors()
throws Exception
{
final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
disruptor.handleEventsWith(delayedEventHandler);
RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
CountDownLatch countDownLatch = new CountDownLatch(2);
EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler).asSequenceBarrier();
final BatchEventProcessor<TestEvent> processor =
new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, handlerWithBarrier);
disruptor.handleEventsWith(processor);
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
示例6: shouldSupportCustomProcessorsAndHandlersAsDependencies
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@Test
public void shouldSupportCustomProcessorsAndHandlersAsDependencies() throws Exception
{
final DelayedEventHandler delayedEventHandler1 = createDelayedEventHandler();
final DelayedEventHandler delayedEventHandler2 = createDelayedEventHandler();
disruptor.handleEventsWith(delayedEventHandler1);
RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
CountDownLatch countDownLatch = new CountDownLatch(2);
EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler1).asSequenceBarrier();
final BatchEventProcessor<TestEvent> processor =
new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, delayedEventHandler2);
disruptor.after(delayedEventHandler1).and(processor).handleEventsWith(handlerWithBarrier);
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2);
}
示例7: shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@Test
public void shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately() throws Exception
{
final CountDownLatch countDownLatch = new CountDownLatch(2);
final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
disruptor.handleEventsWith(
new EventProcessorFactory<TestEvent>()
{
@Override
public EventProcessor createEventProcessor(
final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences)
{
assertEquals("Should not have had any barrier sequences", 0, barrierSequences.length);
return new BatchEventProcessor<TestEvent>(
disruptor.getRingBuffer(), ringBuffer.newBarrier(
barrierSequences), eventHandler);
}
});
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch);
}
示例8: shouldHonourDependenciesForCustomProcessors
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@Test
public void shouldHonourDependenciesForCustomProcessors() throws Exception
{
final CountDownLatch countDownLatch = new CountDownLatch(2);
final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
disruptor.handleEventsWith(delayedEventHandler).then(
new EventProcessorFactory<TestEvent>()
{
@Override
public EventProcessor createEventProcessor(
final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences)
{
assertSame("Should have had a barrier sequence", 1, barrierSequences.length);
return new BatchEventProcessor<TestEvent>(
disruptor.getRingBuffer(), ringBuffer.newBarrier(
barrierSequences), eventHandler);
}
});
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
示例9: DisruptorTransfer
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DisruptorTransfer(final SpanEventHandler spanEventHandler, final int buffSize) {
// Executor executor = Executors.newCachedThreadPool();
final ThreadFactory threadFactory = Executors.defaultThreadFactory();
// The factory for the event
final SpanEventFactory factory = new SpanEventFactory();
// Specify the size of the ring buffer, must be power of 2.
final int bufferSize = buffSize;
// Construct the Disruptor
disruptor = new Disruptor<SpanEvent>(factory, bufferSize, threadFactory);
// Connect the handler
// disruptor.handleEventsWith(new
// SpanEventHandler("http://localhost:9080/upload"));
disruptor.handleEventsWith(spanEventHandler);
// Start the Disruptor, starts all threads running
disruptor.start();
final RingBuffer<SpanEvent> ringBuffer = disruptor.getRingBuffer();
producer = new SpanEventProducer(ringBuffer);
}
示例10: RingBufferProcessor
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
private RingBufferProcessor(String name,
ExecutorService executor,
int bufferSize,
WaitStrategy waitStrategy,
boolean shared,
boolean autoCancel) {
super(name, executor, autoCancel);
this.ringBuffer = RingBuffer.create(
shared ? ProducerType.MULTI : ProducerType.SINGLE,
new EventFactory<MutableSignal<E>>() {
@Override
public MutableSignal<E> newInstance() {
return new MutableSignal<E>();
}
},
bufferSize,
waitStrategy
);
this.recentSequence = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);
this.barrier = ringBuffer.newBarrier();
//ringBuffer.addGatingSequences(recentSequence);
}
示例11: RingBufferWorkProcessor
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
private RingBufferWorkProcessor(String name,
ExecutorService executor,
int bufferSize,
WaitStrategy waitStrategy,
boolean share,
boolean autoCancel) {
super(name, executor, autoCancel);
this.ringBuffer = RingBuffer.create(
share ? ProducerType.MULTI : ProducerType.SINGLE,
new EventFactory<MutableSignal<E>>() {
@Override
public MutableSignal<E> newInstance() {
return new MutableSignal<E>();
}
},
bufferSize,
waitStrategy
);
ringBuffer.addGatingSequences(workSequence);
}
示例12: init
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
/**
* Init method.
*
* @return
*/
public DisruptorQueue<ID, DATA> init() {
/* single producer "seems" to offer better performance */
ringBuffer = RingBuffer.createSingleProducer(EVENT_FACTORY, ringSize);
// ringBuffer = RingBuffer.createMultiProducer(EVENT_FACTORY, ringSize);
if (!isEphemeralDisabled()) {
int ephemeralBoundSize = Math.max(0, getEphemeralMaxSize());
ephemeralStorage = new ConcurrentHashMap<>(
ephemeralBoundSize > 0 ? Math.min(ephemeralBoundSize, ringSize) : ringSize);
}
consumedSeq = new Sequence();
ringBuffer.addGatingSequences(consumedSeq);
long cursor = ringBuffer.getCursor();
consumedSeq.set(cursor);
knownPublishedSeq = cursor;
return this;
}
示例13: 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;
}
示例14: post
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
public void post(Object event) {
Class<?> eventClass = event.getClass();
Disruptor<BaseEvent> eventDisruptor = disruptorPool.get(eventClass);
if(eventDisruptor == null) {
List<RegistedEventHandler> registedEventHandlers = handlesMap.get(eventClass);
if(registedEventHandlers == null || registedEventHandlers.size() == 0) {
throw new RuntimeException("The " + eventClass.getSimpleName() + " event dosen't regist any eventHandler.");
}
eventDisruptor = createDisruptor(eventClass, registedEventHandlers);
disruptorPool.put(eventClass, eventDisruptor);
}
// check whether has event Repository definition.
if(eventRepository != null) {
eventRepository.save(event);
}
RingBuffer<BaseEvent> ringBuffer = eventDisruptor.getRingBuffer();
BaseEventProducer producer = new BaseEventProducer(ringBuffer);
producer.onData(event);
}
示例15: stampSequenceIdAndPublishToRingBuffer
import com.lmax.disruptor.RingBuffer; //导入依赖的package包/类
protected final long stampSequenceIdAndPublishToRingBuffer(RegionInfo hri, WALKeyImpl key,
WALEdit edits, boolean inMemstore, RingBuffer<RingBufferTruck> ringBuffer)
throws IOException {
if (this.closed) {
throw new IOException(
"Cannot append; log is closed, regionName = " + hri.getRegionNameAsString());
}
MutableLong txidHolder = new MutableLong();
MultiVersionConcurrencyControl.WriteEntry we = key.getMvcc().begin(() -> {
txidHolder.setValue(ringBuffer.next());
});
long txid = txidHolder.longValue();
try (TraceScope scope = TraceUtil.createTrace(implClassName + ".append")) {
FSWALEntry entry = new FSWALEntry(txid, key, edits, hri, inMemstore);
entry.stampRegionSequenceId(we);
ringBuffer.get(txid).load(entry);
} finally {
ringBuffer.publish(txid);
}
return txid;
}