Search in sources :

Example 26 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)

Example 27 with ManyToOneRingBuffer

use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.

the class ClusterEventLogger method logStateChange.

/**
 * Log a state change event for a cluster node.
 *
 * @param eventCode for the type of state change.
 * @param oldState  before the change.
 * @param newState  after the change.
 * @param memberId  on which the change has taken place.
 * @param <E>       type representing the state change.
 */
public <E extends Enum<E>> void logStateChange(final ClusterEventCode eventCode, final E oldState, final E newState, final int memberId) {
    final int length = stateChangeLength(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 {
            encodeStateChange((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, oldState, newState, memberId);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 28 with ManyToOneRingBuffer

use of org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer in project Aeron by real-logic.

the class ClusterEventLogger method logElectionStateChange.

/**
 * Log an election state change event for a cluster node.
 *
 * @param oldState            before the change.
 * @param newState            after the change.
 * @param memberId            on which the change has taken place.
 * @param leaderId            of the cluster.
 * @param candidateTermId     of the node.
 * @param leadershipTermId    of the node.
 * @param logPosition         of the node.
 * @param logLeadershipTermId of the node.
 * @param appendPosition      of the node.
 * @param catchupPosition     of the node.
 * @param <E>                 type representing the state change.
 */
public <E extends Enum<E>> void logElectionStateChange(final E oldState, final E newState, final int memberId, final int leaderId, final long candidateTermId, final long leadershipTermId, final long logPosition, final long logLeadershipTermId, final long appendPosition, final long catchupPosition) {
    final int length = electionStateChangeLength(oldState, newState);
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(ELECTION_STATE_CHANGE.toEventCodeId(), encodedLength);
    if (index > 0) {
        try {
            encodeElectionStateChange((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, oldState, newState, memberId, leaderId, candidateTermId, leadershipTermId, logPosition, logLeadershipTermId, appendPosition, catchupPosition);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 29 with ManyToOneRingBuffer

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

Example 30 with ManyToOneRingBuffer

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);
        }
    }
}
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