use of org.agrona.concurrent.status.Position in project Aeron by real-logic.
the class DriverConductor method linkIpcSubscription.
private void linkIpcSubscription(final IpcSubscriptionLink subscription, final IpcPublication publication) {
final long joiningPosition = publication.joiningPosition();
final long registrationId = subscription.registrationId();
final int sessionId = publication.sessionId();
final int streamId = subscription.streamId();
final String channel = subscription.uri();
final Position position = SubscriberPos.allocate(countersManager, registrationId, sessionId, streamId, channel, joiningPosition);
position.setOrdered(joiningPosition);
subscription.link(publication, position);
publication.addSubscriber(position);
clientProxy.onAvailableImage(publication.correlationId(), streamId, sessionId, publication.rawLog().fileName(), Collections.singletonList(new SubscriberPosition(subscription, position)), channel);
}
use of org.agrona.concurrent.status.Position in project Aeron by real-logic.
the class DriverConductor method linkMatchingImages.
private void linkMatchingImages(final ReceiveChannelEndpoint channelEndpoint, final SubscriptionLink subscription) {
final long registrationId = subscription.registrationId();
final int streamId = subscription.streamId();
final String channel = subscription.uri();
for (int i = 0, size = publicationImages.size(); i < size; i++) {
final PublicationImage image = publicationImages.get(i);
if (image.matches(channelEndpoint, streamId) && image.isAcceptingSubscriptions()) {
final long rebuildPosition = image.rebuildPosition();
final int sessionId = image.sessionId();
final Position position = SubscriberPos.allocate(countersManager, registrationId, sessionId, streamId, channel, rebuildPosition);
position.setOrdered(rebuildPosition);
image.addSubscriber(position);
subscription.link(image, position);
clientProxy.onAvailableImage(image.correlationId(), streamId, sessionId, image.rawLog().fileName(), Collections.singletonList(new SubscriberPosition(subscription, position)), generateSourceIdentity(image.sourceAddress()));
}
}
}
use of org.agrona.concurrent.status.Position in project Aeron by real-logic.
the class DriverConductor method onCreatePublicationImage.
void onCreatePublicationImage(final int sessionId, final int streamId, final int initialTermId, final int activeTermId, final int initialTermOffset, final int termBufferLength, final int senderMtuLength, final int transportIndex, final InetSocketAddress controlAddress, final InetSocketAddress sourceAddress, final ReceiveChannelEndpoint channelEndpoint) {
Configuration.validateMtuLength(senderMtuLength);
final UdpChannel subscriptionChannel = channelEndpoint.subscriptionUdpChannel();
Configuration.validateInitialWindowLength(subscriptionChannel.receiverWindowLengthOrDefault(ctx.initialWindowLength()), senderMtuLength);
final long joinPosition = computePosition(activeTermId, initialTermOffset, LogBufferDescriptor.positionBitsToShift(termBufferLength), initialTermId);
final ArrayList<SubscriberPosition> subscriberPositions = createSubscriberPositions(sessionId, streamId, channelEndpoint, joinPosition);
if (subscriberPositions.size() > 0) {
RawLog rawLog = null;
CongestionControl congestionControl = null;
UnsafeBufferPosition hwmPos = null;
UnsafeBufferPosition rcvPos = null;
try {
final long registrationId = toDriverCommands.nextCorrelationId();
rawLog = newPublicationImageLog(sessionId, streamId, initialTermId, termBufferLength, isOldestSubscriptionSparse(subscriberPositions), senderMtuLength, registrationId);
congestionControl = ctx.congestionControlSupplier().newInstance(registrationId, subscriptionChannel, streamId, sessionId, termBufferLength, senderMtuLength, controlAddress, sourceAddress, ctx.receiverCachedNanoClock(), ctx, countersManager);
final SubscriptionLink subscription = subscriberPositions.get(0).subscription();
final String uri = subscription.channel();
hwmPos = ReceiverHwm.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, uri);
rcvPos = ReceiverPos.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, uri);
final boolean treatAsMulticast = subscription.group() == INFER ? channelEndpoint.udpChannel().isMulticast() : subscription.group() == FORCE_TRUE;
final PublicationImage image = new PublicationImage(registrationId, ctx, channelEndpoint, transportIndex, controlAddress, sessionId, streamId, initialTermId, activeTermId, initialTermOffset, rawLog, treatAsMulticast ? ctx.multicastFeedbackDelayGenerator() : ctx.unicastFeedbackDelayGenerator(), subscriberPositions, hwmPos, rcvPos, sourceAddress, congestionControl);
publicationImages.add(image);
receiverProxy.newPublicationImage(channelEndpoint, image);
final String sourceIdentity = Configuration.sourceIdentity(sourceAddress);
for (int i = 0, size = subscriberPositions.size(); i < size; i++) {
final SubscriberPosition position = subscriberPositions.get(i);
position.addLink(image);
clientProxy.onAvailableImage(registrationId, streamId, sessionId, position.subscription().registrationId(), position.positionCounterId(), rawLog.fileName(), sourceIdentity);
}
} catch (final Exception ex) {
subscriberPositions.forEach((subscriberPosition) -> subscriberPosition.position().close());
CloseHelper.quietCloseAll(rawLog, congestionControl, hwmPos, rcvPos);
throw ex;
}
}
}
use of org.agrona.concurrent.status.Position in project Aeron by real-logic.
the class DriverConductor method linkSpy.
private Position linkSpy(final NetworkPublication publication, final SubscriptionLink subscription) {
final long joinPosition = publication.consumerPosition();
final long registrationId = subscription.registrationId();
final long clientId = subscription.aeronClient().clientId();
final int streamId = publication.streamId();
final int sessionId = publication.sessionId();
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;
}
Aggregations