use of org.agrona.concurrent.status.UnsafeBufferPosition in project Aeron by real-logic.
the class ClientConductor method onNewExclusivePublication.
public void onNewExclusivePublication(final String channel, final int streamId, final int sessionId, final int publicationLimitId, final String logFileName, final long correlationId) {
final ExclusivePublication publication = new ExclusivePublication(this, channel, streamId, sessionId, new UnsafeBufferPosition(counterValuesBuffer, publicationLimitId), logBuffersFactory.map(logFileName, FileChannel.MapMode.READ_WRITE), correlationId);
activeExclusivePublications.put(correlationId, publication);
}
use of org.agrona.concurrent.status.UnsafeBufferPosition in project Aeron by real-logic.
the class ClientConductor method onAvailableImage.
public void onAvailableImage(final int streamId, final int sessionId, final Long2LongHashMap subscriberPositionMap, final String logFileName, final String sourceIdentity, final long correlationId) {
activeSubscriptions.forEach(streamId, (subscription) -> {
if (!subscription.hasImage(correlationId)) {
final long positionId = subscriberPositionMap.get(subscription.registrationId());
if (DriverListenerAdapter.MISSING_REGISTRATION_ID != positionId) {
final Image image = new Image(subscription, sessionId, new UnsafeBufferPosition(counterValuesBuffer, (int) positionId), logBuffersFactory.map(logFileName, imageMapMode), errorHandler, sourceIdentity, correlationId);
subscription.addImage(image);
try {
final AvailableImageHandler handler = subscription.availableImageHandler();
if (null != handler) {
handler.onAvailableImage(image);
}
} catch (final Throwable ex) {
errorHandler.onError(ex);
}
}
}
});
}
use of org.agrona.concurrent.status.UnsafeBufferPosition in project Aeron by real-logic.
the class ClientConductor method onNewExclusivePublication.
void onNewExclusivePublication(final long correlationId, final long registrationId, final int streamId, final int sessionId, final int publicationLimitId, final int statusIndicatorId, final String logFileName) {
if (correlationId != registrationId) {
handleError(new IllegalStateException("correlationId=" + correlationId + " registrationId=" + registrationId));
}
final String stashedChannel = stashedChannelByRegistrationId.remove(correlationId);
final ExclusivePublication publication = new ExclusivePublication(this, stashedChannel, streamId, sessionId, new UnsafeBufferPosition(counterValuesBuffer, publicationLimitId), statusIndicatorId, logBuffers(registrationId, logFileName, stashedChannel), registrationId, correlationId);
resourceByRegIdMap.put(correlationId, publication);
}
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());
}
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;
}
}
Aggregations