com.lmax.disruptor.EventTranslatorOneArg Java Examples
The following examples show how to use
com.lmax.disruptor.EventTranslatorOneArg.
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: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
private <A> void translateAndPublishBatch(final EventTranslatorOneArg<E, A> translator, final A[] arg0, int batchStartsAt, final int batchSize, final long finalSequence) { final long initialSequence = finalSequence - (batchSize - 1); try { long sequence = initialSequence; final int batchEndsAt = batchStartsAt + batchSize; for (int i = batchStartsAt; i < batchEndsAt; i++) { translator.translateTo(get(sequence), sequence++, arg0[i]); } } finally { sequencer.publish(initialSequence, finalSequence); } }
Example #2
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
private <A> void translateAndPublish(EventTranslatorOneArg<E, A> translator, long sequence, A arg0) { try { translator.translateTo(get(sequence), sequence, arg0); } finally { sequencer.publish(sequence); } }
Example #3
Source File: ExchangeApi.java From exchange-core with Apache License 2.0 | 5 votes |
private <T extends ApiCommand, R> CompletableFuture<R> submitCommandAsync(final EventTranslatorOneArg<OrderCommand, T> translator, final T apiCommand, final Function<OrderCommand, R> responseTranslator) { final CompletableFuture<R> future = new CompletableFuture<>(); ringBuffer.publishEvent( (cmd, seq, apiCmd) -> { translator.translateTo(cmd, seq, apiCmd); promises.put(seq, orderCommand -> future.complete(responseTranslator.apply(orderCommand))); }, apiCommand); return future; }
Example #4
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Allows one user supplied argument. * * @param translator The user specified translation for each event * @param batchStartsAt The first element of the array which is within the batch. * @param batchSize The actual size of the batch * @param arg0 An array of user supplied arguments, one element per event. * @return true if the value was published, false if there was insufficient capacity. * @see #tryPublishEvents(EventTranslator[]) */ public <A> boolean tryPublishEvents(EventTranslatorOneArg<E, A> translator, int batchStartsAt, int batchSize, A[] arg0) { checkBounds(arg0, batchStartsAt, batchSize); try { final long finalSequence = sequencer.tryNext(batchSize); translateAndPublishBatch(translator, arg0, batchStartsAt, batchSize, finalSequence); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #5
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 5 votes |
/** * Allows one user supplied argument. * * @see #tryPublishEvent(EventTranslator) * @param translator The user specified translation for the event * @param arg0 A user supplied argument. * @return true if the value was published, false if there was insufficient capacity. */ public <A> boolean tryPublishEvent(EventTranslatorOneArg<E, A> translator, A arg0) { try { final long sequence = sequencer.tryNext(); translateAndPublish(translator, sequence, arg0); return true; } catch (InsufficientCapacityException e) { return false; } }
Example #6
Source File: DisruptorAutoConfiguration.java From disruptor-spring-boot-starter with Apache License 2.0 | 5 votes |
@Bean public ApplicationListener<DisruptorApplicationEvent> disruptorEventListener(Disruptor<DisruptorEvent> disruptor, EventTranslatorOneArg<DisruptorEvent, DisruptorEvent> oneArgEventTranslator) { return new ApplicationListener<DisruptorApplicationEvent>() { @Override public void onApplicationEvent(DisruptorApplicationEvent appEvent) { DisruptorEvent event = (DisruptorEvent) appEvent.getSource(); disruptor.publishEvent(oneArgEventTranslator, event); } }; }
Example #7
Source File: ApmServerReporter.java From apm-agent-java with Apache License 2.0 | 5 votes |
private <E> boolean tryAddEventToRingBuffer(E event, EventTranslatorOneArg<ReportingEvent, E> eventTranslator) { if (dropTransactionIfQueueFull) { boolean queueFull = !disruptor.getRingBuffer().tryPublishEvent(eventTranslator, event); if (queueFull) { if (logger.isDebugEnabled()) { logger.debug("Could not add {} {} to ring buffer as no slots are available", event.getClass().getSimpleName(), event); } dropped.incrementAndGet(); return false; } } else { disruptor.getRingBuffer().publishEvent(eventTranslator, event); } return true; }
Example #8
Source File: CollectingResponseEventSink.java From couchbase-jvm-core with Apache License 2.0 | 4 votes |
@Override public <A> void publishEvents(EventTranslatorOneArg<ResponseEvent, A> translator, int batchStartsAt, int batchSize, A[] arg0) { throw new UnsupportedOperationException(); }
Example #9
Source File: CollectingResponseEventSink.java From couchbase-jvm-core with Apache License 2.0 | 4 votes |
@Override public <A> boolean tryPublishEvents(EventTranslatorOneArg<ResponseEvent, A> translator, int batchStartsAt, int batchSize, A[] arg0) { throw new UnsupportedOperationException(); }
Example #10
Source File: CollectingResponseEventSink.java From couchbase-jvm-core with Apache License 2.0 | 4 votes |
@Override public <A> boolean tryPublishEvents(EventTranslatorOneArg<ResponseEvent, A> translator, A[] arg0) { throw new UnsupportedOperationException(); }
Example #11
Source File: CollectingResponseEventSink.java From couchbase-jvm-core with Apache License 2.0 | 4 votes |
@Override public <A> void publishEvents(EventTranslatorOneArg<ResponseEvent, A> translator, A[] arg0) { throw new UnsupportedOperationException(); }
Example #12
Source File: CollectingResponseEventSink.java From couchbase-jvm-core with Apache License 2.0 | 4 votes |
@Override public <A> boolean tryPublishEvent(EventTranslatorOneArg<ResponseEvent, A> translator, A arg0) { throw new UnsupportedOperationException(); }
Example #13
Source File: CollectingResponseEventSink.java From couchbase-jvm-core with Apache License 2.0 | 4 votes |
@Override public <A> void publishEvent(EventTranslatorOneArg<ResponseEvent, A> translator, A arg0) { throw new UnsupportedOperationException(); }
Example #14
Source File: DefaultDisruptorQueue.java From async-framework with Apache License 2.0 | 4 votes |
public void setTranslator(EventTranslatorOneArg<QueueEvent, EventData> translator) { this.translator = translator; }
Example #15
Source File: DisruptorAutoConfiguration.java From disruptor-spring-boot-starter with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnMissingBean public EventTranslatorOneArg<DisruptorEvent, DisruptorEvent> oneArgEventTranslator() { return new DisruptorEventOneArgTranslator(); }
Example #16
Source File: ExchangeApi.java From exchange-core with Apache License 2.0 | 4 votes |
private <T extends ApiCommand> CompletableFuture<OrderCommand> submitCommandAsyncFullResponse(EventTranslatorOneArg<OrderCommand, T> translator, final T apiCommand) { return submitCommandAsync(translator, apiCommand, Function.identity()); }
Example #17
Source File: ExchangeApi.java From exchange-core with Apache License 2.0 | 4 votes |
private <T extends ApiCommand> CompletableFuture<CommandResultCode> submitCommandAsync(EventTranslatorOneArg<OrderCommand, T> translator, final T apiCommand) { return submitCommandAsync(translator, apiCommand, c -> c.resultCode); }
Example #18
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 2 votes |
/** * Allows one user supplied argument. * * @see #publishEvent(EventTranslator) * @param translator The user specified translation for the event * @param arg0 A user supplied argument. */ public <A> void publishEvent(EventTranslatorOneArg<E, A> translator, A arg0) { final long sequence = sequencer.next(); translateAndPublish(translator, sequence, arg0); }
Example #19
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 2 votes |
/** * Allows one user supplied argument per event. * * @param translator The user specified translation for the event * @param arg0 A user supplied argument. * @see #publishEvents(com.lmax.disruptor.EventTranslator[]) */ public <A> void publishEvents(EventTranslatorOneArg<E, A> translator, A[] arg0) { publishEvents(translator, 0, arg0.length, arg0); }
Example #20
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 2 votes |
/** * Allows one user supplied argument per event. * * @param translator The user specified translation for each event * @param batchStartsAt The first element of the array which is within the batch. * @param batchSize The actual size of the batch * @param arg0 An array of user supplied arguments, one element per event. * @see #publishEvents(EventTranslator[]) */ public <A> void publishEvents(EventTranslatorOneArg<E, A> translator, int batchStartsAt, int batchSize, A[] arg0) { checkBounds(arg0, batchStartsAt, batchSize); final long finalSequence = sequencer.next(batchSize); translateAndPublishBatch(translator, arg0, batchStartsAt, batchSize, finalSequence); }
Example #21
Source File: RingBuffer.java From jstorm with Apache License 2.0 | 2 votes |
/** * Allows one user supplied argument. * * @param translator The user specified translation for each event * @param arg0 An array of user supplied arguments, one element per event. * @return true if the value was published, false if there was insufficient capacity. * @see #tryPublishEvents(com.lmax.disruptor.EventTranslator[]) */ public <A> boolean tryPublishEvents(EventTranslatorOneArg<E, A> translator, A[] arg0) { return tryPublishEvents(translator, 0, arg0.length, arg0); }
Example #22
Source File: CommandEventProducer.java From artemis-disruptor-miaosha with Apache License 2.0 | 2 votes |
public void onData(T command) { ringBuffer.publishEvent((EventTranslatorOneArg) TRANSLATOR, command); }