Search in sources :

Example 31 with Subscription

use of io.aeron.Subscription in project aeron by real-logic.

the class RecordingSessionTest method mockSubscription.

private Subscription mockSubscription(final String channel, final int streamId) {
    final Subscription subscription = mock(Subscription.class);
    when(subscription.channel()).thenReturn(channel);
    when(subscription.streamId()).thenReturn(streamId);
    return subscription;
}
Also used : Subscription(io.aeron.Subscription)

Example 32 with Subscription

use of io.aeron.Subscription in project aeron by real-logic.

the class ArchiveReplayLoadTest method replay.

private void replay(final int iteration) {
    try (Subscription replay = aeronArchive.replay(recordingId, startPosition, expectedRecordingLength, REPLAY_URI, iteration)) {
        TestUtil.await(replay::isConnected);
        fragmentCount = 0;
        remaining = totalPayloadLength;
        while (remaining > 0) {
            final int fragments = replay.poll(validatingFragmentHandler, 128);
            if (0 == fragments) {
                if (!replay.isConnected() && remaining > 0) {
                    System.out.println("Unexpected close of image: remaining=" + remaining);
                    System.out.println("Image position=" + receivedPosition + " expected=" + expectedRecordingLength);
                    System.out.println("Resulting error: " + aeronArchive.pollForErrorResponse());
                    aeron.printCounters(System.out);
                    break;
                }
                Thread.yield();
            }
        }
        assertThat(fragmentCount, is(MESSAGE_COUNT));
        assertThat(remaining, is(0L));
    }
}
Also used : Subscription(io.aeron.Subscription)

Example 33 with Subscription

use of io.aeron.Subscription in project aeron by real-logic.

the class EmbeddedPingPong method runPing.

private static void runPing(final String embeddedDirName) throws InterruptedException {
    final Aeron.Context ctx = new Aeron.Context().availableImageHandler(EmbeddedPingPong::availablePongImageHandler).aeronDirectoryName(embeddedDirName);
    System.out.println("Publishing Ping at " + PING_CHANNEL + " on stream Id " + PING_STREAM_ID);
    System.out.println("Subscribing Pong at " + PONG_CHANNEL + " on stream Id " + PONG_STREAM_ID);
    System.out.println("Message payload length of " + MESSAGE_LENGTH + " bytes");
    final FragmentAssembler dataHandler = new FragmentAssembler(EmbeddedPingPong::pongHandler);
    try (Aeron aeron = Aeron.connect(ctx);
        Publication pingPublication = aeron.addPublication(PING_CHANNEL, PING_STREAM_ID);
        Subscription pongSubscription = aeron.addSubscription(PONG_CHANNEL, PONG_STREAM_ID)) {
        System.out.println("Waiting for new image from Pong...");
        PONG_IMAGE_LATCH.await();
        System.out.println("Warming up... " + WARMUP_NUMBER_OF_ITERATIONS + " iterations of " + WARMUP_NUMBER_OF_MESSAGES + " messages");
        for (int i = 0; i < WARMUP_NUMBER_OF_ITERATIONS; i++) {
            roundTripMessages(dataHandler, pingPublication, pongSubscription, WARMUP_NUMBER_OF_MESSAGES);
        }
        Thread.sleep(100);
        final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
        do {
            HISTOGRAM.reset();
            System.out.println("Pinging " + NUMBER_OF_MESSAGES + " messages");
            roundTripMessages(dataHandler, pingPublication, pongSubscription, NUMBER_OF_MESSAGES);
            System.out.println("Histogram of RTT latencies in microseconds.");
            HISTOGRAM.outputPercentileDistribution(System.out, 1000.0);
        } while (barrier.await());
    }
}
Also used : Publication(io.aeron.Publication) ContinueBarrier(org.agrona.console.ContinueBarrier) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) FragmentAssembler(io.aeron.FragmentAssembler)

Example 34 with Subscription

use of io.aeron.Subscription in project aeron by real-logic.

the class EmbeddedPingPong method startPong.

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);
            Publication pongPublication = aeron.addPublication(PONG_CHANNEL, PONG_STREAM_ID);
            Subscription pingSubscription = aeron.addSubscription(PING_CHANNEL, PING_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...");
        }
    });
}
Also used : Publication(io.aeron.Publication) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) FragmentAssembler(io.aeron.FragmentAssembler)

Example 35 with Subscription

use of io.aeron.Subscription in project aeron by real-logic.

the class SamplesUtil method printUnavailableImage.

/**
 * Print the information for an unavailable image to stdout.
 *
 * @param image that has gone inactive
 */
public static void printUnavailableImage(final Image image) {
    final Subscription subscription = image.subscription();
    System.out.println(String.format("Unavailable image on %s streamId=%d sessionId=%d", subscription.channel(), subscription.streamId(), image.sessionId()));
}
Also used : Subscription(io.aeron.Subscription)

Aggregations

Subscription (io.aeron.Subscription)55 Aeron (io.aeron.Aeron)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)20 Publication (io.aeron.Publication)19 MediaDriver (io.aeron.driver.MediaDriver)16 IdleStrategy (org.agrona.concurrent.IdleStrategy)13 FragmentAssembler (io.aeron.FragmentAssembler)12 ContinueBarrier (org.agrona.console.ContinueBarrier)10 FragmentHandler (io.aeron.logbuffer.FragmentHandler)8 TimeUnit (java.util.concurrent.TimeUnit)6 BackoffIdleStrategy (org.agrona.concurrent.BackoffIdleStrategy)5 Test (org.junit.jupiter.api.Test)5 Context (io.aeron.archive.client.AeronArchive.Context)4 io.aeron.logbuffer (io.aeron.logbuffer)4 ExecutorService (java.util.concurrent.ExecutorService)4 SigInt (org.agrona.concurrent.SigInt)4 InOrder (org.mockito.InOrder)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 DirectBuffer (org.agrona.DirectBuffer)3 CommonContext (io.aeron.CommonContext)2