use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.
the class DriverConductor method onAddNetworkSubscription.
void onAddNetworkSubscription(final String channel, final int streamId, final long registrationId, final long clientId) {
final UdpChannel udpChannel = UdpChannel.parse(channel);
final String reliableParam = udpChannel.aeronUri().get(RELIABLE_STREAM_PARAM_NAME, "true");
final boolean isReliable = !"false".equals(reliableParam);
checkForClashingSubscription(isReliable, udpChannel, streamId);
final ReceiveChannelEndpoint channelEndpoint = getOrCreateReceiveChannelEndpoint(udpChannel);
final int refCount = channelEndpoint.incRefToStream(streamId);
if (1 == refCount) {
receiverProxy.addSubscription(channelEndpoint, streamId);
}
final AeronClient client = getOrAddClient(clientId);
final SubscriptionLink subscription = new NetworkSubscriptionLink(registrationId, channelEndpoint, streamId, channel, client, context.clientLivenessTimeoutNs(), isReliable);
subscriptionLinks.add(subscription);
clientProxy.operationSucceeded(registrationId);
linkMatchingImages(channelEndpoint, subscription);
}
use of io.aeron.driver.media.ReceiveChannelEndpoint 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 io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.
the class DriverConductor method onRemoveSubscription.
void onRemoveSubscription(final long registrationId, final long correlationId) {
final SubscriptionLink subscription = removeSubscriptionLink(subscriptionLinks, registrationId);
if (null == subscription) {
throw new ControlProtocolException(UNKNOWN_SUBSCRIPTION, "Unknown Subscription: " + registrationId);
}
subscription.close();
final ReceiveChannelEndpoint channelEndpoint = subscription.channelEndpoint();
if (null != channelEndpoint) {
final int refCount = channelEndpoint.decRefToStream(subscription.streamId());
if (0 == refCount) {
receiverProxy.removeSubscription(channelEndpoint, subscription.streamId());
}
if (channelEndpoint.shouldBeClosed()) {
channelEndpoint.closeStatusIndicator();
receiveChannelEndpointByChannelMap.remove(channelEndpoint.udpChannel().canonicalForm());
receiverProxy.closeReceiveChannelEndpoint(channelEndpoint);
while (!channelEndpoint.isClosed()) {
Thread.yield();
}
}
}
clientProxy.operationSucceeded(correlationId);
}
use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.
the class DriverConductor method onCreatePublicationImage.
public void onCreatePublicationImage(final int sessionId, final int streamId, final int initialTermId, final int activeTermId, final int initialTermOffset, final int termBufferLength, final int senderMtuLength, final InetSocketAddress controlAddress, final InetSocketAddress sourceAddress, final ReceiveChannelEndpoint channelEndpoint) {
channelEndpoint.validateSenderMtuLength(senderMtuLength);
channelEndpoint.validateWindowMaxLength(context.initialWindowLength());
final UdpChannel udpChannel = channelEndpoint.udpChannel();
final String channel = udpChannel.originalUriString();
final long registrationId = nextImageCorrelationId();
final long joiningPosition = computePosition(activeTermId, initialTermOffset, Integer.numberOfTrailingZeros(termBufferLength), initialTermId);
final List<SubscriberPosition> subscriberPositions = createSubscriberPositions(sessionId, streamId, channelEndpoint, joiningPosition);
if (subscriberPositions.size() > 0) {
final RawLog rawLog = newPublicationImageLog(sessionId, streamId, initialTermId, termBufferLength, senderMtuLength, udpChannel, registrationId);
final CongestionControl congestionControl = context.congestionControlSupplier().newInstance(registrationId, udpChannel, streamId, sessionId, termBufferLength, senderMtuLength, nanoClock, context, countersManager);
final PublicationImage image = new PublicationImage(registrationId, imageLivenessTimeoutNs, channelEndpoint, controlAddress, sessionId, streamId, initialTermId, activeTermId, initialTermOffset, rawLog, udpChannel.isMulticast() ? NAK_MULTICAST_DELAY_GENERATOR : NAK_UNICAST_DELAY_GENERATOR, positionArray(subscriberPositions), ReceiverHwm.allocate(countersManager, registrationId, sessionId, streamId, channel), ReceiverPos.allocate(countersManager, registrationId, sessionId, streamId, channel), nanoClock, context.epochClock(), context.systemCounters(), sourceAddress, congestionControl, context.lossReport(), subscriberPositions.get(0).subscription().isReliable());
for (int i = 0, size = subscriberPositions.size(); i < size; i++) {
subscriberPositions.get(i).addLink(image);
}
publicationImages.add(image);
receiverProxy.newPublicationImage(channelEndpoint, image);
clientProxy.onAvailableImage(registrationId, streamId, sessionId, rawLog.fileName(), subscriberPositions, generateSourceIdentity(sourceAddress));
}
}
use of io.aeron.driver.media.ReceiveChannelEndpoint in project Aeron by real-logic.
the class DriverConductor method getOrCreateReceiveChannelEndpoint.
private ReceiveChannelEndpoint getOrCreateReceiveChannelEndpoint(final UdpChannel udpChannel) {
ReceiveChannelEndpoint channelEndpoint = receiveChannelEndpointByChannelMap.get(udpChannel.canonicalForm());
if (null == channelEndpoint) {
channelEndpoint = context.receiveChannelEndpointSupplier().newInstance(udpChannel, new DataPacketDispatcher(fromReceiverConductorProxy, receiverProxy.receiver()), ReceiveChannelStatus.allocate(countersManager, udpChannel.originalUriString()), context);
receiveChannelEndpointByChannelMap.put(udpChannel.canonicalForm(), channelEndpoint);
receiverProxy.registerReceiveChannelEndpoint(channelEndpoint);
}
return channelEndpoint;
}
Aggregations