Skip to content

Commit

Permalink
Align the SimplestCase single host sample with the multi host example. (
Browse files Browse the repository at this point in the history
#235)

- make the "from the start" position argument conform to the contract (AeronArchive.NULL_POSITION)
 - wait for the counter to become available instead of assuming that it is immediately available ( as it sometimes resulted in error when attempted to read too early).
 - fix shut down behaviour by attempting to close the resources even if the exception occurred. It used to hang forever by not executing close logic on exception.
  • Loading branch information
michaelszymczak authored Nov 12, 2023
1 parent 20746d5 commit e8a7be9
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ public class SimplestCase
public static void main(final String[] args)
{
final SimplestCase simplestCase = new SimplestCase();
simplestCase.setup();
LOGGER.info("Writing");
simplestCase.write();
LOGGER.info("Reading");
simplestCase.read();
simplestCase.cleanUp();
try
{
simplestCase.setup();
LOGGER.info("Writing");
simplestCase.write();
LOGGER.info("Reading");
simplestCase.read();
}
finally
{
simplestCase.cleanUp();
}
}

private void cleanUp()
Expand All @@ -85,7 +91,7 @@ private void read()
.aeron(aeron)))
{
final long recordingId = findLatestRecording(reader, channel, streamCapture);
final long position = 0L;
final long position = AeronArchive.NULL_POSITION;
final long length = Long.MAX_VALUE;

final long sessionId = reader.startReplay(recordingId, position, length, channel, streamReplay);
Expand Down Expand Up @@ -128,7 +134,12 @@ private void write()

final long stopPosition = publication.position();
final CountersReader countersReader = aeron.countersReader();
final int counterId = RecordingPos.findCounterIdBySession(countersReader, publication.sessionId());
int counterId = RecordingPos.findCounterIdBySession(countersReader, publication.sessionId());
while (CountersReader.NULL_COUNTER_ID == counterId)
{
idleStrategy.idle();
counterId = RecordingPos.findCounterIdBySession(countersReader, publication.sessionId());
}

while (countersReader.getCounterValue(counterId) < stopPosition)
{
Expand Down

0 comments on commit e8a7be9

Please sign in to comment.