Java Code Examples for io.aeron.Aeron#addExclusivePublication()

The following examples show how to use io.aeron.Aeron#addExclusivePublication() . 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: EchoNode.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
EchoNode(
    final AtomicBoolean running, final MediaDriver mediaDriver, final Aeron aeron, final boolean ownsAeronClient)
{
    this.running = running;
    this.mediaDriver = mediaDriver;
    this.aeron = aeron;
    this.ownsAeronClient = ownsAeronClient;

    publication = aeron.addExclusivePublication(receiveChannel(), receiveStreamId());
    subscription = aeron.addSubscription(sendChannel(), sendStreamId());

    while (!subscription.isConnected() || !publication.isConnected())
    {
        yieldUninterruptedly();
    }
}
 
Example 2
Source File: EmbeddedPingPong.java    From aeron with Apache License 2.0 6 votes vote down vote up
private static Thread startPong(final Aeron aeron)
{
    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);

        try (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 BufferClaim bufferClaim = new BufferClaim();
            final FragmentHandler fragmentHandler = (buffer, offset, length, header) ->
                pingHandler(bufferClaim, pongPublication, buffer, offset, length, header);

            while (RUNNING.get())
            {
                PING_HANDLER_IDLE_STRATEGY.idle(pingSubscription.poll(fragmentHandler, FRAME_COUNT_LIMIT));
            }

            System.out.println("Shutting down...");
        }
    });
}
 
Example 3
Source File: ReplayIndexTest.java    From artio with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp()
{
    mediaDriver = TestFixtures.launchMediaDriver();
    aeronArchive = AeronArchive.connect();

    recordingIdLookup = new RecordingIdLookup(new YieldingIdleStrategy(), aeron().countersReader());

    aeronArchive.startRecording(CHANNEL, STREAM_ID, SourceLocation.LOCAL);

    final Aeron aeron = aeron();
    publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID);
    subscription = aeron.addSubscription(CHANNEL, STREAM_ID);

    IoUtil.deleteIfExists(logFile(SESSION_ID));
    IoUtil.deleteIfExists(logFile(SESSION_ID_2));

    newReplayIndex();
    query = new ReplayQuery(
        DEFAULT_LOG_FILE_DIR,
        DEFAULT_LOGGER_CACHE_NUM_SETS,
        DEFAULT_LOGGER_CACHE_SET_SIZE,
        existingBufferFactory,
        DEFAULT_OUTBOUND_LIBRARY_STREAM,
        new NoOpIdleStrategy(),
        aeronArchive,
        errorHandler,
        DEFAULT_ARCHIVE_REPLAY_STREAM);
}
 
Example 4
Source File: LiveRecordingMessageTransceiver.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
public void init(final Configuration configuration)
{
    final AeronArchive.Context context = aeronArchive.context();
    final Aeron aeron = context.aeron();

    fragmentLimit = fragmentLimit();

    subscription = aeron.addSubscription(receiveChannel(), receiveStreamId());

    final String sendChannel = sendChannel();
    final int sendStreamId = sendStreamId();
    publication = aeron.addExclusivePublication(sendChannel, sendStreamId);

    recordingEventsSubscription = aeron.addSubscription(
        context.recordingEventsChannel(), context.recordingEventsStreamId());

    recordingEventsAdapter = new RecordingEventsAdapter(
        new LiveRecordingEventsListener(this), recordingEventsSubscription, fragmentLimit);

    while (!recordingEventsSubscription.isConnected() || !subscription.isConnected() || !publication.isConnected())
    {
        yieldUninterruptedly();
    }

    final int publicationSessionId = publication.sessionId();
    final String channel = addSessionId(sendChannel, publicationSessionId);
    aeronArchive.startRecording(channel, sendStreamId, LOCAL, true);
    recordingId = awaitRecordingStart(aeron, publicationSessionId);

    offerBuffer = new UnsafeBuffer(allocateDirectAligned(configuration.messageLength(), CACHE_LINE_LENGTH));
    image = subscription.imageAtIndex(0);
}
 
Example 5
Source File: LiveReplayMessageTransceiver.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
public void init(final Configuration configuration)
{
    final Aeron aeron = aeronArchive.context().aeron();

    publication = aeron.addExclusivePublication(sendChannel(), sendStreamId());

    while (!publication.isConnected())
    {
        yieldUninterruptedly();
    }

    final long recordingId = findLastRecordingId(aeronArchive, archiveChannel(), archiveStreamId());

    final String replayChannel = receiveChannel();
    final int replayStreamId = receiveStreamId();
    final long replaySessionId = replayFullRecording(aeronArchive, recordingId, replayChannel, replayStreamId);

    final String channel = addSessionId(replayChannel, (int)replaySessionId);
    subscription = aeron.addSubscription(channel, replayStreamId);

    while (!subscription.isConnected())
    {
        yieldUninterruptedly();
    }

    image = subscription.imageAtIndex(0);

    offerBuffer = new UnsafeBuffer(allocateDirectAligned(configuration.messageLength(), CACHE_LINE_LENGTH));

    fragmentLimit = fragmentLimit();
}
 
Example 6
Source File: LiveReplayNode.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
LiveReplayNode(
    final AtomicBoolean running,
    final MediaDriver mediaDriver,
    final AeronArchive aeronArchive,
    final boolean ownsArchiveClient)
{
    this.running = running;
    this.mediaDriver = mediaDriver;
    this.aeronArchive = aeronArchive;
    this.ownsArchiveClient = ownsArchiveClient;

    final Aeron aeron = aeronArchive.context().aeron();

    publication = aeron.addExclusivePublication(receiveChannel(), receiveStreamId());

    while (!publication.isConnected())
    {
        yieldUninterruptedly();
    }

    final long recordingId = findLastRecordingId(aeronArchive, archiveChannel(), archiveStreamId());

    final String replayChannel = sendChannel();
    final int replayStreamId = sendStreamId();
    final long replaySessionId = replayFullRecording(aeronArchive, recordingId, replayChannel, replayStreamId);

    final String channel = addSessionId(replayChannel, (int)replaySessionId);
    subscription = aeron.addSubscription(channel, replayStreamId);

    while (!subscription.isConnected())
    {
        yieldUninterruptedly();
    }
}
 
Example 7
Source File: ArchiveMessageTransceiver.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
public void init(final Configuration configuration)
{
    final Aeron aeron = aeronArchive.context().aeron();

    subscription = aeron.addSubscription(receiveChannel(), receiveStreamId());

    final String archiveChannel = archiveChannel();
    final int archiveStreamId = archiveStreamId();
    publication = aeron.addExclusivePublication(archiveChannel, archiveStreamId);

    final int publicationSessionId = publication.sessionId();
    final String channel = addSessionId(archiveChannel, publicationSessionId);
    aeronArchive.startRecording(channel, archiveStreamId, LOCAL, true);

    while (!subscription.isConnected() || !publication.isConnected())
    {
        yieldUninterruptedly();
    }

    awaitRecordingStart(aeron, publicationSessionId);

    offerBuffer = new UnsafeBuffer(allocateDirectAligned(configuration.messageLength(), CACHE_LINE_LENGTH));

    image = subscription.imageAtIndex(0);

    fragmentLimit = fragmentLimit();
}
 
Example 8
Source File: ArchiveNode.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
ArchiveNode(
    final AtomicBoolean running,
    final ArchivingMediaDriver archivingMediaDriver,
    final AeronArchive aeronArchive,
    final boolean ownsArchiveClient)
{
    this.running = running;
    this.archivingMediaDriver = archivingMediaDriver;
    this.aeronArchive = aeronArchive;
    this.ownsArchiveClient = ownsArchiveClient;

    final Aeron aeron = aeronArchive.context().aeron();

    subscription = aeron.addSubscription(sendChannel(), sendStreamId());

    final String archiveChannel = archiveChannel();
    final int archiveStreamId = archiveStreamId();
    publication = aeron.addExclusivePublication(archiveChannel, archiveStreamId);

    final int publicationSessionId = publication.sessionId();
    final String channel = addSessionId(archiveChannel, publicationSessionId);
    aeronArchive.startRecording(channel, archiveStreamId, LOCAL, true);

    while (!subscription.isConnected() || !publication.isConnected())
    {
        yieldUninterruptedly();
    }

    awaitRecordingStart(aeron, publicationSessionId);
}
 
Example 9
Source File: EmbeddedPingPong.java    From aeron with Apache License 2.0 4 votes vote down vote up
private static void runPing(final Aeron aeron) throws InterruptedException
{
    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");
    System.out.println("Using exclusive publications: " + EXCLUSIVE_PUBLICATIONS);

    final FragmentAssembler dataHandler = new FragmentAssembler(EmbeddedPingPong::pongHandler);

    try (Subscription pongSubscription = aeron.addSubscription(
        PONG_CHANNEL, PONG_STREAM_ID, EmbeddedPingPong::availablePongImageHandler, null);
        Publication pingPublication = EXCLUSIVE_PUBLICATIONS ?
            aeron.addExclusivePublication(PING_CHANNEL, PING_STREAM_ID) :
            aeron.addPublication(PING_CHANNEL, PING_STREAM_ID))
    {
        System.out.println("Waiting for new image from Pong...");
        PONG_IMAGE_LATCH.await();

        System.out.format("Warming up... %d iterations of %,d messages%n",
            WARMUP_NUMBER_OF_ITERATIONS, WARMUP_NUMBER_OF_MESSAGES);

        for (int i = 0; i < WARMUP_NUMBER_OF_ITERATIONS; i++)
        {
            roundTripMessages(dataHandler, pingPublication, pongSubscription, WARMUP_NUMBER_OF_MESSAGES);
            Thread.yield();
        }

        Thread.sleep(100);
        final ContinueBarrier barrier = new ContinueBarrier("Execute again?");

        do
        {
            HISTOGRAM.reset();
            System.out.format("Pinging %,d messages%n", NUMBER_OF_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());
    }
}