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()));
}
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()));
}
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);
}
}
}
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");
}
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()));
}
Aggregations