diff --git a/aeron-archive/src/main/java/io/aeron/archive/Archive.java b/aeron-archive/src/main/java/io/aeron/archive/Archive.java index 7acc060c21..e95b2e2cb5 100644 --- a/aeron-archive/src/main/java/io/aeron/archive/Archive.java +++ b/aeron-archive/src/main/java/io/aeron/archive/Archive.java @@ -22,6 +22,7 @@ import io.aeron.archive.client.ArchiveException; import io.aeron.driver.DutyCycleTracker; import io.aeron.driver.status.DutyCycleStallTracker; +import io.aeron.exceptions.AeronException; import io.aeron.exceptions.ConcurrentConcludeException; import io.aeron.exceptions.ConfigurationException; import io.aeron.security.Authenticator; @@ -117,9 +118,24 @@ public static void main(final String[] args) { loadPropertiesFiles(args); - try (Archive ignore = launch()) + final ShutdownSignalBarrier shutdownSignalBarrier = new ShutdownSignalBarrier(); + final Archive.Context ctx = new Context(); + ctx.errorHandler( + throwable -> + { + if (throwable instanceof AgentTerminationException) + { + shutdownSignalBarrier.signal(); + } + else if (AeronException.isFatal(throwable)) + { + shutdownSignalBarrier.signal(); + } + }); + + try (Archive ignore = launch(ctx)) { - new ShutdownSignalBarrier().await(); + shutdownSignalBarrier.await(); System.out.println("Shutdown Archive..."); } } @@ -1137,9 +1153,9 @@ public void conclude() aeron = Aeron.connect( new Aeron.Context() .aeronDirectoryName(aeronDirectoryName) - .errorHandler(errorHandler) .epochClock(epochClock) .nanoClock(nanoClock) + .errorHandler(RethrowingErrorHandler.INSTANCE) .driverAgentInvoker(mediaDriverAgentInvoker) .useConductorAgentInvoker(true) .subscriberErrorHandler(RethrowingErrorHandler.INSTANCE) @@ -1166,10 +1182,6 @@ public void conclude() if (null == countedErrorHandler) { countedErrorHandler = new CountedErrorHandler(errorHandler, errorCounter); - if (ownsAeronClient) - { - aeron.context().errorHandler(countedErrorHandler); - } } if (null == threadFactory) diff --git a/aeron-client/src/main/java/io/aeron/exceptions/AeronException.java b/aeron-client/src/main/java/io/aeron/exceptions/AeronException.java index 3dac397a98..af1af5b335 100644 --- a/aeron-client/src/main/java/io/aeron/exceptions/AeronException.java +++ b/aeron-client/src/main/java/io/aeron/exceptions/AeronException.java @@ -185,4 +185,15 @@ public Category category() { return category; } + + /** + * Determines if a throwable is a FATAL AeronException. + * + * @param t throwable to check + * @return true if this is an AeronException with a category set to FATAL, false otherwise. + */ + public static boolean isFatal(final Throwable t) + { + return t instanceof AeronException && Category.FATAL == ((AeronException)t).category; + } }