private static bool PollForResponse(AeronArchive archive, long correlationId) { ControlResponsePoller poller = archive.ControlResponsePoller(); if (poller.Poll() > 0 && poller.IsPollComplete()) { if (poller.ControlSessionId() == archive.ControlSessionId() && poller.CorrelationId() == correlationId) { if (poller.Code() == ControlResponseCode.ERROR) { throw new ArchiveException("archive response for correlationId=" + correlationId + ", error: " + poller.ErrorMessage(), (int)poller.RelevantId()); } return(true); } } return(false); }
private int GetRecordingPosition(long nowMs) { int workCount = 0; if (Aeron.NULL_VALUE == activeCorrelationId) { long correlationId = archive.Ctx().AeronClient().NextCorrelationId(); if (archive.Proxy().GetRecordingPosition(recordingId, correlationId, archive.ControlSessionId())) { activeCorrelationId = correlationId; timeOfLastProgressMs = nowMs; workCount += 1; } } else if (PollForResponse(archive, activeCorrelationId)) { nextTargetPosition = PolledRelevantId(archive); activeCorrelationId = Aeron.NULL_VALUE; if (AeronArchive.NULL_POSITION == nextTargetPosition) { long correlationId = archive.Ctx().AeronClient().NextCorrelationId(); if (archive.Proxy().GetStopPosition(recordingId, correlationId, archive.ControlSessionId())) { activeCorrelationId = correlationId; timeOfLastProgressMs = nowMs; workCount += 1; } } else { timeOfLastProgressMs = nowMs; SetState(State.REPLAY); } workCount += 1; } return(workCount); }
private int AwaitInitialRecordingPosition() { int workCount = 0; if (NULL_VALUE == activeCorrelationId) { long correlationId = archive.Ctx().AeronClient().NextCorrelationId(); if (archive.Proxy().GetRecordingPosition(recordingId, correlationId, archive.ControlSessionId())) { activeCorrelationId = correlationId; workCount += 1; } } else if (PollForResponse(archive, activeCorrelationId)) { nextTargetPosition = PolledRelevantId(archive); if (AeronArchive.NULL_POSITION == nextTargetPosition) { var correlationId = archive.Ctx().AeronClient().NextCorrelationId(); if (archive.Proxy().GetStopPosition(recordingId, correlationId, archive.ControlSessionId())) { activeCorrelationId = correlationId; workCount += 1; } } else { initialMaxPosition = nextTargetPosition; activeCorrelationId = NULL_VALUE; SetState(State.AWAIT_REPLAY); } workCount += 1; } return(workCount); }