Java Code Examples for com.lmax.disruptor.RingBuffer#publishEvent()
The following examples show how to use
com.lmax.disruptor.RingBuffer#publishEvent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LongEventMain.java From elastic-rabbitmq with MIT License | 6 votes |
public static void main(String[] args) throws Exception { Executor executor = Executors.newCachedThreadPool(); LongEventFactory eventFactory = new LongEventFactory(); int bufferSize = 1024; // Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(eventFactory, bufferSize, executor); // disruptor.handleEventsWith(new LongEventHandler()); // disruptor.start(); Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, bufferSize, executor); disruptor.handleEventsWith((event, sequence, endOfBatch) -> {System.out.println("Event: " + event); System.out.println("CurrentThreadName:" + Thread.currentThread().getName()); }); disruptor.start(); RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer(); LongEventProducer producer = new LongEventProducer(ringBuffer); ByteBuffer bb = ByteBuffer.allocate(8); for (long l = 0; true; l++) { bb.putLong(0, l); ringBuffer.publishEvent((event, sequence, buffer) -> event.set(buffer.getLong(0)), bb); // producer.onData(bb); //Thread.sleep(1000); } }
Example 2
Source File: TxTransactionEventPublisher.java From Raincat with GNU Lesser General Public License v3.0 | 5 votes |
/** * publish disruptor event. * * @param transactionRecover {@linkplain TransactionRecover } * @param type {@linkplain CompensationActionEnum} */ public void publishEvent(final TransactionRecover transactionRecover, final int type) { if (txConfig.getCompensation()) { final RingBuffer<TxTransactionEvent> ringBuffer = disruptor.getRingBuffer(); ringBuffer.publishEvent(new TxTransactionEventTranslator(type), transactionRecover); } }
Example 3
Source File: ThreadBoundExecutorImpl.java From elasticactors with Apache License 2.0 | 5 votes |
@Override public void execute(ThreadBoundEvent event) { if (shuttingDown.get()) { throw new RejectedExecutionException("The system is shutting down."); } if (event instanceof ThreadBoundRunnable) { event = wrap((ThreadBoundRunnable<?>) event); } final RingBuffer<ThreadBoundEventWrapper> ringBuffer = this.disruptors.get(getBucket(event.getKey())).getRingBuffer(); // this method will wait when the buffer is overflowing ( using Lock.parkNanos(1) ) ringBuffer.publishEvent(translator, event); }
Example 4
Source File: LogEventPublisher.java From fast-family-master with Apache License 2.0 | 4 votes |
public void publishEvent(AccessLogInfo accessLogInfo) { RingBuffer<LogEvent> ringBuffer = disruptor.getRingBuffer(); ringBuffer.publishEvent(new LogEventTranslator(), accessLogInfo); }
Example 5
Source File: MythTransactionEventPublisher.java From myth with Apache License 2.0 | 2 votes |
/** * publish disruptor event. * * @param mythTransaction {@linkplain MythTransaction } * @param type {@linkplain EventTypeEnum} */ public void publishEvent(final MythTransaction mythTransaction, final int type) { final RingBuffer<MythTransactionEvent> ringBuffer = disruptor.getRingBuffer(); ringBuffer.publishEvent(new MythTransactionEventTranslator(type), mythTransaction); }