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