Search in sources :

Example 1 with Position

use of org.agrona.concurrent.status.Position in project Aeron by real-logic.

the class DriverConductor method linkMatchingImages.

private void linkMatchingImages(final SubscriptionLink subscriptionLink) {
    for (int i = 0, size = publicationImages.size(); i < size; i++) {
        final PublicationImage image = publicationImages.get(i);
        if (subscriptionLink.matches(image) && image.isAcceptingSubscriptions()) {
            final long registrationId = subscriptionLink.registrationId();
            final long joinPosition = image.joinPosition();
            final int sessionId = image.sessionId();
            final int streamId = subscriptionLink.streamId();
            final Position position = SubscriberPos.allocate(tempBuffer, countersManager, subscriptionLink.aeronClient().clientId(), registrationId, sessionId, streamId, subscriptionLink.channel(), joinPosition);
            position.setOrdered(joinPosition);
            subscriptionLink.link(image, position);
            image.addSubscriber(subscriptionLink, position, cachedNanoClock.nanoTime());
            clientProxy.onAvailableImage(image.correlationId(), streamId, sessionId, registrationId, position.id(), image.rawLog().fileName(), Configuration.sourceIdentity(image.sourceAddress()));
        }
    }
}
Also used : Position(org.agrona.concurrent.status.Position) UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Example 2 with Position

use of org.agrona.concurrent.status.Position in project Aeron by real-logic.

the class DriverConductor method createSubscriberPositions.

private ArrayList<SubscriberPosition> createSubscriberPositions(final int sessionId, final int streamId, final ReceiveChannelEndpoint channelEndpoint, final long joinPosition) {
    final ArrayList<SubscriberPosition> subscriberPositions = new ArrayList<>();
    for (int i = 0, size = subscriptionLinks.size(); i < size; i++) {
        final SubscriptionLink subscription = subscriptionLinks.get(i);
        if (subscription.matches(channelEndpoint, streamId, sessionId)) {
            final Position position = SubscriberPos.allocate(tempBuffer, countersManager, subscription.aeronClient().clientId(), subscription.registrationId(), sessionId, streamId, subscription.channel(), joinPosition);
            position.setOrdered(joinPosition);
            subscriberPositions.add(new SubscriberPosition(subscription, null, position));
        }
    }
    return subscriberPositions;
}
Also used : Position(org.agrona.concurrent.status.Position) UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) ArrayList(java.util.ArrayList) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Example 3 with Position

use of org.agrona.concurrent.status.Position in project Aeron by real-logic.

the class DriverConductor method linkIpcSubscription.

private Position linkIpcSubscription(final IpcPublication publication, final SubscriptionLink subscription) {
    final long joinPosition = publication.joinPosition();
    final long registrationId = subscription.registrationId();
    final long clientId = subscription.aeronClient().clientId();
    final int sessionId = publication.sessionId();
    final int streamId = subscription.streamId();
    final String channel = subscription.channel();
    final Position position = SubscriberPos.allocate(tempBuffer, countersManager, clientId, registrationId, sessionId, streamId, channel, joinPosition);
    position.setOrdered(joinPosition);
    subscription.link(publication, position);
    publication.addSubscriber(subscription, position, cachedNanoClock.nanoTime());
    return position;
}
Also used : Position(org.agrona.concurrent.status.Position) UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Example 4 with Position

use of org.agrona.concurrent.status.Position in project Aeron by real-logic.

the class UntetheredSubscriptionTest method shouldLifeCycleTimeoutsAndRelink.

@Test
public void shouldLifeCycleTimeoutsAndRelink() {
    final Position tetheredPosition = new AtomicLongPosition();
    tetheredPosition.set(TERM_WINDOW_LENGTH - 1);
    final Position untetheredPosition = new AtomicLongPosition();
    final SubscriptionLink tetheredLink = newLink(1, true);
    final SubscriptionLink untetheredLink = newLink(1, false);
    ipcPublication.addSubscriber(tetheredLink, tetheredPosition, ctx.cachedNanoClock().nanoTime());
    ipcPublication.addSubscriber(untetheredLink, untetheredPosition, ctx.cachedNanoClock().nanoTime());
    final DriverConductor conductor = mock(DriverConductor.class);
    ipcPublication.updatePublisherLimit();
    final long timeNs = TIME_NS + 1;
    ipcPublication.onTimeEvent(timeNs, 0, conductor);
    verify(conductor, never()).notifyUnavailableImageLink(REGISTRATION_ID, untetheredLink);
    final long windowLimitTimeoutNs = timeNs + UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS;
    ipcPublication.onTimeEvent(windowLimitTimeoutNs, 0, conductor);
    verify(conductor, times(1)).notifyUnavailableImageLink(REGISTRATION_ID, untetheredLink);
    ipcPublication.updatePublisherLimit();
    assertEquals(TERM_WINDOW_LENGTH, publisherLimit.get());
    final long afterLingerTimeoutNs = windowLimitTimeoutNs + UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS;
    ipcPublication.onTimeEvent(afterLingerTimeoutNs, 0, conductor);
    ipcPublication.updatePublisherLimit();
    assertEquals(tetheredPosition.get() + TERM_WINDOW_LENGTH, publisherLimit.get());
    final long afterRestingTimeoutNs = afterLingerTimeoutNs + UNTETHERED_RESTING_TIMEOUT_NS;
    ipcPublication.onTimeEvent(afterRestingTimeoutNs, 0, conductor);
    verify(conductor, times(1)).notifyAvailableImageLink(eq(REGISTRATION_ID), eq(SESSION_ID), eq(untetheredLink), anyInt(), eq(ipcPublication.joinPosition()), eq(rawLog.fileName()), eq(CommonContext.IPC_CHANNEL));
}
Also used : Position(org.agrona.concurrent.status.Position) AtomicLongPosition(org.agrona.concurrent.status.AtomicLongPosition) AtomicLongPosition(org.agrona.concurrent.status.AtomicLongPosition) Test(org.junit.jupiter.api.Test)

Example 5 with Position

use of org.agrona.concurrent.status.Position in project Aeron by real-logic.

the class DriverConductor method addIpcPublication.

private IpcPublication addIpcPublication(final int streamId, final String channel, final boolean isExclusive) {
    final int termLength = getTermBufferLength(AeronUri.parse(channel), context.ipcTermBufferLength());
    final long registrationId = nextImageCorrelationId();
    final int sessionId = nextSessionId++;
    final int initialTermId = BitUtil.generateRandomisedId();
    final RawLog rawLog = newIpcPublicationLog(termLength, sessionId, streamId, initialTermId, registrationId);
    final Position publisherLimit = PublisherLimit.allocate(countersManager, registrationId, sessionId, streamId, channel);
    final IpcPublication publication = new IpcPublication(registrationId, sessionId, streamId, publisherLimit, rawLog, publicationUnblockTimeoutNs, context.systemCounters(), isExclusive);
    ipcPublications.add(publication);
    return publication;
}
Also used : Position(org.agrona.concurrent.status.Position) ReadablePosition(org.agrona.concurrent.status.ReadablePosition) RawLog(io.aeron.driver.buffer.RawLog) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Aggregations

Position (org.agrona.concurrent.status.Position)9 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)8 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)8 UnsafeBufferPosition (org.agrona.concurrent.status.UnsafeBufferPosition)5 ReadablePosition (org.agrona.concurrent.status.ReadablePosition)3 RawLog (io.aeron.driver.buffer.RawLog)2 ArrayList (java.util.ArrayList)2 Aeron (io.aeron.Aeron)1 ChannelUri (io.aeron.ChannelUri)1 SPY_QUALIFIER (io.aeron.ChannelUri.SPY_QUALIFIER)1 CommonContext (io.aeron.CommonContext)1 FORCE_TRUE (io.aeron.CommonContext.InferableBoolean.FORCE_TRUE)1 INFER (io.aeron.CommonContext.InferableBoolean.INFER)1 ErrorCode (io.aeron.ErrorCode)1 Context (io.aeron.driver.MediaDriver.Context)1 PublicationParams (io.aeron.driver.PublicationParams)1 SubscriptionParams.validateInitialWindowForRcvBuf (io.aeron.driver.SubscriptionParams.validateInitialWindowForRcvBuf)1 LogFactory (io.aeron.driver.buffer.LogFactory)1 InvalidChannelException (io.aeron.driver.exceptions.InvalidChannelException)1 ReceiveDestinationTransport (io.aeron.driver.media.ReceiveDestinationTransport)1