Search in sources :

Example 26 with Subscription

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

the class SamplesUtil method printAvailableImage.

/**
     * Print the information for an available image to stdout.
     *
     * @param image that has been created
     */
public static void printAvailableImage(final Image image) {
    final Subscription subscription = image.subscription();
    System.out.println(String.format("Available image on %s streamId=%d sessionId=%d from %s", subscription.channel(), subscription.streamId(), image.sessionId(), image.sourceIdentity()));
}
Also used : Subscription(io.aeron.Subscription)

Example 27 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)

Example 28 with Subscription

use of io.aeron.Subscription in project nd4j by deeplearning4j.

the class AeronNDArraySubscriber method launch.

/**
 * Launch a background thread
 * that subscribes to  the aeron context
 * @throws Exception
 */
public void launch() throws Exception {
    if (init.get())
        return;
    // Register a SIGINT handler for graceful shutdown.
    if (!init.get())
        init();
    log.info("Subscribing to " + channel + " on stream Id " + streamId);
    log.info("Using aeron directory " + ctx.aeronDirectoryName());
    // Register a SIGINT handler for graceful shutdown.
    SigInt.register(() -> running.set(false));
    if (channel == null)
        throw new IllegalStateException("No channel for subscriber defined");
    if (streamId <= 0)
        throw new IllegalStateException("No stream for subscriber defined");
    if (aeron == null)
        throw new IllegalStateException("No aeron instance defined");
    boolean started = false;
    while (!started) {
        try (final Subscription subscription = aeron.addSubscription(channel, streamId)) {
            this.subscription = subscription;
            log.info("Beginning subscribe on channel " + channel + " and stream " + streamId);
            AeronUtil.subscriberLoop(new FragmentAssembler(new NDArrayFragmentHandler(ndArrayCallback)), fragmentLimitCount, running, launched).accept(subscription);
            started = true;
        } catch (Exception e) {
            log.warn("Unable to connect...trying again on channel " + channel, e);
        }
    }
}
Also used : Subscription(io.aeron.Subscription) FragmentAssembler(io.aeron.FragmentAssembler)

Example 29 with Subscription

use of io.aeron.Subscription in project nd4j by deeplearning4j.

the class AeronNDArrayResponder method launch.

/**
 * Launch a background thread
 * that subscribes to  the aeron context
 * @throws Exception
 */
public void launch() throws Exception {
    if (init.get())
        return;
    // Register a SIGINT handler for graceful shutdown.
    if (!init.get())
        init();
    log.info("Subscribing to " + channel + " on stream Id " + streamId);
    // Register a SIGINT handler for graceful shutdown.
    SigInt.register(() -> running.set(false));
    // Create an Aeron instance with client-provided context configuration, connect to the
    // media driver, and add a subscription for the given channel and stream using the supplied
    // dataHandler method, which will be called with new messages as they are received.
    // The Aeron and Subscription classes implement AutoCloseable, and will automatically
    // clean up resources when this try block is finished.
    // Note here that we are either creating 1 or 2 subscriptions.
    // The first one is a  normal 1 subscription listener.
    // The second one is when we want to send responses
    boolean started = false;
    int numTries = 0;
    while (!started && numTries < 3) {
        try {
            try (final Subscription subscription = aeron.addSubscription(channel, streamId)) {
                log.info("Beginning subscribe on channel " + channel + " and stream " + streamId);
                AeronUtil.subscriberLoop(new FragmentAssembler(NDArrayResponseFragmentHandler.builder().aeron(aeron).context(ctx).streamId(responseStreamId).holder(ndArrayHolder).build()), fragmentLimitCount, running, launched).accept(subscription);
                started = true;
            }
        } catch (Exception e) {
            numTries++;
            log.warn("Failed to connect..trying again", e);
        }
    }
    if (numTries >= 3)
        throw new IllegalStateException("Was unable to start responder after " + numTries + "tries");
}
Also used : Subscription(io.aeron.Subscription) FragmentAssembler(io.aeron.FragmentAssembler)

Example 30 with Subscription

use of io.aeron.Subscription in project nd4j by deeplearning4j.

the class AeronUtil method printAvailableImage.

/**
 * Print the information for an available image to stdout.
 *
 * @param image that has been created
 */
public static void printAvailableImage(final Image image) {
    final Subscription subscription = image.subscription();
    System.out.println(String.format("Available image on %s streamId=%d sessionId=%d from %s", subscription.channel(), subscription.streamId(), image.sessionId(), image.sourceIdentity()));
}
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