use of io.aeron.Subscription in project Aeron by real-logic.
the class MultipleSubscribersWithFragmentAssembly method eventAvailableImage.
/**
* Print the information for an available image to stdout.
*
* @param image that has been created
*/
public static void eventAvailableImage(final Image image) {
final Subscription subscription = image.subscription();
System.out.format("new image on %s streamId %x sessionId %x from %s%n", subscription.channel(), subscription.streamId(), image.sessionId(), image.sourceIdentity());
}
use of io.aeron.Subscription in project Aeron by real-logic.
the class Pong method main.
public static void main(final String[] args) throws Exception {
final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;
final Aeron.Context ctx = new Aeron.Context();
if (EMBEDDED_MEDIA_DRIVER) {
ctx.aeronDirectoryName(driver.aeronDirectoryName());
}
if (INFO_FLAG) {
ctx.availableImageHandler(SamplesUtil::printAvailableImage);
ctx.unavailableImageHandler(SamplesUtil::printUnavailableImage);
}
final IdleStrategy idleStrategy = new BusySpinIdleStrategy();
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 AtomicBoolean running = new AtomicBoolean(true);
SigInt.register(() -> running.set(false));
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()) {
idleStrategy.idle(pingSubscription.poll(dataHandler, FRAME_COUNT_LIMIT));
}
System.out.println("Shutting down...");
}
CloseHelper.quietClose(driver);
}
use of io.aeron.Subscription in project Aeron by real-logic.
the class RateSubscriber method main.
public static void main(final String[] args) throws Exception {
System.out.println("Subscribing to " + CHANNEL + " on stream Id " + STREAM_ID);
final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;
final ExecutorService executor = Executors.newFixedThreadPool(1);
final Aeron.Context ctx = new Aeron.Context().availableImageHandler(SamplesUtil::printAvailableImage).unavailableImageHandler(SamplesUtil::printUnavailableImage);
if (EMBEDDED_MEDIA_DRIVER) {
ctx.aeronDirectoryName(driver.aeronDirectoryName());
}
final RateReporter reporter = new RateReporter(TimeUnit.SECONDS.toNanos(1), SamplesUtil::printRate);
final FragmentHandler rateReporterHandler = new FragmentAssembler(rateReporterHandler(reporter));
final AtomicBoolean running = new AtomicBoolean(true);
SigInt.register(() -> {
reporter.halt();
running.set(false);
});
try (Aeron aeron = Aeron.connect(ctx);
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
final Future future = executor.submit(() -> SamplesUtil.subscriberLoop(rateReporterHandler, FRAGMENT_COUNT_LIMIT, running).accept(subscription));
reporter.run();
System.out.println("Shutting down...");
future.get();
}
executor.shutdown();
if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
System.out.println("Warning: not all tasks completed promptly");
}
CloseHelper.quietClose(driver);
}
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()));
}
Aggregations