use of org.agrona.ErrorHandler in project aeron by real-logic.
the class ClusteredMediaDriver method launch.
/**
* Launch a new {@link ClusteredMediaDriver} with provided contexts.
*
* @param driverCtx for configuring the {@link MediaDriver}.
* @param archiveCtx for configuring the {@link Archive}.
* @param consensusModuleCtx for the configuration of the {@link ConsensusModule}.
* @return a new {@link ClusteredMediaDriver} with the provided contexts.
*/
public static ClusteredMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx, final ConsensusModule.Context consensusModuleCtx) {
MediaDriver driver = null;
Archive archive = null;
ConsensusModule consensusModule = null;
try {
driver = MediaDriver.launch(driverCtx);
final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId);
final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? archiveCtx.errorHandler() : driverCtx.errorHandler();
archive = Archive.launch(archiveCtx.mediaDriverAgentInvoker(driver.sharedAgentInvoker()).aeronDirectoryName(driver.aeronDirectoryName()).errorHandler(errorHandler).errorCounter(errorCounter));
consensusModule = ConsensusModule.launch(consensusModuleCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()));
return new ClusteredMediaDriver(driver, archive, consensusModule);
} catch (final Exception ex) {
CloseHelper.quietCloseAll(consensusModule, archive, driver);
throw ex;
}
}
use of org.agrona.ErrorHandler in project Aeron by real-logic.
the class CommonContextTest method setupErrorHandlerReturnsALoggingErrorHandlerInstanceIfNoUserErrorHandlerSupplied.
@Test
void setupErrorHandlerReturnsALoggingErrorHandlerInstanceIfNoUserErrorHandlerSupplied() {
final DistinctErrorLog distinctErrorLog = mock(DistinctErrorLog.class);
final ErrorHandler errorHandler = CommonContext.setupErrorHandler(null, distinctErrorLog);
assertNotNull(errorHandler);
final LoggingErrorHandler loggingErrorHandler = assertInstanceOf(LoggingErrorHandler.class, errorHandler);
assertSame(distinctErrorLog, loggingErrorHandler.distinctErrorLog());
}
use of org.agrona.ErrorHandler in project Aeron by real-logic.
the class CommonContextTest method setupErrorHandlerReturnsAnErrorHandlerThatFirstInvokesLoggingErrorHandlerBeforeCallingSuppliedErrorHandler.
@Test
void setupErrorHandlerReturnsAnErrorHandlerThatFirstInvokesLoggingErrorHandlerBeforeCallingSuppliedErrorHandler() {
final Throwable throwable = new Throwable("Hello, world!");
final ErrorHandler userErrorHandler = mock(ErrorHandler.class);
final AssertionError userHandlerError = new AssertionError("user handler error");
doThrow(userHandlerError).when(userErrorHandler).onError(throwable);
final DistinctErrorLog distinctErrorLog = mock(DistinctErrorLog.class);
doReturn(true).when(distinctErrorLog).record(any(Throwable.class));
final InOrder inOrder = inOrder(userErrorHandler, distinctErrorLog);
final ErrorHandler errorHandler = CommonContext.setupErrorHandler(userErrorHandler, distinctErrorLog);
assertNotNull(errorHandler);
assertNotSame(userErrorHandler, errorHandler);
final AssertionError error = assertThrowsExactly(AssertionError.class, () -> errorHandler.onError(throwable));
assertSame(userHandlerError, error);
inOrder.verify(distinctErrorLog).record(throwable);
inOrder.verify(userErrorHandler).onError(throwable);
inOrder.verifyNoMoreInteractions();
}
use of org.agrona.ErrorHandler in project Aeron by real-logic.
the class AuthorisationServiceTest method shouldForbidAllCommandsIfDenyAllIsUsed.
@Test
void shouldForbidAllCommandsIfDenyAllIsUsed() {
final byte[] encodedCredentials = { 0x4, 0x5, 0x6 };
final ErrorHandler errorHandler = mock(ErrorHandler.class);
final int protocolId = 77;
final int actionId = ThreadLocalRandom.current().nextInt();
assertFalse(DENY_ALL.isAuthorised(protocolId, actionId, null, encodedCredentials));
verifyNoInteractions(errorHandler);
}
use of org.agrona.ErrorHandler in project Aeron by real-logic.
the class AeronArchive method close.
/**
* Notify the archive that this control session is closed, so it can promptly release resources then close the
* local resources associated with the client.
*/
public void close() {
lock.lock();
try {
if (!isClosed) {
isClosed = true;
final ErrorHandler errorHandler = context.errorHandler();
if (archiveProxy.publication().isConnected()) {
CloseHelper.close(errorHandler, () -> archiveProxy.closeSession(controlSessionId));
}
if (!context.ownsAeronClient()) {
CloseHelper.close(errorHandler, archiveProxy.publication());
CloseHelper.close(errorHandler, controlResponsePoller.subscription());
}
context.close();
}
} finally {
lock.unlock();
}
}
Aggregations