// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java
// static ArchivingMediaDriver launchArchiveWithEmbeddedDriver()
// {
//     MediaDriver driver = null;
//     Archive archive = null;
//     try
//     {
//         final MediaDriver.Context driverCtx = new MediaDriver.Context()
//             .dirDeleteOnStart(true)
//             .dirDeleteOnShutdown(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() ?
//             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(driverCtx.aeronDirectoryName())
//             .errorHandler(errorHandler)
//             .errorCounter(errorCounter));
// 
//         return new ArchivingMediaDriver(driver, archive);
//     }
//     catch (final Exception ex)
//     {
//         CloseHelper.quietCloseAll(archive, driver);
//         throw ex;
//     }
// }
// 
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java
// static ArchivingMediaDriver launchArchiveWithStandaloneDriver()
// {
//     return new ArchivingMediaDriver(null, Archive.launch(new Archive.Context().deleteArchiveOnStart(true)));
// }


import io.aeron.Aeron;
import io.aeron.ExclusivePublication;
import io.aeron.Image;
import io.aeron.Subscription;
import io.aeron.archive.client.AeronArchive;
import io.aeron.archive.client.ArchiveException;
import io.aeron.archive.client.RecordingDescriptorConsumer;
import io.aeron.driver.MediaDriver;
import io.aeron.exceptions.AeronException;
import io.aeron.logbuffer.BufferClaim;
import io.aeron.logbuffer.FragmentHandler;
import org.agrona.ErrorHandler;
import org.agrona.LangUtil;
import org.agrona.MutableDirectBuffer;
import org.agrona.collections.MutableLong;
import org.agrona.concurrent.IdleStrategy;
import org.agrona.concurrent.NanoClock;
import org.agrona.concurrent.NoOpIdleStrategy;
import org.agrona.concurrent.ShutdownSignalBarrier;
import org.agrona.concurrent.status.CountersReader;
import sun.misc.Signal;
import sun.misc.SignalHandler;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier;
import static io.aeron.CommonContext.IPC_CHANNEL;
import static io.aeron.Publication.*;
import static io.aeron.archive.status.RecordingPos.findCounterIdBySession;
import static io.aeron.archive.status.RecordingPos.getRecordingId;
import static java.lang.Boolean.getBoolean;
import static java.lang.Class.forName;
import static java.lang.Integer.getInteger;
import static java.lang.Long.MAX_VALUE;
import static java.lang.System.getProperty;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static org.agrona.BitUtil.SIZE_OF_LONG;
import static org.agrona.Strings.isEmpty;
import static org.agrona.SystemUtil.parseDuration;
import static org.agrona.concurrent.status.CountersReader.NULL_COUNTER_ID;
import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver;
import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithStandaloneDriver;
        final String idleStrategy = getProperty(IDLE_STRATEGY_PROP_NAME);
        if (isEmpty(idleStrategy))
        {
            return NoOpIdleStrategy.INSTANCE;
        }

        try
        {
            return (IdleStrategy)forName(idleStrategy).getConstructor().newInstance();
        }
        catch (final ReflectiveOperationException | ClassCastException ex)
        {
            throw new IllegalArgumentException("Invalid IdleStrategy: " + idleStrategy, ex);
        }
    }

    static MediaDriver launchEmbeddedMediaDriverIfConfigured()
    {
        if (embeddedMediaDriver())
        {
            return MediaDriver.launch(new MediaDriver.Context()
                .dirDeleteOnStart(true)
                .spiesSimulateConnection(true));
        }

        return null;
    }

    static ArchivingMediaDriver launchArchivingMediaDriver()
    {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java
// static ArchivingMediaDriver launchArchiveWithEmbeddedDriver()
// {
//     MediaDriver driver = null;
//     Archive archive = null;
//     try
//     {
//         final MediaDriver.Context driverCtx = new MediaDriver.Context()
//             .dirDeleteOnStart(true)
//             .dirDeleteOnShutdown(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() ?
//             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(driverCtx.aeronDirectoryName())
//             .errorHandler(errorHandler)
//             .errorCounter(errorCounter));
// 
//         return new ArchivingMediaDriver(driver, archive);
//     }
//     catch (final Exception ex)
//     {
//         CloseHelper.quietCloseAll(archive, driver);
//         throw ex;
//     }
// }
// 
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java
// static ArchivingMediaDriver launchArchiveWithStandaloneDriver()
// {
//     return new ArchivingMediaDriver(null, Archive.launch(new Archive.Context().deleteArchiveOnStart(true)));
// }


// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java
import io.aeron.Aeron;
import io.aeron.ExclusivePublication;
import io.aeron.Image;
import io.aeron.Subscription;
import io.aeron.archive.client.AeronArchive;
import io.aeron.archive.client.ArchiveException;
import io.aeron.archive.client.RecordingDescriptorConsumer;
import io.aeron.driver.MediaDriver;
import io.aeron.exceptions.AeronException;
import io.aeron.logbuffer.BufferClaim;
import io.aeron.logbuffer.FragmentHandler;
import org.agrona.ErrorHandler;
import org.agrona.LangUtil;
import org.agrona.MutableDirectBuffer;
import org.agrona.collections.MutableLong;
import org.agrona.concurrent.IdleStrategy;
import org.agrona.concurrent.NanoClock;
import org.agrona.concurrent.NoOpIdleStrategy;
import org.agrona.concurrent.ShutdownSignalBarrier;
import org.agrona.concurrent.status.CountersReader;
import sun.misc.Signal;
import sun.misc.SignalHandler;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier;
import static io.aeron.CommonContext.IPC_CHANNEL;
import static io.aeron.Publication.*;
import static io.aeron.archive.status.RecordingPos.findCounterIdBySession;
import static io.aeron.archive.status.RecordingPos.getRecordingId;
import static java.lang.Boolean.getBoolean;
import static java.lang.Class.forName;
import static java.lang.Integer.getInteger;
import static java.lang.Long.MAX_VALUE;
import static java.lang.System.getProperty;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static org.agrona.BitUtil.SIZE_OF_LONG;
import static org.agrona.Strings.isEmpty;
import static org.agrona.SystemUtil.parseDuration;
import static org.agrona.concurrent.status.CountersReader.NULL_COUNTER_ID;
import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver;
import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithStandaloneDriver;

        final String idleStrategy = getProperty(IDLE_STRATEGY_PROP_NAME);
        if (isEmpty(idleStrategy))
        {
            return NoOpIdleStrategy.INSTANCE;
        }

        try
        {
            return (IdleStrategy)forName(idleStrategy).getConstructor().newInstance();
        }
        catch (final ReflectiveOperationException | ClassCastException ex)
        {
            throw new IllegalArgumentException("Invalid IdleStrategy: " + idleStrategy, ex);
        }
    }

    static MediaDriver launchEmbeddedMediaDriverIfConfigured()
    {
        if (embeddedMediaDriver())
        {
            return MediaDriver.launch(new MediaDriver.Context()
                .dirDeleteOnStart(true)
                .spiesSimulateConnection(true));
        }

        return null;
    }

    static ArchivingMediaDriver launchArchivingMediaDriver()
    {
        return embeddedMediaDriver() ? launchArchiveWithEmbeddedDriver() : launchArchiveWithStandaloneDriver();