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