Search in sources :

Example 6 with RawLog

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

the class DriverConductor method newPublicationImageLog.

private RawLog newPublicationImageLog(final int sessionId, final int streamId, final int initialTermId, final int termBufferLength, final int senderMtuLength, final UdpChannel udpChannel, final long correlationId) {
    final RawLog rawLog = rawLogFactory.newNetworkedImage(udpChannel.canonicalForm(), sessionId, streamId, correlationId, termBufferLength);
    final UnsafeBuffer logMetaData = rawLog.metaData();
    storeDefaultFrameHeader(logMetaData, createDefaultHeader(sessionId, streamId, initialTermId));
    initialTermId(logMetaData, initialTermId);
    mtuLength(logMetaData, senderMtuLength);
    termLength(logMetaData, termBufferLength);
    pageSize(logMetaData, context.filePageSize());
    correlationId(logMetaData, correlationId);
    endOfStreamPosition(logMetaData, Long.MAX_VALUE);
    return rawLog;
}
Also used : RawLog(io.aeron.driver.buffer.RawLog)

Example 7 with RawLog

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

the class DriverConductor method newNetworkPublicationLog.

private RawLog newNetworkPublicationLog(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 8 with RawLog

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

Example 9 with RawLog

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

the class DriverConductorTest method shouldTimeoutPublicationWithNoKeepaliveButNotDrained.

@Test
public void shouldTimeoutPublicationWithNoKeepaliveButNotDrained() {
    driverProxy.addPublication(CHANNEL_4000, STREAM_ID_1);
    driverConductor.doWork();
    final ArgumentCaptor<NetworkPublication> captor = ArgumentCaptor.forClass(NetworkPublication.class);
    verify(senderProxy, times(1)).newNetworkPublication(captor.capture());
    final NetworkPublication publication = captor.getValue();
    final int termId = 101;
    final int index = LogBufferDescriptor.indexByTerm(termId, termId);
    final RawLog rawLog = publication.rawLog();
    LogBufferDescriptor.rawTail(rawLog.metaData(), index, LogBufferDescriptor.packTail(termId, 0));
    final TermAppender appender = new TermAppender(rawLog.termBuffers()[index], rawLog.metaData(), index);
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[256]);
    final HeaderWriter headerWriter = HeaderWriter.newInstance(createDefaultHeader(SESSION_ID, STREAM_ID_1, termId));
    final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
    when(msg.consumptionTermId()).thenReturn(termId);
    when(msg.consumptionTermOffset()).thenReturn(0);
    when(msg.receiverWindowLength()).thenReturn(10);
    publication.onStatusMessage(msg, new InetSocketAddress("localhost", 4059));
    appender.appendUnfragmentedMessage(headerWriter, srcBuffer, 0, 256, null, termId);
    assertEquals(NetworkPublication.State.ACTIVE, publication.state());
    doWorkUntil(() -> nanoClock.nanoTime() >= CLIENT_LIVENESS_TIMEOUT_NS * 1.25, (timeNs) -> {
        publication.onStatusMessage(msg, new InetSocketAddress("localhost", 4059));
        publication.updateHasReceivers(timeNs);
    });
    assertThat(publication.state(), Matchers.anyOf(is(NetworkPublication.State.DRAINING), is(NetworkPublication.State.LINGER)));
    final long endTime = nanoClock.nanoTime() + publicationConnectionTimeoutNs() + DEFAULT_TIMER_INTERVAL_NS;
    doWorkUntil(() -> nanoClock.nanoTime() >= endTime, publication::updateHasReceivers);
    assertThat(publication.state(), Matchers.anyOf(is(NetworkPublication.State.LINGER), is(NetworkPublication.State.DONE)));
    nanoClock.advance(DEFAULT_TIMER_INTERVAL_NS + PUBLICATION_LINGER_TIMEOUT_NS);
    driverConductor.doWork();
    assertEquals(NetworkPublication.State.DONE, publication.state());
    verify(senderProxy).removeNetworkPublication(eq(publication));
    verify(senderProxy).registerSendChannelEndpoint(any());
}
Also used : StatusMessageFlyweight(io.aeron.protocol.StatusMessageFlyweight) InetSocketAddress(java.net.InetSocketAddress) RawLog(io.aeron.driver.buffer.RawLog) TermAppender(io.aeron.logbuffer.TermAppender) HeaderWriter(io.aeron.logbuffer.HeaderWriter) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) Test(org.junit.jupiter.api.Test)

Example 10 with RawLog

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

the class DriverConductor method addIpcPublication.

private IpcPublication addIpcPublication(final int streamId, final String channel, final boolean isExclusive) {
    final int termLength = getTermBufferLength(AeronUri.parse(channel), context.ipcTermBufferLength());
    final long registrationId = nextImageCorrelationId();
    final int sessionId = nextSessionId++;
    final int initialTermId = BitUtil.generateRandomisedId();
    final RawLog rawLog = newIpcPublicationLog(termLength, sessionId, streamId, initialTermId, registrationId);
    final Position publisherLimit = PublisherLimit.allocate(countersManager, registrationId, sessionId, streamId, channel);
    final IpcPublication publication = new IpcPublication(registrationId, sessionId, streamId, publisherLimit, rawLog, publicationUnblockTimeoutNs, context.systemCounters(), isExclusive);
    ipcPublications.add(publication);
    return publication;
}
Also used : Position(org.agrona.concurrent.status.Position) ReadablePosition(org.agrona.concurrent.status.ReadablePosition) RawLog(io.aeron.driver.buffer.RawLog) ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint)

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