Java Code Examples for com.lmax.disruptor.RingBuffer#publish()
The following examples show how to use
com.lmax.disruptor.RingBuffer#publish() .
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: AbstractFSWAL.java From hbase with Apache License 2.0 | 6 votes |
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(); ServerCall<?> rpcCall = RpcServer.getCurrentCall().filter(c -> c instanceof ServerCall) .filter(c -> c.getCellScanner() != null).map(c -> (ServerCall) c).orElse(null); try (TraceScope scope = TraceUtil.createTrace(implClassName + ".append")) { FSWALEntry entry = new FSWALEntry(txid, key, edits, hri, inMemstore, rpcCall); entry.stampRegionSequenceId(we); ringBuffer.get(txid).load(entry); } finally { ringBuffer.publish(txid); } return txid; }
Example 2
Source File: BenchmarkHandler.java From Okra with Apache License 2.0 | 6 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer(); long next = ringBuffer.next(); try { ConcurrentEvent commandEvent = ringBuffer.get(next); commandEvent.setValues(new Executor() { @Override public void onExecute() { ctx.channel().writeAndFlush(msg); } @Override public void release() { } }); } finally { ringBuffer.publish(next); } }
Example 3
Source File: DisruptorAdapterHandler.java From Okra with Apache License 2.0 | 6 votes |
@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); } } } }
Example 4
Source File: FastEventServiceImpl.java From redtorch with MIT License | 6 votes |
@Override public void emitContract(ContractField contract) { // 发送事件 RingBuffer<FastEvent> ringBuffer = getRingBuffer(); long sequence = ringBuffer.next(); // Grab the next sequence try { FastEvent fastEvent = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence fastEvent.setObj(contract); fastEvent.setEvent(contract.getContractId()); fastEvent.setFastEventType(FastEventType.CONTRACT); } finally { ringBuffer.publish(sequence); } }
Example 5
Source File: FastEventServiceImpl.java From redtorch with MIT License | 6 votes |
@Override public void emitTick(TickField tick) { RingBuffer<FastEvent> ringBuffer = getRingBuffer(); long sequence = ringBuffer.next(); // Grab the next sequence try { FastEvent fastEvent = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence fastEvent.setObj(tick); fastEvent.setEvent(tick.getUnifiedSymbol()+"@"+tick.getGatewayId()); fastEvent.setFastEventType(FastEventType.TICK); } finally { ringBuffer.publish(sequence); } }
Example 6
Source File: FastEventServiceImpl.java From redtorch with MIT License | 6 votes |
@Override public void emitTrade(TradeField trade) { // 发送特定合约成交事件 RingBuffer<FastEvent> ringBuffer = getRingBuffer(); long sequence = ringBuffer.next(); // Grab the next sequence try { FastEvent fastEvent = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence fastEvent.setObj(trade); fastEvent.setEvent(trade.getOriginOrderId()); fastEvent.setFastEventType(FastEventType.TRADE); } finally { ringBuffer.publish(sequence); } }
Example 7
Source File: FastEventServiceImpl.java From redtorch with MIT License | 6 votes |
@Override public void emitOrder(OrderField order) { // 发送带定单ID的事件 RingBuffer<FastEvent> ringBuffer = getRingBuffer(); long sequence = ringBuffer.next(); // Grab the next sequence try { FastEvent fastEvent = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence fastEvent.setObj(order); fastEvent.setEvent(order.getOriginOrderId()); fastEvent.setFastEventType(FastEventType.ORDER); } finally { ringBuffer.publish(sequence); } }
Example 8
Source File: FastEventServiceImpl.java From redtorch with MIT License | 6 votes |
@Override public void emitNotice(NoticeField notice) { RingBuffer<FastEvent> ringBuffer = getRingBuffer(); long sequence = ringBuffer.next(); // Grab the next sequence try { FastEvent fastEvent = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence fastEvent.setObj(notice); fastEvent.setEvent(FastEventType.NOTICE.getDeclaringClass().getName()); fastEvent.setFastEventType(FastEventType.NOTICE); } finally { ringBuffer.publish(sequence); } }
Example 9
Source File: TaskDispatcher.java From sofa-jraft with Apache License 2.0 | 6 votes |
@Override public boolean dispatch(final Runnable message) { final RingBuffer<MessageEvent<Runnable>> ringBuffer = disruptor.getRingBuffer(); try { final long sequence = ringBuffer.tryNext(); try { final MessageEvent<Runnable> event = ringBuffer.get(sequence); event.setMessage(message); } finally { ringBuffer.publish(sequence); } return true; } catch (final InsufficientCapacityException e) { // This exception is used by the Disruptor as a global goto. It is a singleton // and has no stack trace. Don't worry about performance. return false; } }
Example 10
Source File: TaskDispatcher.java From Jupiter with Apache License 2.0 | 6 votes |
@Override public boolean dispatch(Runnable message) { RingBuffer<MessageEvent<Runnable>> ringBuffer = disruptor.getRingBuffer(); try { long sequence = ringBuffer.tryNext(); try { MessageEvent<Runnable> event = ringBuffer.get(sequence); event.setMessage(message); } finally { ringBuffer.publish(sequence); } return true; } catch (InsufficientCapacityException e) { // 这个异常是Disruptor当做全局goto使用的, 是单例的并且没有堆栈信息, 不必担心抛出异常的性能问题 return false; } }
Example 11
Source File: DisruptorEventQueue.java From opencensus-java with Apache License 2.0 | 5 votes |
private static DisruptorEventQueue create() { // Create new Disruptor for processing. Note that Disruptor creates a single thread per // consumer (see https://github.com/LMAX-Exchange/disruptor/issues/121 for details); // this ensures that the event handler can take unsynchronized actions whenever possible. Disruptor<DisruptorEvent> disruptor = new Disruptor<>( DisruptorEventFactory.INSTANCE, DISRUPTOR_BUFFER_SIZE, new DaemonThreadFactory("OpenCensus.Disruptor"), ProducerType.MULTI, new SleepingWaitStrategy(0, 1000 * 1000)); disruptor.handleEventsWith(new DisruptorEventHandler[] {DisruptorEventHandler.INSTANCE}); disruptor.start(); final RingBuffer<DisruptorEvent> ringBuffer = disruptor.getRingBuffer(); DisruptorEnqueuer enqueuer = new DisruptorEnqueuer() { @Override public void enqueue(Entry entry) { long sequence = ringBuffer.next(); try { DisruptorEvent event = ringBuffer.get(sequence); event.setEntry(entry); } finally { ringBuffer.publish(sequence); } } }; return new DisruptorEventQueue(disruptor, enqueuer); }
Example 12
Source File: DisruptorAdapterBy41xHandler.java From Okra with Apache License 2.0 | 5 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, O msg) throws Exception { Session session = SESSIONS.get(ctx.channel().id()); if (null == session) { return; } 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); } }
Example 13
Source File: SingleEventProducer.java From tutorials with MIT License | 5 votes |
private void produce(final RingBuffer<ValueEvent> ringBuffer, final int count) { for (int i = 0; i < count; i++) { final long seq = ringBuffer.next(); final ValueEvent valueEvent = ringBuffer.get(seq); valueEvent.setValue(i); ringBuffer.publish(seq); } }
Example 14
Source File: SlowLogRecorder.java From hbase with Apache License 2.0 | 5 votes |
/** * Add slow log rpcCall details to ringbuffer * * @param rpcLogDetails all details of rpc call that would be useful for ring buffer * consumers */ public void addSlowLogPayload(RpcLogDetails rpcLogDetails) { if (!isOnlineLogProviderEnabled) { return; } RingBuffer<RingBufferEnvelope> ringBuffer = this.disruptor.getRingBuffer(); long seqId = ringBuffer.next(); try { ringBuffer.get(seqId).load(rpcLogDetails); } finally { ringBuffer.publish(seqId); } }
Example 15
Source File: RingBufferSubscriberUtils.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
public static <E> void onError(Throwable error, RingBuffer<MutableSignal<E>> ringBuffer) { if (error == null) { throw SpecificationExceptions.spec_2_13_exception(); } final long seqId = ringBuffer.next(); final MutableSignal<E> signal = ringBuffer.get(seqId); signal.type = MutableSignal.Type.ERROR; signal.value = null; signal.error = error; ringBuffer.publish(seqId); }
Example 16
Source File: RingBufferSubscriberUtils.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
public static <E> void onNext(E value, RingBuffer<MutableSignal<E>> ringBuffer) { if (value == null) { throw SpecificationExceptions.spec_2_13_exception(); } final long seqId = ringBuffer.next(); final MutableSignal<E> signal = ringBuffer.get(seqId); signal.type = MutableSignal.Type.NEXT; signal.value = value; ringBuffer.publish(seqId); }
Example 17
Source File: DelayedMultiEventProducer.java From tutorials with MIT License | 5 votes |
private void produce(final RingBuffer<ValueEvent> ringBuffer, final int count, final boolean addDelay) { for (int i = 0; i < count; i++) { final long seq = ringBuffer.next(); final ValueEvent valueEvent = ringBuffer.get(seq); valueEvent.setValue(i); ringBuffer.publish(seq); if (addDelay) { addDelay(); } } }
Example 18
Source File: FastEventServiceImpl.java From redtorch with MIT License | 5 votes |
@Override public void emitPosition(PositionField position) { RingBuffer<FastEvent> ringBuffer = getRingBuffer(); long sequence = ringBuffer.next(); // Grab the next sequence try { FastEvent fastEvent = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence fastEvent.setObj(position); fastEvent.setEvent(position.getPositionId()); fastEvent.setFastEventType(FastEventType.POSITION); } finally { ringBuffer.publish(sequence); } }
Example 19
Source File: FastEventServiceImpl.java From redtorch with MIT License | 5 votes |
@Override public void emitEvent(FastEventType fastEventType, String event, Object obj) { RingBuffer<FastEvent> ringBuffer = getRingBuffer(); long sequence = ringBuffer.next(); // Grab the next sequence try { FastEvent fastEvent = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence fastEvent.setFastEventType(fastEventType); fastEvent.setEvent(event); fastEvent.setObj(obj); } finally { ringBuffer.publish(sequence); } }
Example 20
Source File: DisruptorProducer.java From md_blockchain with Apache License 2.0 | 5 votes |
@Override public void publish(BaseEvent baseEvent) { RingBuffer<BaseEvent> ringBuffer = disruptor.getRingBuffer(); long sequence = ringBuffer.next(); try { // Get the entry in the Disruptor BaseEvent event = ringBuffer.get(sequence); // for the sequence // Fill with data event.setBlockPacket(baseEvent.getBlockPacket()); event.setChannelContext(baseEvent.getChannelContext()); } finally { ringBuffer.publish(sequence); } }