Search in sources :

Example 16 with UdpChannel

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

the class DriverConductorTest method shouldOnlyRemoveSubscriptionMediaEndpointUponRemovalOfAllSubscribers.

@Test
public void shouldOnlyRemoveSubscriptionMediaEndpointUponRemovalOfAllSubscribers() throws Exception {
    final UdpChannel udpChannel = UdpChannel.parse(CHANNEL_4000);
    final long id1 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
    final long id2 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_2);
    final long id3 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_3);
    driverConductor.doWork();
    final ReceiveChannelEndpoint channelEndpoint = driverConductor.receiverChannelEndpoint(udpChannel);
    assertNotNull(channelEndpoint);
    assertThat(channelEndpoint.streamCount(), is(3));
    driverProxy.removeSubscription(id2);
    driverProxy.removeSubscription(id3);
    driverConductor.doWork();
    assertNotNull(driverConductor.receiverChannelEndpoint(udpChannel));
    assertThat(channelEndpoint.streamCount(), is(1));
    driverProxy.removeSubscription(id1);
    driverConductor.doWork();
    assertNull(driverConductor.receiverChannelEndpoint(udpChannel));
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Example 17 with UdpChannel

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

the class DriverConductorTest method shouldKeepSubscriptionMediaEndpointUponRemovalOfAllButOneSubscriber.

@Test
public void shouldKeepSubscriptionMediaEndpointUponRemovalOfAllButOneSubscriber() throws Exception {
    final UdpChannel udpChannel = UdpChannel.parse(CHANNEL_4000);
    final long id1 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1);
    final long id2 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_2);
    driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_3);
    driverConductor.doWork();
    final ReceiveChannelEndpoint channelEndpoint = driverConductor.receiverChannelEndpoint(udpChannel);
    assertNotNull(channelEndpoint);
    assertThat(channelEndpoint.streamCount(), is(3));
    driverProxy.removeSubscription(id1);
    driverProxy.removeSubscription(id2);
    driverConductor.doWork();
    assertNotNull(driverConductor.receiverChannelEndpoint(udpChannel));
    assertThat(channelEndpoint.streamCount(), is(1));
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.Test)

Example 18 with UdpChannel

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

the class DriverConductor method onAddNetworkPublication.

void onAddNetworkPublication(final String channel, final int streamId, final long registrationId, final long clientId, final boolean isExclusive) {
    final UdpChannel udpChannel = UdpChannel.parse(channel);
    final AeronUri aeronUri = udpChannel.aeronUri();
    final int mtuLength = getMtuLength(aeronUri, context.mtuLength());
    final int termLength = getTermBufferLength(aeronUri, context.publicationTermBufferLength());
    final SendChannelEndpoint channelEndpoint = getOrCreateSendChannelEndpoint(udpChannel);
    NetworkPublication publication = null;
    if (!isExclusive) {
        publication = findPublication(networkPublications, streamId, channelEndpoint);
    }
    if (null == publication) {
        final int sessionId = nextSessionId++;
        final int initialTermId = BitUtil.generateRandomisedId();
        final RetransmitHandler retransmitHandler = new RetransmitHandler(nanoClock, context.systemCounters(), RETRANSMIT_UNICAST_DELAY_GENERATOR, RETRANSMIT_UNICAST_LINGER_GENERATOR);
        final FlowControl flowControl = udpChannel.isMulticast() || udpChannel.hasExplicitControl() ? context.multicastFlowControlSupplier().newInstance(udpChannel, streamId, registrationId) : context.unicastFlowControlSupplier().newInstance(udpChannel, streamId, registrationId);
        publication = new NetworkPublication(registrationId, channelEndpoint, nanoClock, toDriverCommands::consumerHeartbeatTime, newNetworkPublicationLog(sessionId, streamId, initialTermId, udpChannel, registrationId, termLength), PublisherLimit.allocate(countersManager, registrationId, sessionId, streamId, channel), SenderPos.allocate(countersManager, registrationId, sessionId, streamId, channel), SenderLimit.allocate(countersManager, registrationId, sessionId, streamId, channel), sessionId, streamId, initialTermId, mtuLength, context.systemCounters(), flowControl, retransmitHandler, networkPublicationThreadLocals, publicationUnblockTimeoutNs, isExclusive);
        channelEndpoint.incRef();
        networkPublications.add(publication);
        senderProxy.newNetworkPublication(publication);
        linkSpies(subscriptionLinks, publication);
    } else if (publication.mtuLength() != mtuLength) {
        throw new IllegalStateException("Existing publication has different MTU length: existing=" + publication.mtuLength() + " requested=" + mtuLength);
    }
    publicationLinks.add(new PublicationLink(registrationId, publication, getOrAddClient(clientId)));
    clientProxy.onPublicationReady(registrationId, streamId, publication.sessionId(), publication.rawLog().fileName(), publication.publisherLimitId(), isExclusive);
}
Also used : SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) AeronUri(io.aeron.driver.uri.AeronUri) UdpChannel(io.aeron.driver.media.UdpChannel) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Example 19 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);
    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);
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Example 20 with UdpChannel

use of io.aeron.driver.media.UdpChannel 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));
    }
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) RawLog(io.aeron.driver.buffer.RawLog) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

Aggregations

UdpChannel (io.aeron.driver.media.UdpChannel)31 Test (org.junit.Test)16 Theory (org.junit.experimental.theories.Theory)11 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)6 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)4 RawLog (io.aeron.driver.buffer.RawLog)1 AeronUri (io.aeron.driver.uri.AeronUri)1 HashMap (java.util.HashMap)1