use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class DriverTool method main.
public static void main(final String[] args) throws Exception {
boolean printPidOnly = false;
if (0 != args.length) {
checkForHelp(args);
if (args[0].equals("pid")) {
printPidOnly = true;
}
}
final File cncFile = CommonContext.newDefaultCncFile();
final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
if (CncFileDescriptor.CNC_VERSION != cncVersion) {
throw new IllegalStateException("Aeron CnC version does not match: version=" + cncVersion + " required=" + CNC_VERSION);
}
final ManyToOneRingBuffer toDriver = new ManyToOneRingBuffer(createToDriverBuffer(cncByteBuffer, cncMetaData));
if (printPidOnly) {
System.out.println(pid(cncMetaData));
} else {
System.out.println("Command `n Control file %s" + cncFile);
System.out.format("Version: %d, PID: %d%n", cncVersion, pid(cncMetaData));
printDateActivityAndStartTimestamps(startTimestamp(cncMetaData), toDriver.consumerHeartbeatTime());
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class IpcPublicationTest method setUp.
@SuppressWarnings("unchecked")
@Before
public void setUp() {
final RingBuffer fromClientCommands = new ManyToOneRingBuffer(new UnsafeBuffer(ByteBuffer.allocateDirect(Configuration.CONDUCTOR_BUFFER_LENGTH)));
final RawLogFactory mockRawLogFactory = mock(RawLogFactory.class);
final UnsafeBuffer counterBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_LENGTH));
final CountersManager countersManager = new CountersManager(new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_LENGTH * 2)), counterBuffer, StandardCharsets.US_ASCII);
when(mockRawLogFactory.newIpcPublication(anyInt(), anyInt(), anyLong(), anyInt())).thenReturn(LogBufferHelper.newTestLogBuffers(TERM_BUFFER_LENGTH));
final MediaDriver.Context ctx = new MediaDriver.Context().tempBuffer(new UnsafeBuffer(new byte[METADATA_LENGTH])).ipcTermBufferLength(TERM_BUFFER_LENGTH).toDriverCommands(fromClientCommands).rawLogBuffersFactory(mockRawLogFactory).clientProxy(mock(ClientProxy.class)).driverCommandQueue(mock(ManyToOneConcurrentArrayQueue.class)).epochClock(new SystemEpochClock()).cachedEpochClock(new CachedEpochClock()).cachedNanoClock(new CachedNanoClock()).countersManager(countersManager).systemCounters(mock(SystemCounters.class)).nanoClock(nanoClock);
ctx.countersValuesBuffer(counterBuffer);
driverProxy = new DriverProxy(fromClientCommands, CLIENT_ID);
driverConductor = new DriverConductor(ctx);
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.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.
the class DriverEventLogger method logPublicationRemoval.
/**
* Log the removal of a publication.
*
* @param channel for the channel.
* @param sessionId for the publication.
* @param streamId within the channel.
*/
public void logPublicationRemoval(final String channel, final int sessionId, final int streamId) {
final int length = SIZE_OF_INT * 3 + channel.length();
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(toEventCodeId(REMOVE_PUBLICATION_CLEANUP), encodedLength);
if (index > 0) {
try {
final UnsafeBuffer buffer = (UnsafeBuffer) ringBuffer.buffer();
encodePublicationRemoval(buffer, index, captureLength, length, channel, sessionId, streamId);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.
the class DriverEventLogger method logFrameOut.
/**
* Log a frame being sent out from the driver to the media.
*
* @param buffer containing the frame.
* @param dstAddress for the frame.
*/
public void logFrameOut(final ByteBuffer buffer, final InetSocketAddress dstAddress) {
final int length = buffer.remaining() + socketAddressLength(dstAddress);
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(toEventCodeId(FRAME_OUT), encodedLength);
if (index > 0) {
try {
encode((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, buffer, buffer.position(), dstAddress);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.
the class DriverEventLogger method logSubscriptionRemoval.
/**
* Log the removal of a subscription.
*
* @param channel for the channel.
* @param streamId within the channel.
* @param subscriptionId for the subscription.
*/
public void logSubscriptionRemoval(final String channel, final int streamId, final long subscriptionId) {
final int length = SIZE_OF_INT * 2 + SIZE_OF_LONG + channel.length();
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(toEventCodeId(REMOVE_SUBSCRIPTION_CLEANUP), encodedLength);
if (index > 0) {
try {
final UnsafeBuffer buffer = (UnsafeBuffer) ringBuffer.buffer();
encodeSubscriptionRemoval(buffer, index, captureLength, length, channel, streamId, subscriptionId);
} finally {
ringBuffer.commit(index);
}
}
}
Aggregations