Search in sources :

Example 16 with RawLog

use of io.aeron.driver.buffer.RawLog in project Aeron by real-logic.

the class DriverConductor method newIpcPublicationLog.

private RawLog newIpcPublicationLog(final int sessionId, final int streamId, final int initialTermId, final long registrationId, final PublicationParams params) {
    final RawLog rawLog = logFactory.newPublication(registrationId, params.termLength, params.isSparse);
    initLogMetadata(sessionId, streamId, initialTermId, params.mtuLength, registrationId, rawLog);
    initialisePositionCounters(initialTermId, params, rawLog.metaData());
    return rawLog;
}
Also used : RawLog(io.aeron.driver.buffer.RawLog)

Example 17 with RawLog

use of io.aeron.driver.buffer.RawLog in project Aeron by real-logic.

the class DriverConductor method newNetworkPublication.

private NetworkPublication newNetworkPublication(final long registrationId, final long clientId, final int streamId, final String channel, final UdpChannel udpChannel, final SendChannelEndpoint channelEndpoint, final PublicationParams params, final boolean isExclusive) {
    final String canonicalForm = udpChannel.canonicalForm();
    final int sessionId = params.hasSessionId ? params.sessionId : nextAvailableSessionId(streamId, canonicalForm);
    final int initialTermId = params.hasPosition ? params.initialTermId : BitUtil.generateRandomisedId();
    final FlowControl flowControl = udpChannel.isMulticast() || udpChannel.isMultiDestination() ? ctx.multicastFlowControlSupplier().newInstance(udpChannel, streamId, registrationId) : ctx.unicastFlowControlSupplier().newInstance(udpChannel, streamId, registrationId);
    flowControl.initialize(ctx, udpChannel, initialTermId, params.termLength);
    final RawLog rawLog = newNetworkPublicationLog(sessionId, streamId, initialTermId, registrationId, params);
    UnsafeBufferPosition publisherPos = null;
    UnsafeBufferPosition publisherLmt = null;
    UnsafeBufferPosition senderPos = null;
    UnsafeBufferPosition senderLmt = null;
    AtomicCounter senderBpe = null;
    try {
        publisherPos = PublisherPos.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
        publisherLmt = PublisherLimit.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
        senderPos = SenderPos.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
        senderLmt = SenderLimit.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
        senderBpe = SenderBpe.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
        countersManager.setCounterOwnerId(publisherLmt.id(), clientId);
        if (params.hasPosition) {
            final int bits = LogBufferDescriptor.positionBitsToShift(params.termLength);
            final long position = computePosition(params.termId, params.termOffset, bits, initialTermId);
            publisherPos.setOrdered(position);
            publisherLmt.setOrdered(position);
            senderPos.setOrdered(position);
            senderLmt.setOrdered(position);
        }
        final RetransmitHandler retransmitHandler = new RetransmitHandler(ctx.senderCachedNanoClock(), ctx.systemCounters().get(INVALID_PACKETS), ctx.retransmitUnicastDelayGenerator(), ctx.retransmitUnicastLingerGenerator());
        final NetworkPublication publication = new NetworkPublication(registrationId, ctx, params, channelEndpoint, rawLog, Configuration.producerWindowLength(params.termLength, ctx.publicationTermWindowLength()), publisherPos, publisherLmt, senderPos, senderLmt, senderBpe, sessionId, streamId, initialTermId, flowControl, retransmitHandler, networkPublicationThreadLocals, isExclusive);
        channelEndpoint.incRef();
        networkPublications.add(publication);
        senderProxy.newNetworkPublication(publication);
        activeSessionSet.add(new SessionKey(sessionId, streamId, canonicalForm));
        return publication;
    } catch (final Exception ex) {
        CloseHelper.quietCloseAll(rawLog, publisherPos, publisherLmt, senderPos, senderLmt, senderBpe);
        throw ex;
    }
}
Also used : UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) RawLog(io.aeron.driver.buffer.RawLog) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) InvalidChannelException(io.aeron.driver.exceptions.InvalidChannelException) ControlProtocolException(io.aeron.exceptions.ControlProtocolException)

Example 18 with RawLog

use of io.aeron.driver.buffer.RawLog 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

RawLog (io.aeron.driver.buffer.RawLog)18 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)9 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)6 InetSocketAddress (java.net.InetSocketAddress)4 InvalidChannelException (io.aeron.driver.exceptions.InvalidChannelException)3 ControlProtocolException (io.aeron.exceptions.ControlProtocolException)3 HeaderWriter (io.aeron.logbuffer.HeaderWriter)3 TermAppender (io.aeron.logbuffer.TermAppender)3 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)3 UnsafeBufferPosition (org.agrona.concurrent.status.UnsafeBufferPosition)3 UdpChannel (io.aeron.driver.media.UdpChannel)2 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)2 Position (org.agrona.concurrent.status.Position)2 Test (org.junit.Test)2 Aeron (io.aeron.Aeron)1 ChannelUri (io.aeron.ChannelUri)1 SPY_QUALIFIER (io.aeron.ChannelUri.SPY_QUALIFIER)1 CommonContext (io.aeron.CommonContext)1 FORCE_TRUE (io.aeron.CommonContext.InferableBoolean.FORCE_TRUE)1 INFER (io.aeron.CommonContext.InferableBoolean.INFER)1