Skip to content

Commit

Permalink
Let Archive take care of handling Aeron exceptions when client is emb…
Browse files Browse the repository at this point in the history
…edded. (aeron-io#1454)

* [Java] Use RethrowingExceptionHandler when Aeron is owned by the Archive.  Add isFatal method to AeronException.  Add checks for AgentTerminationException and fatal AeronExceptions in Archive.main.

* [Java] Remove test/debug code.
  • Loading branch information
mikeb01 authored Apr 27, 2023
1 parent 0d1f28b commit b8acdbf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
26 changes: 19 additions & 7 deletions aeron-archive/src/main/java/io/aeron/archive/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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...");
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -1166,10 +1182,6 @@ public void conclude()
if (null == countedErrorHandler)
{
countedErrorHandler = new CountedErrorHandler(errorHandler, errorCounter);
if (ownsAeronClient)
{
aeron.context().errorHandler(countedErrorHandler);
}
}

if (null == threadFactory)
Expand Down
11 changes: 11 additions & 0 deletions aeron-client/src/main/java/io/aeron/exceptions/AeronException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit b8acdbf

Please sign in to comment.