Search in sources :

Example 16 with UnsafeBufferPosition

use of org.agrona.concurrent.status.UnsafeBufferPosition 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 17 with UnsafeBufferPosition

use of org.agrona.concurrent.status.UnsafeBufferPosition in project aeron by real-logic.

the class ClientConductor method onAvailableImage.

void onAvailableImage(final long correlationId, final int sessionId, final long subscriptionRegistrationId, final int subscriberPositionId, final String logFileName, final String sourceIdentity) {
    final Subscription subscription = (Subscription) resourceByRegIdMap.get(subscriptionRegistrationId);
    if (null != subscription) {
        final Image image = new Image(subscription, sessionId, new UnsafeBufferPosition(counterValuesBuffer, subscriberPositionId), logBuffers(correlationId, logFileName, subscription.channel()), ctx.subscriberErrorHandler(), sourceIdentity, correlationId);
        final AvailableImageHandler handler = subscription.availableImageHandler();
        if (null != handler) {
            isInCallback = true;
            try {
                handler.onAvailableImage(image);
            } catch (final Exception ex) {
                handleError(ex);
            } finally {
                isInCallback = false;
            }
        }
        subscription.addImage(image);
    }
}
Also used : UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition)

Example 18 with UnsafeBufferPosition

use of org.agrona.concurrent.status.UnsafeBufferPosition 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 19 with UnsafeBufferPosition

use of org.agrona.concurrent.status.UnsafeBufferPosition in project aeron by real-logic.

the class DriverConductor method addIpcPublication.

private IpcPublication addIpcPublication(final long registrationId, final long clientId, final int streamId, final String channel, final boolean isExclusive, final PublicationParams params) {
    final int sessionId = params.hasSessionId ? params.sessionId : nextAvailableSessionId(streamId, IPC_MEDIA);
    final int initialTermId = params.hasPosition ? params.initialTermId : BitUtil.generateRandomisedId();
    final RawLog rawLog = newIpcPublicationLog(sessionId, streamId, initialTermId, registrationId, params);
    UnsafeBufferPosition publisherPosition = null;
    UnsafeBufferPosition publisherLimit = null;
    try {
        publisherPosition = PublisherPos.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
        publisherLimit = PublisherLimit.allocate(tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
        countersManager.setCounterOwnerId(publisherLimit.id(), clientId);
        if (params.hasPosition) {
            final int positionBitsToShift = positionBitsToShift(params.termLength);
            final long position = computePosition(params.termId, params.termOffset, positionBitsToShift, initialTermId);
            publisherPosition.setOrdered(position);
            publisherLimit.setOrdered(position);
        }
        final IpcPublication publication = new IpcPublication(registrationId, channel, ctx, params.entityTag, sessionId, streamId, publisherPosition, publisherLimit, rawLog, Configuration.producerWindowLength(params.termLength, ctx.ipcPublicationTermWindowLength()), isExclusive, params);
        ipcPublications.add(publication);
        activeSessionSet.add(new SessionKey(sessionId, streamId, IPC_MEDIA));
        return publication;
    } catch (final Exception ex) {
        CloseHelper.quietCloseAll(rawLog, publisherPosition, publisherLimit);
        throw ex;
    }
}
Also used : UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) 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)

Aggregations

UnsafeBufferPosition (org.agrona.concurrent.status.UnsafeBufferPosition)19 RawLog (io.aeron.driver.buffer.RawLog)6 InvalidChannelException (io.aeron.driver.exceptions.InvalidChannelException)6 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)6 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)6 ControlProtocolException (io.aeron.exceptions.ControlProtocolException)6 RingBuffer (org.agrona.concurrent.ringbuffer.RingBuffer)4 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)4 CountersManager (org.agrona.concurrent.status.CountersManager)4 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