Search in sources :

Example 11 with ManyToOneRingBuffer

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;
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) File(java.io.File)

Example 12 with ManyToOneRingBuffer

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);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 13 with ManyToOneRingBuffer

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);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 14 with ManyToOneRingBuffer

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);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 15 with ManyToOneRingBuffer

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);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Aggregations

ManyToOneRingBuffer (org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)50 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)12 File (java.io.File)5 MappedByteBuffer (java.nio.MappedByteBuffer)5 DriverProxy (io.aeron.DriverProxy)4 DriverTimeoutException (io.aeron.exceptions.DriverTimeoutException)3 TestLogFactory (io.aeron.driver.buffer.TestLogFactory)2 SystemCounters (io.aeron.driver.status.SystemCounters)2 AeronException (io.aeron.exceptions.AeronException)2 DirectBuffer (org.agrona.DirectBuffer)2 RingBuffer (org.agrona.concurrent.ringbuffer.RingBuffer)2 CountersManager (org.agrona.concurrent.status.CountersManager)2 UnsafeBufferPosition (org.agrona.concurrent.status.UnsafeBufferPosition)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2