Search in sources :

Example 6 with UnsafeBufferPosition

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

the class ClientConductor method onNewPublication.

void onNewPublication(final long correlationId, final long registrationId, final int streamId, final int sessionId, final int publicationLimitId, final int statusIndicatorId, final String logFileName) {
    final String stashedChannel = stashedChannelByRegistrationId.remove(correlationId);
    final ConcurrentPublication publication = new ConcurrentPublication(this, stashedChannel, streamId, sessionId, new UnsafeBufferPosition(counterValuesBuffer, publicationLimitId), statusIndicatorId, logBuffers(registrationId, logFileName, stashedChannel), registrationId, correlationId);
    resourceByRegIdMap.put(correlationId, publication);
}
Also used : UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition)

Example 7 with UnsafeBufferPosition

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

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

the class SubscriberPos method allocate.

/**
 * Allocate a new subscriber position counter for a stream.
 *
 * @param tempBuffer      to build the label.
 * @param countersManager to allocate the counter from.
 * @param clientId        that owns the subscription.
 * @param registrationId  associated with the counter.
 * @param sessionId       associated with the counter.
 * @param streamId        associated with the counter.
 * @param channel         associated with the counter.
 * @param joinPosition    for the stream.
 * @return the allocated counter.
 */
public static UnsafeBufferPosition allocate(final MutableDirectBuffer tempBuffer, final CountersManager countersManager, final long clientId, final long registrationId, final int sessionId, final int streamId, final String channel, final long joinPosition) {
    final UnsafeBufferPosition position = StreamCounter.allocate(tempBuffer, NAME, SUBSCRIBER_POSITION_TYPE_ID, countersManager, registrationId, sessionId, streamId, channel, joinPosition);
    countersManager.setCounterOwnerId(position.id(), clientId);
    return position;
}
Also used : UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition)

Example 9 with UnsafeBufferPosition

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

the class IpcPublicationTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() {
    final RingBuffer toDriverCommands = new ManyToOneRingBuffer(new UnsafeBuffer(ByteBuffer.allocate(Configuration.CONDUCTOR_BUFFER_LENGTH_DEFAULT)));
    final UnsafeBuffer counterBuffer = new UnsafeBuffer(ByteBuffer.allocate(BUFFER_LENGTH));
    final UnsafeBuffer metaDataBuffer = new UnsafeBuffer(ByteBuffer.allocate(Configuration.countersMetadataBufferLength(BUFFER_LENGTH)));
    final CountersManager countersManager = new CountersManager(metaDataBuffer, counterBuffer, StandardCharsets.US_ASCII);
    final SystemCounters systemCounters = new SystemCounters(countersManager);
    final MediaDriver.Context ctx = new MediaDriver.Context().tempBuffer(new UnsafeBuffer(new byte[METADATA_LENGTH])).ipcTermBufferLength(TERM_BUFFER_LENGTH).toDriverCommands(toDriverCommands).logFactory(new TestLogFactory()).clientProxy(mock(ClientProxy.class)).driverCommandQueue(mock(ManyToOneConcurrentArrayQueue.class)).epochClock(SystemEpochClock.INSTANCE).cachedEpochClock(new CachedEpochClock()).cachedNanoClock(new CachedNanoClock()).countersManager(countersManager).systemCounters(systemCounters).nameResolver(DefaultNameResolver.INSTANCE).nanoClock(new CachedNanoClock());
    ctx.countersValuesBuffer(counterBuffer);
    driverProxy = new DriverProxy(toDriverCommands, CLIENT_ID);
    driverConductor = new DriverConductor(ctx);
    driverConductor.onStart();
    driverProxy.addPublication(CommonContext.IPC_CHANNEL, STREAM_ID);
    driverConductor.doWork();
    ipcPublication = driverConductor.getSharedIpcPublication(STREAM_ID);
    publisherLimit = new UnsafeBufferPosition(counterBuffer, ipcPublication.publisherLimitId());
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) TestLogFactory(io.aeron.driver.buffer.TestLogFactory) SystemCounters(io.aeron.driver.status.SystemCounters) RingBuffer(org.agrona.concurrent.ringbuffer.RingBuffer) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) DriverProxy(io.aeron.DriverProxy) UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition) CountersManager(org.agrona.concurrent.status.CountersManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with UnsafeBufferPosition

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

the class ClientConductor method onNewPublication.

public void onNewPublication(final String channel, final int streamId, final int sessionId, final int publicationLimitId, final String logFileName, final long correlationId) {
    final Publication publication = new Publication(this, channel, streamId, sessionId, new UnsafeBufferPosition(counterValuesBuffer, publicationLimitId), logBuffersFactory.map(logFileName, FileChannel.MapMode.READ_WRITE), correlationId);
    activePublications.put(channel, streamId, publication);
}
Also used : UnsafeBufferPosition(org.agrona.concurrent.status.UnsafeBufferPosition)

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