Search in sources :

Example 41 with ManyToOneRingBuffer

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

the class DriverEventLogger method logFlowControlReceiver.

/**
 * Log the information about receiver for the corresponding flow control event.
 *
 * @param code          flow control event type.
 * @param receiverId    of the receiver.
 * @param sessionId     of the image.
 * @param streamId      of the image.
 * @param channel       uri of the channel.
 * @param receiverCount number of the receivers after the event.
 */
public void logFlowControlReceiver(final DriverEventCode code, final long receiverId, final int sessionId, final int streamId, final String channel, final int receiverCount) {
    final int length = SIZE_OF_INT * 4 + 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(code), encodedLength);
    if (index > 0) {
        try {
            encodeFlowControlReceiver((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, receiverId, sessionId, streamId, channel, receiverCount);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 42 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 43 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 44 with ManyToOneRingBuffer

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

the class ClusterEventLogger method logRequestVote.

/**
 * Log a request to vote from a cluster candidate for leadership.
 *
 * @param logLeadershipTermId leadershipTermId processes from the log by the candidate.
 * @param logPosition         position reached in the log for the latest leadership term.
 * @param candidateTermId     the term id as the candidate sees it for the election.
 * @param candidateId         id of the candidate node.
 */
public void logRequestVote(final long logLeadershipTermId, final long logPosition, final long candidateTermId, final int candidateId) {
    final int length = requestVoteLength();
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(REQUEST_VOTE.toEventCodeId(), encodedLength);
    if (index > 0) {
        try {
            encodeRequestVote((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, logLeadershipTermId, logPosition, candidateTermId, candidateId);
        } finally {
            ringBuffer.commit(index);
        }
    }
}
Also used : ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)

Example 45 with ManyToOneRingBuffer

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

the class ClusterEventLogger method logNewLeadershipTerm.

/**
 * Log a new leadership term event.
 *
 * @param logLeadershipTermId     term for which log entries are present.
 * @param nextLeadershipTermId    next term relative to the logLeadershipTermId
 * @param nextTermBaseLogPosition base log position for the next term.
 * @param nextLogPosition         committed log position for next term.
 * @param leadershipTermId        new leadership term id.
 * @param termBaseLogPosition     position the log reached at base of new term.
 * @param logPosition             position the log reached for the new term.
 * @param leaderRecordingId       of the log in the leader archive.
 * @param timestamp               of the new term.
 * @param leaderMemberId          member id for the new leader.
 * @param logSessionId            session id of the log extension.
 * @param isStartup               is the leader starting up fresh.
 */
public void logNewLeadershipTerm(final long logLeadershipTermId, final long nextLeadershipTermId, final long nextTermBaseLogPosition, final long nextLogPosition, final long leadershipTermId, final long termBaseLogPosition, final long logPosition, final long leaderRecordingId, final long timestamp, final int leaderMemberId, final int logSessionId, final boolean isStartup) {
    final int length = newLeaderShipTermLength();
    final int captureLength = captureLength(length);
    final int encodedLength = encodedLength(captureLength);
    final ManyToOneRingBuffer ringBuffer = this.ringBuffer;
    final int index = ringBuffer.tryClaim(NEW_LEADERSHIP_TERM.toEventCodeId(), encodedLength);
    if (index > 0) {
        try {
            encodeNewLeadershipTerm((UnsafeBuffer) ringBuffer.buffer(), index, captureLength, length, logLeadershipTermId, nextLeadershipTermId, nextTermBaseLogPosition, nextLogPosition, leadershipTermId, termBaseLogPosition, logPosition, leaderRecordingId, timestamp, leaderMemberId, logSessionId, isStartup);
        } 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