use of io.aeron.Subscription in project aeron by real-logic.
the class SamplesUtil method printEndOfStreamImage.
/**
* Print the information for an end of stream image to stdout.
*
* @param image that has reached end of stream
*/
public static void printEndOfStreamImage(final Image image) {
final Subscription subscription = image.subscription();
System.out.println(String.format("End Of Stream 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 DriverLoggingAgentTest method testLogMediaDriverEvents.
private void testLogMediaDriverEvents(final String channel, final String enabledEvents, final EnumSet<DriverEventCode> expectedEvents) {
before(enabledEvents, expectedEvents);
final MediaDriver.Context driverCtx = new MediaDriver.Context().errorHandler(Tests::onError).publicationLingerTimeoutNs(0).timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(1));
try (MediaDriver mediaDriver = MediaDriver.launch(driverCtx)) {
try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
Publication publication = aeron.addPublication(channel, STREAM_ID)) {
final UnsafeBuffer offerBuffer = new UnsafeBuffer(new byte[32]);
while (publication.offer(offerBuffer) < 0) {
Tests.yield();
}
final MutableInteger counter = new MutableInteger();
final FragmentHandler handler = (buffer, offset, length, header) -> counter.value++;
while (0 == subscription.poll(handler, 1)) {
Tests.yield();
}
assertEquals(counter.get(), 1);
}
final Supplier<String> errorMessage = () -> "Pending events: " + WAIT_LIST;
while (!WAIT_LIST.isEmpty()) {
Tests.yieldingIdle(errorMessage);
}
}
}
use of io.aeron.Subscription in project Aeron by real-logic.
the class ListRecordingSubscriptionsSession method doWork.
/**
* {@inheritDoc}
*/
public int doWork() {
int workCount = 0;
int index = 0;
final int size = subscriptionByKeyMap.size();
for (final Subscription subscription : subscriptionByKeyMap.values()) {
if (index++ >= pseudoIndex) {
if (!(applyStreamId && subscription.streamId() != streamId) && subscription.channel().contains(channelFragment)) {
if (!controlSession.sendSubscriptionDescriptor(correlationId, subscription, proxy)) {
break;
}
workCount += 1;
if (++sent >= subscriptionCount) {
isDone = true;
break;
}
}
pseudoIndex = index - 1;
}
}
if (!isDone && index >= size) {
controlSession.sendSubscriptionUnknown(correlationId, proxy);
isDone = true;
workCount += 1;
}
return workCount;
}
use of io.aeron.Subscription in project Aeron by real-logic.
the class RecordingSessionTest method mockSubscription.
private static Subscription mockSubscription() {
final Subscription subscription = mock(Subscription.class);
when(subscription.channel()).thenReturn(CHANNEL);
when(subscription.streamId()).thenReturn(STREAM_ID);
return subscription;
}
use of io.aeron.Subscription in project Aeron by real-logic.
the class AeronArchiveTest method closeOwningAeronClient.
@Test
void closeOwningAeronClient() {
final long controlSessionId = 42;
final Aeron.Context aeronContext = mock(Aeron.Context.class);
when(aeronContext.nanoClock()).thenReturn(SystemNanoClock.INSTANCE);
when(aeron.context()).thenReturn(aeronContext);
final IllegalMonitorStateException aeronException = new IllegalMonitorStateException("aeron closed");
doThrow(aeronException).when(aeron).close();
final Publication publication = mock(Publication.class);
when(publication.isConnected()).thenReturn(true);
doThrow(new IllegalStateException("publication is closed")).when(publication).close();
final Subscription subscription = mock(Subscription.class);
when(controlResponsePoller.subscription()).thenReturn(subscription);
doThrow(new IndexOutOfBoundsException("subscription")).when(subscription).close();
when(archiveProxy.publication()).thenReturn(publication);
final IndexOutOfBoundsException closeSessionException = new IndexOutOfBoundsException();
when(archiveProxy.closeSession(controlSessionId)).thenThrow(closeSessionException);
final Context context = new Context().aeron(aeron).idleStrategy(NoOpIdleStrategy.INSTANCE).messageTimeoutNs(100).lock(NoOpLock.INSTANCE).errorHandler(errorHandler).ownsAeronClient(true);
final AeronArchive aeronArchive = new AeronArchive(context, controlResponsePoller, archiveProxy, controlSessionId);
final IllegalMonitorStateException ex = assertThrows(IllegalMonitorStateException.class, aeronArchive::close);
assertSame(aeronException, ex);
final InOrder inOrder = inOrder(errorHandler);
inOrder.verify(errorHandler).onError(closeSessionException);
inOrder.verifyNoMoreInteractions();
}
Aggregations