Java Code Examples for org.agrona.CloseHelper#quietCloseAll()

The following examples show how to use org.agrona.CloseHelper#quietCloseAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArchivingMediaDriver.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
static ArchivingMediaDriver launchArchiveWithEmbeddedDriver()
{
    MediaDriver driver = null;
    Archive archive = null;
    try
    {
        final MediaDriver.Context driverCtx = new MediaDriver.Context()
            .dirDeleteOnStart(true)
            .spiesSimulateConnection(true);

        driver = MediaDriver.launch(driverCtx);

        final Archive.Context archiveCtx = new Archive.Context()
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .deleteArchiveOnStart(true);

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.errorHandler();

        archive = Archive.launch(archiveCtx
            .mediaDriverAgentInvoker(driver.sharedAgentInvoker())
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .errorHandler(errorHandler)
            .errorCounter(errorCounter));
        return new ArchivingMediaDriver(driver, archive);
    }
    catch (final Exception ex)
    {
        CloseHelper.quietCloseAll(archive, driver);
        throw ex;
    }
}
 
Example 2
Source File: ArchivingMediaDriver.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a new {@link ArchivingMediaDriver} with provided contexts.
 *
 * @param driverCtx  for configuring the {@link MediaDriver}.
 * @param archiveCtx for configuring the {@link Archive}.
 * @return a new {@link ArchivingMediaDriver} with the provided contexts.
 */
public static ArchivingMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx)
{
    MediaDriver driver = null;
    Archive archive = null;
    try
    {
        driver = MediaDriver.launch(driverCtx);

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.errorHandler();

        archive = Archive.launch(archiveCtx
            .mediaDriverAgentInvoker(driver.sharedAgentInvoker())
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .errorHandler(errorHandler)
            .errorCounter(errorCounter));

        return new ArchivingMediaDriver(driver, archive);
    }
    catch (final Exception ex)
    {
        CloseHelper.quietCloseAll(archive, driver);
        throw ex;
    }
}
 
Example 3
Source File: ClusterBackupMediaDriver.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a new {@link ClusterBackupMediaDriver} with provided contexts.
 *
 * @param driverCtx        for configuring the {@link MediaDriver}.
 * @param archiveCtx       for configuring the {@link Archive}.
 * @param clusterBackupCtx for the configuration of the {@link ClusterBackup}.
 * @return a new {@link ClusterBackupMediaDriver} with the provided contexts.
 */
public static ClusterBackupMediaDriver launch(
    final MediaDriver.Context driverCtx,
    final Archive.Context archiveCtx,
    final ClusterBackup.Context clusterBackupCtx)
{
    MediaDriver driver = null;
    Archive archive = null;
    ClusterBackup clusterBackup = null;

    try
    {
        driver = MediaDriver.launch(driverCtx
            .spiesSimulateConnection(true));

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.errorHandler();

        archive = Archive.launch(archiveCtx
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .mediaDriverAgentInvoker(driver.sharedAgentInvoker())
            .errorHandler(errorHandler)
            .errorCounter(errorCounter));

        clusterBackup = ClusterBackup.launch(clusterBackupCtx
            .aeronDirectoryName(driverCtx.aeronDirectoryName()));

        return new ClusterBackupMediaDriver(driver, archive, clusterBackup);
    }
    catch (final Throwable throwable)
    {
        CloseHelper.quietCloseAll(driver, archive, clusterBackup);
        throw throwable;
    }
}
 
Example 4
Source File: ClusteredMediaDriver.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * 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
            .spiesSimulateConnection(true));

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.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;
    }
}
 
Example 5
Source File: MinFlowControlSystemTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
@AfterEach
public void after()
{
    CloseHelper.quietCloseAll(clientB, clientA, driverB, driverA);
    IoUtil.delete(new File(ROOT_DIR), true);
}
 
Example 6
Source File: MaxFlowControlStrategySystemTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
@AfterEach
public void after()
{
    CloseHelper.quietCloseAll(clientB, clientA, driverB, driverA);
    IoUtil.delete(new File(ROOT_DIR), true);
}