Search in sources :

Example 36 with Subscription

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()));
}
Also used : Subscription(io.aeron.Subscription)

Example 37 with Subscription

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);
        }
    }
}
Also used : Tests(io.aeron.test.Tests) DriverEventCode(io.aeron.agent.DriverEventCode) Subscription(io.aeron.Subscription) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) EnumSource(org.junit.jupiter.params.provider.EnumSource) Supplier(java.util.function.Supplier) Collections.synchronizedSet(java.util.Collections.synchronizedSet) MessageHandler(org.agrona.concurrent.MessageHandler) EVENT_READER_FRAME_LIMIT(io.aeron.agent.EventConfiguration.EVENT_READER_FRAME_LIMIT) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EVENT_RING_BUFFER(io.aeron.agent.EventConfiguration.EVENT_RING_BUFFER) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Publication(io.aeron.Publication) Agent(org.agrona.concurrent.Agent) MutableInteger(org.agrona.collections.MutableInteger) EnumSet(java.util.EnumSet) MediaDriver(io.aeron.driver.MediaDriver) Aeron(io.aeron.Aeron) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) EnumMap(java.util.EnumMap) Set(java.util.Set) IPC_CHANNEL(io.aeron.CommonContext.IPC_CHANNEL) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) INCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.INCLUDE) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) Tests(io.aeron.test.Tests) Aeron(io.aeron.Aeron) MediaDriver(io.aeron.driver.MediaDriver) FragmentHandler(io.aeron.logbuffer.FragmentHandler) Subscription(io.aeron.Subscription) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 38 with Subscription

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;
}
Also used : Subscription(io.aeron.Subscription)

Example 39 with Subscription

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;
}
Also used : Subscription(io.aeron.Subscription)

Example 40 with 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();
}
Also used : Context(io.aeron.archive.client.AeronArchive.Context) InOrder(org.mockito.InOrder) Publication(io.aeron.Publication) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) Test(org.junit.jupiter.api.Test)

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