Search in sources :

Example 76 with UdpChannel

use of io.aeron.driver.media.UdpChannel 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;
        }
    }
}
Also used : AtomicCounter(org.agrona.concurrent.status.AtomicCounter) PublicationParams(io.aeron.driver.PublicationParams) UdpChannel(io.aeron.driver.media.UdpChannel) ArrayListUtil.fastUnorderedRemove(org.agrona.collections.ArrayListUtil.fastUnorderedRemove) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Context(io.aeron.driver.MediaDriver.Context) ChannelUri(io.aeron.ChannelUri) AeronEvent(io.aeron.exceptions.AeronEvent) org.agrona.concurrent(org.agrona.concurrent) SPY_QUALIFIER(io.aeron.ChannelUri.SPY_QUALIFIER) RingBuffer(org.agrona.concurrent.ringbuffer.RingBuffer) BitUtil(org.agrona.BitUtil) ArrayList(java.util.ArrayList) FORCE_TRUE(io.aeron.CommonContext.InferableBoolean.FORCE_TRUE) ErrorCode(io.aeron.ErrorCode) DataHeaderFlyweight.createDefaultHeader(io.aeron.protocol.DataHeaderFlyweight.createDefaultHeader) SystemCounterDescriptor(io.aeron.driver.status.SystemCounterDescriptor) Position(org.agrona.concurrent.status.Position) RawLog(io.aeron.driver.buffer.RawLog) LogFactory(io.aeron.driver.buffer.LogFactory) ChannelEndpointStatus(io.aeron.status.ChannelEndpointStatus) CloseHelper(org.agrona.CloseHelper) InvalidChannelException(io.aeron.driver.exceptions.InvalidChannelException) Object2ObjectHashMap(org.agrona.collections.Object2ObjectHashMap) Aeron(io.aeron.Aeron) io.aeron.driver.status(io.aeron.driver.status) CountersManager(org.agrona.concurrent.status.CountersManager) CommonContext(io.aeron.CommonContext) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) InetSocketAddress(java.net.InetSocketAddress) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) TimeUnit(java.util.concurrent.TimeUnit) SubscriptionParams.validateInitialWindowForRcvBuf(io.aeron.driver.SubscriptionParams.validateInitialWindowForRcvBuf) ObjectHashSet(org.agrona.collections.ObjectHashSet) ReceiveDestinationTransport(io.aeron.driver.media.ReceiveDestinationTransport) UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) MutableDirectBuffer(org.agrona.MutableDirectBuffer) ControlProtocolException(io.aeron.exceptions.ControlProtocolException) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) INFER(io.aeron.CommonContext.InferableBoolean.INFER) DirectBuffer(org.agrona.DirectBuffer) UdpChannel(io.aeron.driver.media.UdpChannel) RawLog(io.aeron.driver.buffer.RawLog) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) InvalidChannelException(io.aeron.driver.exceptions.InvalidChannelException) ControlProtocolException(io.aeron.exceptions.ControlProtocolException) UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition)

Example 77 with UdpChannel

use of io.aeron.driver.media.UdpChannel 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, nameResolver);
    validateControlForSubscription(udpChannel);
    validateTimestampConfiguration(udpChannel);
    final SubscriptionParams params = SubscriptionParams.getSubscriptionParams(udpChannel.channelUri(), ctx);
    checkForClashingSubscription(params, udpChannel, streamId);
    final ReceiveChannelEndpoint channelEndpoint = getOrCreateReceiveChannelEndpoint(params, udpChannel, registrationId);
    final NetworkSubscriptionLink subscription = new NetworkSubscriptionLink(registrationId, channelEndpoint, streamId, channel, getOrAddClient(clientId), params);
    subscriptionLinks.add(subscription);
    if (params.hasSessionId) {
        if (1 == channelEndpoint.incRefToStreamAndSession(streamId, params.sessionId)) {
            receiverProxy.addSubscription(channelEndpoint, streamId, params.sessionId);
        }
    } else {
        if (1 == channelEndpoint.incRefToStream(streamId)) {
            receiverProxy.addSubscription(channelEndpoint, streamId);
        }
    }
    clientProxy.onSubscriptionReady(registrationId, channelEndpoint.statusIndicatorCounter().id());
    linkMatchingImages(subscription);
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint)

Example 78 with UdpChannel

use of io.aeron.driver.media.UdpChannel in project Aeron by real-logic.

the class DriverConductor method onAddSpySubscription.

void onAddSpySubscription(final String channel, final int streamId, final long registrationId, final long clientId) {
    final UdpChannel udpChannel = UdpChannel.parse(channel, nameResolver);
    final SubscriptionParams params = SubscriptionParams.getSubscriptionParams(udpChannel.channelUri(), ctx);
    final SpySubscriptionLink subscriptionLink = new SpySubscriptionLink(registrationId, udpChannel, streamId, getOrAddClient(clientId), params);
    subscriptionLinks.add(subscriptionLink);
    clientProxy.onSubscriptionReady(registrationId, ChannelEndpointStatus.NO_ID_ALLOCATED);
    for (int i = 0, size = networkPublications.size(); i < size; i++) {
        final NetworkPublication publication = networkPublications.get(i);
        if (subscriptionLink.matches(publication) && publication.isAcceptingSubscriptions()) {
            clientProxy.onAvailableImage(publication.registrationId(), streamId, publication.sessionId(), registrationId, linkSpy(publication, subscriptionLink).id(), publication.rawLog().fileName(), CommonContext.IPC_CHANNEL);
        }
    }
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Aggregations

UdpChannel (io.aeron.driver.media.UdpChannel)78 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)35 Test (org.junit.jupiter.api.Test)26 Test (org.junit.Test)18 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)12 Theory (org.junit.experimental.theories.Theory)11 CsvSource (org.junit.jupiter.params.provider.CsvSource)11 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)7 ChannelUri (io.aeron.ChannelUri)3 PublicationParams (io.aeron.driver.PublicationParams)3 ControlProtocolException (io.aeron.exceptions.ControlProtocolException)3 RawLog (io.aeron.driver.buffer.RawLog)2 ReceiveDestinationTransport (io.aeron.driver.media.ReceiveDestinationTransport)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 Aeron (io.aeron.Aeron)1 SPY_QUALIFIER (io.aeron.ChannelUri.SPY_QUALIFIER)1 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)1 CommonContext (io.aeron.CommonContext)1