Java Code Examples for io.aeron.driver.MediaDriver#Context

The following examples show how to use io.aeron.driver.MediaDriver#Context . 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: JavaTestMediaDriver.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static void enableLossGenerationOnReceive(
    final MediaDriver.Context context,
    final double rate,
    final long seed,
    final boolean loseDataMessages,
    final boolean loseControlMessages)
{
    final LossGenerator dataLossGenerator = loseDataMessages ?
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(rate, seed) :
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);

    final LossGenerator controlLossGenerator = loseControlMessages ?
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(rate, seed) :
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);

    context.receiveChannelEndpointSupplier((udpChannel, dispatcher, statusIndicator, ctx) ->
        new DebugReceiveChannelEndpoint(
        udpChannel, dispatcher, statusIndicator, ctx, dataLossGenerator, controlLossGenerator));
}
 
Example 2
Source File: NameReResolutionTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void before()
{
    final MediaDriver.Context context = new MediaDriver.Context()
        .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH)
        .dirDeleteOnStart(true)
        .dirDeleteOnShutdown(true)
        .threadingMode(ThreadingMode.SHARED);

    TestMediaDriver.enableCsvNameLookupConfiguration(context, STUB_LOOKUP_CONFIGURATION);

    driver = TestMediaDriver.launch(context, testWatcher);

    client = Aeron.connect();
    countersReader = client.countersReader();
}
 
Example 3
Source File: LowLatencyMediaDriver.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
    MediaDriver.loadPropertiesFiles(args);

    setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
    setProperty("aeron.mtu.length", "16384");
    setProperty("aeron.socket.so_sndbuf", "2097152");
    setProperty("aeron.socket.so_rcvbuf", "2097152");
    setProperty("aeron.rcv.initial.window.length", "2097152");

    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());

    try (MediaDriver ignored = MediaDriver.launch(ctx)) {
        new SigIntBarrier().await();

    }
}
 
Example 4
Source File: LowLatencyMediaDriver.java    From rpc-bench with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
  MediaDriver.loadPropertiesFiles(args);

  setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
  setProperty("aeron.mtu.length", "16384");
  setProperty("aeron.socket.so_sndbuf", "2097152");
  setProperty("aeron.socket.so_rcvbuf", "2097152");
  setProperty("aeron.rcv.initial.window.length", "2097152");

  final MediaDriver.Context ctx = new MediaDriver.Context()
      .threadingMode(ThreadingMode.DEDICATED)
      .dirsDeleteOnStart(true)
      .termBufferSparseFile(false)
      .conductorIdleStrategy(new BusySpinIdleStrategy())
      .receiverIdleStrategy(new BusySpinIdleStrategy())
      .senderIdleStrategy(new BusySpinIdleStrategy());

  try (MediaDriver ignored = MediaDriver.launch(ctx)) {
    new SigIntBarrier().await();

  }
}
 
Example 5
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 6
Source File: DebugReceiveChannelEndpointSupplier.java    From aeron with Apache License 2.0 5 votes vote down vote up
public ReceiveChannelEndpoint newInstance(
    final UdpChannel udpChannel,
    final DataPacketDispatcher dispatcher,
    final AtomicCounter statusIndicator,
    final MediaDriver.Context context)
{
    return new DebugReceiveChannelEndpoint(udpChannel, dispatcher, statusIndicator, context);
}
 
Example 7
Source File: DriverNameResolverTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private static MediaDriver.Context setDefaults(final MediaDriver.Context context)
{
    context
        .errorHandler(Tests::onError)
        .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH)
        .threadingMode(ThreadingMode.SHARED)
        .dirDeleteOnStart(true);

    return context;
}
 
Example 8
Source File: ChannelEndpointStatusTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before()
{
    final String baseDirA = ROOT_DIR + "A";
    final String baseDirB = ROOT_DIR + "B";

    buffer.putInt(0, 1);

    final MediaDriver.Context driverAContext = new MediaDriver.Context()
        .publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .aeronDirectoryName(baseDirA)
        .errorHandler(driverErrorHandler)
        .threadingMode(THREADING_MODE);

    final MediaDriver.Context driverBContext = new MediaDriver.Context()
        .publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .aeronDirectoryName(baseDirB)
        .errorHandler(driverErrorHandler)
        .threadingMode(THREADING_MODE);

    driverA = TestMediaDriver.launch(driverAContext, testWatcher);
    driverB = TestMediaDriver.launch(driverBContext, testWatcher);

    clientA = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(driverAContext.aeronDirectoryName())
            .errorHandler(errorHandlerClientA));

    clientB = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(driverBContext.aeronDirectoryName())
            .errorHandler(errorHandlerClientB));

    clientC = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(driverBContext.aeronDirectoryName())
            .errorHandler(errorHandlerClientC));
}
 
Example 9
Source File: UdpNameResolutionTransport.java    From aeron with Apache License 2.0 5 votes vote down vote up
public UdpNameResolutionTransport(
    final UdpChannel udpChannel,
    final InetSocketAddress resolverAddr,
    final UnsafeBuffer unsafeBuffer,
    final MediaDriver.Context context)
{
    super(udpChannel, null, resolverAddr, null, context);

    this.unsafeBuffer = unsafeBuffer;
    this.byteBuffer = unsafeBuffer.byteBuffer();
}
 
Example 10
Source File: UdpChannelTransport.java    From aeron with Apache License 2.0 5 votes vote down vote up
public UdpChannelTransport(
    final UdpChannel udpChannel,
    final InetSocketAddress endPointAddress,
    final InetSocketAddress bindAddress,
    final InetSocketAddress connectAddress,
    final MediaDriver.Context context)
{
    this.context = context;
    this.udpChannel = udpChannel;
    this.errorHandler = context.errorHandler();
    this.endPointAddress = endPointAddress;
    this.bindAddress = bindAddress;
    this.connectAddress = connectAddress;
    this.invalidPackets = context.systemCounters().get(SystemCounterDescriptor.INVALID_PACKETS);
}
 
Example 11
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 12
Source File: CubicCongestionControlSupplier.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public CongestionControl newInstance(
    final long registrationId,
    final UdpChannel udpChannel,
    final int streamId,
    final int sessionId,
    final int termLength,
    final int senderMtuLength,
    final InetSocketAddress controlAddress,
    final InetSocketAddress sourceAddress,
    final NanoClock nanoClock,
    final MediaDriver.Context context,
    final CountersManager countersManager)
{
    return new CubicCongestionControl(
        registrationId,
        udpChannel,
        streamId,
        sessionId,
        termLength,
        senderMtuLength,
        controlAddress,
        sourceAddress,
        nanoClock,
        context,
        countersManager);
}
 
Example 13
Source File: AeronNDArrayResponseTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());
    mediaDriver = MediaDriver.launchEmbedded(ctx);
    System.out.println("Using media driver directory " + mediaDriver.aeronDirectoryName());
    System.out.println("Launched media driver");
}
 
Example 14
Source File: Server.java    From artio with Apache License 2.0 5 votes vote down vote up
public Server()
{
    final AuthenticationStrategy authenticationStrategy = logon -> true;

    // Static configuration lasts the duration of a FIX-Gateway instance
    final String aeronChannel = "aeron:udp?endpoint=localhost:10000";
    final EngineConfiguration configuration = new EngineConfiguration()
        .bindTo("localhost", StressConfiguration.PORT)
        .logFileDir("stress-server-logs")
        .libraryAeronChannel(aeronChannel)
        .sessionPersistenceStrategy(alwaysPersistent());

    configuration
        .authenticationStrategy(authenticationStrategy)
        .agentNamePrefix("server-");

    System.out.println("Server Logs at " + configuration.logFileDir());

    StressUtil.cleanupOldLogFileDir(configuration);

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(ThreadingMode.SHARED)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true);

    mediaDriver = ArchivingMediaDriver.launch(context, archiveContext);
    fixEngine = FixEngine.launch(configuration);

    final LibraryConfiguration libraryConfiguration = new LibraryConfiguration();
    libraryConfiguration
        .agentNamePrefix("server-");

    fixLibrary = blockingConnect(libraryConfiguration
        .sessionAcquireHandler((session, acquiredInfo) -> new StressSessionHandler(session))
        .sessionExistsHandler(new AcquiringSessionExistsHandler(true))
        .libraryAeronChannels(singletonList(aeronChannel)));
}
 
Example 15
Source File: WildcardPortsSystemTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void launch()
{
    buffer.putInt(0, 1);

    final MediaDriver.Context context = new MediaDriver.Context()
        .dirDeleteOnStart(true)
        .threadingMode(ThreadingMode.SHARED);

    driver = TestMediaDriver.launch(context, testWatcher);
    client = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()));
}
 
Example 16
Source File: ReceiveDestinationTransport.java    From aeron with Apache License 2.0 5 votes vote down vote up
public ReceiveDestinationTransport(
    final UdpChannel udpChannel,
    final MediaDriver.Context context,
    final AtomicCounter localSocketAddressIndicator)
{
    super(udpChannel, udpChannel.remoteData(), udpChannel.remoteData(), null, context);

    this.timeOfLastActivityNs = context.cachedNanoClock().nanoTime();
    this.currentControlAddress = udpChannel.hasExplicitControl() ? udpChannel.localControl() : null;
    this.localSocketAddressIndicator = localSocketAddressIndicator;
}
 
Example 17
Source File: ArchiveCreator.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        new File("archive") : new File(archiveDirName);

    final MediaDriver.Context driverContext = new MediaDriver.Context()
        .publicationTermBufferLength(TERM_LENGTH)
        .termBufferSparseFile(true)
        .threadingMode(ThreadingMode.SHARED)
        .errorHandler(Throwable::printStackTrace)
        .spiesSimulateConnection(true)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .maxCatalogEntries(MAX_CATALOG_ENTRIES)
        .segmentFileLength(SEGMENT_LENGTH)
        .deleteArchiveOnStart(true)
        .archiveDir(archiveDir)
        .fileSyncLevel(0)
        .threadingMode(ArchiveThreadingMode.SHARED);

    System.out.println("Creating basic archive at " + archiveContext.archiveDir());

    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverContext, archiveContext);
        Aeron aeron = Aeron.connect();
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron)))
    {
        createRecording(
            aeron,
            aeronArchive,
            0,
            (SEGMENT_LENGTH * 5L) + 1);

        createRecording(
            aeron,
            aeronArchive,
            (long)TERM_LENGTH + (FrameDescriptor.FRAME_ALIGNMENT * 2),
            (SEGMENT_LENGTH * 3L) + 1);

    }
    catch (final Exception ex)
    {
        ex.printStackTrace();
    }
}
 
Example 18
Source File: CubicCongestionControl.java    From aeron with Apache License 2.0 4 votes vote down vote up
public CubicCongestionControl(
    final long registrationId,
    final UdpChannel udpChannel,
    final int streamId,
    final int sessionId,
    final int termLength,
    final int senderMtuLength,
    final InetSocketAddress controlAddress,
    final InetSocketAddress sourceAddress,
    final NanoClock clock,
    final MediaDriver.Context context,
    final CountersManager countersManager)
{
    mtu = senderMtuLength;
    minWindow = senderMtuLength;
    final int maxWindow = Math.min(termLength >> 1, context.initialWindowLength());

    maxCwnd = maxWindow / mtu;
    cwnd = 1;
    w_max = maxCwnd; // initially set w_max to max window and act in the TCP and concave region initially
    k = StrictMath.cbrt((double)w_max * B / C);

    // determine interval for adjustment based on heuristic of MTU, max window, and/or RTT estimate
    rttInNs = CubicCongestionControlConfiguration.INITIAL_RTT_NS;
    windowUpdateTimeoutNs = rttInNs;

    rttIndicator = PerImageIndicator.allocate(
        context.tempBuffer(),
        "rcv-cc-cubic-rtt",
        countersManager,
        registrationId,
        sessionId,
        streamId,
        udpChannel.originalUriString());

    windowIndicator = PerImageIndicator.allocate(
        context.tempBuffer(),
        "rcv-cc-cubic-wnd",
        countersManager,
        registrationId,
        sessionId,
        streamId,
        udpChannel.originalUriString());

    rttIndicator.setOrdered(0);
    windowIndicator.setOrdered(minWindow);

    lastLossTimestampNs = clock.nanoTime();
    lastUpdateTimestampNs = lastLossTimestampNs;

    errorHandler = context.errorHandler();
}
 
Example 19
Source File: TestMediaDriver.java    From aeron with Apache License 2.0 4 votes vote down vote up
static TestMediaDriver launch(final MediaDriver.Context context, final DriverOutputConsumer driverOutputConsumer)
{
    return shouldRunCMediaDriver() ?
        CTestMediaDriver.launch(context, driverOutputConsumer) : JavaTestMediaDriver.launch(context);
}
 
Example 20
Source File: DebugSendChannelEndpointSupplier.java    From aeron with Apache License 2.0 4 votes vote down vote up
public SendChannelEndpoint newInstance(
    final UdpChannel udpChannel, final AtomicCounter statusIndicator, final MediaDriver.Context context)
{
    return new DebugSendChannelEndpoint(udpChannel, statusIndicator, context);
}