use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class ArchiveEventLogger method log.
/**
* Log an Archive control event.
*
* @param eventCode for the type of control event.
* @param buffer containing the encoded event.
* @param offset in the buffer at which the event begins.
* @param length of the encoded event.
*/
private void log(final ArchiveEventCode eventCode, final DirectBuffer buffer, final int offset, final int length) {
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(eventCode.toEventCodeId(), encodedLength);
if (index > 0) {
try {
encode((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, buffer, offset);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class ArchiveEventLogger method logReplaySessionError.
/**
* Log a control response error.
*
* @param sessionId associated with the response.
* @param recordingId to which the error applies.
* @param errorMessage which resulted.
*/
public void logReplaySessionError(final long sessionId, final long recordingId, final String errorMessage) {
final int length = SIZE_OF_LONG * 2 + SIZE_OF_INT + errorMessage.length();
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(REPLAY_SESSION_ERROR.toEventCodeId(), encodedLength);
if (index > 0) {
try {
encodeReplaySessionError((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, sessionId, recordingId, errorMessage);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class ArchiveEventLogger method logSessionStateChange.
/**
* Log a state change event for an archive control session
*
* @param eventCode for the type of state change.
* @param oldState before the change.
* @param newState after the change.
* @param controlSessionId identity for the control session on the Archive.
* @param <E> type representing the state change.
*/
public <E extends Enum<E>> void logSessionStateChange(final ArchiveEventCode eventCode, final E oldState, final E newState, final long controlSessionId) {
final int length = sessionStateChangeLength(oldState, newState);
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(eventCode.toEventCodeId(), encodedLength);
if (index > 0) {
try {
encodeSessionStateChange((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, oldState, newState, controlSessionId);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class ArchiveEventLogger method logCatalogResize.
/**
* Log a Catalog resize event.
*
* @param oldCatalogLength before the resize.
* @param newCatalogLength after the resize.
*/
public void logCatalogResize(final long oldCatalogLength, final long newCatalogLength) {
final int length = SIZE_OF_LONG * 2;
final int captureLength = captureLength(length);
final int encodedLength = encodedLength(captureLength);
final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
final int index = ringBuffer.tryClaim(CATALOG_RESIZE.toEventCodeId(), encodedLength);
if (index > 0) {
try {
encodeCatalogResize((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, oldCatalogLength, newCatalogLength);
} finally {
ringBuffer.commit(index);
}
}
}
use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project aeron by real-logic.
the class CommonContext method isDriverActive.
/**
* Is a media driver active in the current mapped CnC buffer? If the driver is starting then it will wait for
* up to the driverTimeoutMs by checking for the cncVersion being set.
*
* @param driverTimeoutMs for the driver liveness check.
* @param logger for feedback as liveness checked.
* @param cncByteBuffer for the existing CnC file.
* @return true if a driver is active or false if not.
*/
public static boolean isDriverActive(final long driverTimeoutMs, final Consumer<String> logger, final ByteBuffer cncByteBuffer) {
if (null == cncByteBuffer) {
return false;
}
final UnsafeBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
final long startTimeMs = System.currentTimeMillis();
int cncVersion;
while (0 == (cncVersion = cncMetaDataBuffer.getIntVolatile(CncFileDescriptor.cncVersionOffset(0)))) {
if (System.currentTimeMillis() > (startTimeMs + driverTimeoutMs)) {
throw new DriverTimeoutException("CnC file is created but not initialised.");
}
sleep(1);
}
CncFileDescriptor.checkVersion(cncVersion);
final ManyToOneRingBuffer toDriverBuffer = new ManyToOneRingBuffer(CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer));
final long timestampMs = toDriverBuffer.consumerHeartbeatTime();
final long nowMs = System.currentTimeMillis();
final long timestampAgeMs = nowMs - timestampMs;
logger.accept("INFO: Aeron toDriver consumer heartbeat is (ms): " + timestampAgeMs);
return timestampAgeMs <= driverTimeoutMs;
}
Aggregations