use of io.aeron.status.ReadableCounter in project aeron by real-logic.
the class SequencerAgent method createPositionCounters.
private void createPositionCounters() {
final CountersReader counters = aeron.countersReader();
final int recordingCounterId = awaitRecordingCounter(counters, logSessionId);
logRecordingPosition = new ReadableCounter(counters, recordingCounterId);
commitPosition = CommitPos.allocate(aeron, tempBuffer, leadershipTermId, termBaseLogPosition, CommitPos.NULL_VALUE);
}
use of io.aeron.status.ReadableCounter in project Aeron by real-logic.
the class ConsensusModuleAgent method tryCreateAppendPosition.
private boolean tryCreateAppendPosition(final int logSessionId) {
final CountersReader counters = aeron.countersReader();
final int counterId = RecordingPos.findCounterIdBySession(counters, logSessionId);
if (CountersReader.NULL_COUNTER_ID == counterId) {
return false;
}
final long registrationId = counters.getCounterRegistrationId(counterId);
if (0 == registrationId) {
return false;
}
logRecordingId = RecordingPos.getRecordingId(counters, counterId);
appendPosition = new ReadableCounter(counters, registrationId, counterId);
logRecordedPosition = NULL_POSITION;
return true;
}
use of io.aeron.status.ReadableCounter in project Aeron by real-logic.
the class CounterTest method shouldBeAbleToAddReadableCounterWithinHandler.
@Test
@InterruptAfter(10)
void shouldBeAbleToAddReadableCounterWithinHandler() {
clientB.addAvailableCounterHandler(this::createReadableCounter);
final Counter counter = clientA.addCounter(COUNTER_TYPE_ID, keyBuffer, 0, keyBuffer.capacity(), labelBuffer, 0, COUNTER_LABEL.length());
while (null == readableCounter) {
Tests.sleep(1);
}
assertEquals(CountersReader.RECORD_ALLOCATED, readableCounter.state());
assertEquals(counter.id(), readableCounter.counterId());
assertEquals(counter.registrationId(), readableCounter.registrationId());
}
use of io.aeron.status.ReadableCounter in project aeron by real-logic.
the class ClusteredServiceAgent method checkForReplay.
private void checkForReplay(final CountersReader counters, final int recoveryCounterId) {
final long replayTermCount = RecoveryState.getReplayTermCount(counters, recoveryCounterId);
if (0 == replayTermCount) {
return;
}
service.onReplayBegin();
for (int i = 0; i < replayTermCount; i++) {
awaitActiveLog();
final int counterId = activeLog.commitPositionId;
leadershipTermId = CommitPos.getLeadershipTermId(counters, counterId);
termBaseLogPosition = CommitPos.getTermBaseLogPosition(counters, counterId);
if (CommitPos.getLeadershipTermLength(counters, counterId) > 0) {
try (Subscription subscription = aeron.addSubscription(activeLog.channel, activeLog.streamId)) {
serviceControlPublisher.ackAction(termBaseLogPosition, leadershipTermId, serviceId, READY);
final Image image = awaitImage(activeLog.sessionId, subscription);
final ReadableCounter limit = new ReadableCounter(counters, counterId);
final BoundedLogAdapter adapter = new BoundedLogAdapter(image, limit, this);
consumeImage(image, adapter);
termBaseLogPosition += image.position();
}
}
serviceControlPublisher.ackAction(termBaseLogPosition, leadershipTermId, serviceId, REPLAY);
}
service.onReplayEnd();
}
use of io.aeron.status.ReadableCounter in project aeron by real-logic.
the class ClusteredServiceAgent method switchActiveLog.
private void switchActiveLog() {
if (logAdapter.isCaughtUp()) {
final CountersReader counters = aeron.countersReader();
final int counterId = activeLog.commitPositionId;
leadershipTermId = activeLog.leadershipTermId;
termBaseLogPosition = CommitPos.getTermBaseLogPosition(counters, counterId);
if (CommitPos.getLeadershipTermLength(counters, counterId) > 0) {
logAdapter.close();
final Subscription subscription = aeron.addSubscription(activeLog.channel, activeLog.streamId);
final Image image = awaitImage(activeLog.sessionId, subscription);
serviceControlPublisher.ackAction(termBaseLogPosition, leadershipTermId, serviceId, READY);
final ReadableCounter limit = new ReadableCounter(counters, counterId);
logAdapter = new BoundedLogAdapter(image, limit, this);
activeLog = null;
}
}
}
Aggregations