/** * Return a reusable, parametrised event loop that calls a default idler when no messages are received * * @param fragmentHandler to be called back for each message. * @param limit passed to {@link Subscription#poll(FragmentHandler, int)} * @param running indication for loop * @return loop function */ public static Consumer<Subscription> subscriberLoop( final FragmentHandler fragmentHandler, final int limit, final AtomicBoolean running) { final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); return subscriberLoop(fragmentHandler, limit, running, idleStrategy); }
public void run() { final BusySpinIdleStrategy idleStrategy = new BusySpinIdleStrategy(); while (messageNum < NUM_MESSAGES && null == failedMessage) { idleStrategy.idle(subscription.poll(fragmentAssembler, FRAGMENT_COUNT_LIMIT)); } }
public static void pingHandler( final Publication pongPublication, final DirectBuffer buffer, final int offset, final int length) { if (pongPublication.offer(buffer, offset, length) > 0L) { return; } PING_HANDLER_IDLE_STRATEGY.reset(); while (pongPublication.offer(buffer, offset, length) < 0L) { PING_HANDLER_IDLE_STRATEGY.idle(); } } }
/** * <b>Note</b>: this implementation will result in no safepoint poll once inlined. * * @see org.agrona.concurrent.IdleStrategy#idle(int) */ public void idle(final int workCount) { if (workCount > 0) { return; } idle(); }
private static Thread startPong(final String embeddedDirName) { return new Thread(() -> { System.out.println("Subscribing Ping at " + PING_CHANNEL + " on stream Id " + PING_STREAM_ID); System.out.println("Publishing Pong at " + PONG_CHANNEL + " on stream Id " + PONG_STREAM_ID); final Aeron.Context ctx = new Aeron.Context().aeronDirectoryName(embeddedDirName); try (Aeron aeron = Aeron.connect(ctx); Subscription pingSubscription = aeron.addSubscription(PING_CHANNEL, PING_STREAM_ID); Publication pongPublication = EXCLUSIVE_PUBLICATIONS ? aeron.addExclusivePublication(PONG_CHANNEL, PONG_STREAM_ID) : aeron.addPublication(PONG_CHANNEL, PONG_STREAM_ID)) { final FragmentAssembler dataHandler = new FragmentAssembler( (buffer, offset, length, header) -> pingHandler(pongPublication, buffer, offset, length)); while (RUNNING.get()) { PING_HANDLER_IDLE_STRATEGY.idle(pingSubscription.poll(dataHandler, FRAME_COUNT_LIMIT)); } System.out.println("Shutting down..."); } }); }
public static void main(final String[] args) { loadPropertiesFiles(args); final MediaDriver.Context ctx = new MediaDriver.Context() .termBufferSparseFile(false) .threadingMode(ThreadingMode.DEDICATED) .conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); try (MediaDriver ignored = MediaDriver.launch(ctx)) { new ShutdownSignalBarrier().await(); System.out.println("Shutdown Driver..."); } } }
ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID)) final BusySpinIdleStrategy idleStrategy = new BusySpinIdleStrategy(); idleStrategy.idle();
private static void roundTripMessages( final FragmentHandler fragmentHandler, final Publication pingPublication, final Subscription pongSubscription, final long numMessages) { while (!pongSubscription.isConnected()) { Thread.yield(); } final Image image = pongSubscription.imageAtIndex(0); for (long i = 0; i < numMessages; i++) { long offeredPosition; do { OFFER_BUFFER.putLong(0, System.nanoTime()); } while ((offeredPosition = pingPublication.offer(OFFER_BUFFER, 0, MESSAGE_LENGTH)) < 0L); PONG_HANDLER_IDLE_STRATEGY.reset(); do { while (image.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT) <= 0) { PONG_HANDLER_IDLE_STRATEGY.idle(); } } while (image.position() < offeredPosition); } }
/** * <b>Note</b>: this implementation will result in no safepoint poll once inlined. * * @see org.agrona.concurrent.IdleStrategy#idle(int) */ public void idle(final int workCount) { if (workCount > 0) { return; } idle(); }
final IdleStrategy idleStrategy = new BusySpinIdleStrategy();
Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) final BusySpinIdleStrategy idleStrategy = new BusySpinIdleStrategy(); idleStrategy.idle();
/** * <b>Note</b>: this implementation will result in no safepoint poll once inlined. * * @see org.agrona.concurrent.IdleStrategy#idle(int) */ public void idle(final int workCount) { if (workCount > 0) { return; } idle(); }
/** * Return a reusable, parametrized * event loop that calls a * default idler * when no messages are received * * @param fragmentHandler to be called back for each message. * @param limit passed to {@link Subscription#poll(FragmentHandler, int)} * @param running indication for loop * @return loop function */ public static Consumer<Subscription> subscriberLoop(final FragmentHandler fragmentHandler, final int limit, final AtomicBoolean running, final AtomicBoolean launched) { final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); return subscriberLoop(fragmentHandler, limit, running, idleStrategy, launched); }
public void run() { while (!subscription.isConnected()) { Thread.yield(); } final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); while (true) { final int frameCount = subscription.poll(this, FRAGMENT_LIMIT); if (0 == frameCount) { if (!running.get()) { break; } idleStrategy.idle(); } } }
public void run() { while (!subscription.isConnected()) { Thread.yield(); } final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); while (true) { final int frameCount = subscription.poll(this, FRAGMENT_LIMIT); if (0 == frameCount) { if (!running.get()) { break; } idleStrategy.idle(); } } }
@SuppressWarnings("checkstyle:UncommentedMain") public static void main(final String... args) { MediaDriver.loadPropertiesFiles(args); setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true"); setProperty("aeron.mtu.length", "16384"); setProperty("aeron.socket.so_sndbuf", "2097152"); setProperty("aeron.socket.so_rcvbuf", "2097152"); setProperty("aeron.rcv.initial.window.length", "2097152"); final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true) .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); try (MediaDriver ignored = MediaDriver.launch(ctx)) { new SigIntBarrier().await(); } }