use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class CommonContext method requestDriverTermination.
/**
* Request a driver to run its termination hook.
*
* @param directory for the driver.
* @param tokenBuffer containing the optional token for the request.
* @param tokenOffset within the tokenBuffer at which the token begins.
* @param tokenLength of the token in the tokenBuffer.
* @return true if request was sent or false if request could not be sent.
*/
public static boolean requestDriverTermination(final File directory, final DirectBuffer tokenBuffer, final int tokenOffset, final int tokenLength) {
final File cncFile = new File(directory, CncFileDescriptor.CNC_FILE);
if (cncFile.exists() && cncFile.length() > 0) {
final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "CnC file");
try {
final UnsafeBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
final int cncVersion = cncMetaDataBuffer.getIntVolatile(cncVersionOffset(0));
CncFileDescriptor.checkVersion(cncVersion);
final ManyToOneRingBuffer toDriverBuffer = new ManyToOneRingBuffer(CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer));
final long clientId = toDriverBuffer.nextCorrelationId();
final DriverProxy driverProxy = new DriverProxy(toDriverBuffer, clientId);
return driverProxy.terminateDriver(tokenBuffer, tokenOffset, tokenLength);
} finally {
BufferUtil.free(cncByteBuffer);
}
}
return false;
}
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 logAddress.
/**
* Log an address with associated event.
*
* @param code representing the event type.
* @param address to be logged.
*/
public void logAddress(final DriverEventCode code, final InetSocketAddress address) {
final int length = socketAddressLength(address);
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(toEventCodeId(code), encodedLength);
if (index > 0) {
try {
encode((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, address);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class DriverEventLogger method logImageRemoval.
/**
* Log the removal of an image from the driver.
*
* @param channel for the channel.
* @param sessionId for the image.
* @param streamId for the image.
* @param correlationId for the image.
*/
public void logImageRemoval(final String channel, final int sessionId, final int streamId, final long correlationId) {
final int length = SIZE_OF_INT * 3 + 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_IMAGE_CLEANUP), encodedLength);
if (index > 0) {
try {
final UnsafeBuffer buffer = (UnsafeBuffer) ringBuffer.buffer();
encodeImageRemoval(buffer, index, captureLength, length, channel, sessionId, streamId, correlationId);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class ClusterEventLogger method logCanvassPosition.
/**
* Log a canvass position event received by the cluster node.
*
* @param logLeadershipTermId leadershipTermId reached by the member for it recorded log.
* @param leadershipTermId the most current leadershipTermId a member has seen.
* @param logPosition position the member has durably recorded.
* @param followerMemberId member who sent the event.
*/
public void logCanvassPosition(final long logLeadershipTermId, final long leadershipTermId, final long logPosition, final int followerMemberId) {
final int length = canvassPositionLength();
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(CANVASS_POSITION.toEventCodeId(), encodedLength);
if (index > 0) {
try {
encodeCanvassPosition((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, logLeadershipTermId, leadershipTermId, logPosition, followerMemberId);
} finally {
ringBuffer.commit(index);
}
}
}
Aggregations