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;
}
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;
}
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;
}
}
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());
}
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;
}
Aggregations