Search in sources :

Example 1 with INFER

use of io.aeron.CommonContext.InferableBoolean.INFER 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 2 with INFER

use of io.aeron.CommonContext.InferableBoolean.INFER 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)

Aggregations

Aeron (io.aeron.Aeron)2 ChannelUri (io.aeron.ChannelUri)2 SPY_QUALIFIER (io.aeron.ChannelUri.SPY_QUALIFIER)2 CommonContext (io.aeron.CommonContext)2 FORCE_TRUE (io.aeron.CommonContext.InferableBoolean.FORCE_TRUE)2 INFER (io.aeron.CommonContext.InferableBoolean.INFER)2 ErrorCode (io.aeron.ErrorCode)2 Context (io.aeron.driver.MediaDriver.Context)2 PublicationParams (io.aeron.driver.PublicationParams)2 SubscriptionParams.validateInitialWindowForRcvBuf (io.aeron.driver.SubscriptionParams.validateInitialWindowForRcvBuf)2 LogFactory (io.aeron.driver.buffer.LogFactory)2 RawLog (io.aeron.driver.buffer.RawLog)2 InvalidChannelException (io.aeron.driver.exceptions.InvalidChannelException)2 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)2 ReceiveDestinationTransport (io.aeron.driver.media.ReceiveDestinationTransport)2 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)2 UdpChannel (io.aeron.driver.media.UdpChannel)2 io.aeron.driver.status (io.aeron.driver.status)2 SystemCounterDescriptor (io.aeron.driver.status.SystemCounterDescriptor)2 AeronEvent (io.aeron.exceptions.AeronEvent)2