org.agrona.concurrent.SleepingIdleStrategy Java Examples

The following examples show how to use org.agrona.concurrent.SleepingIdleStrategy. 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: ConcurrentConnections.java    From artio with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    loadPropertiesFiles(args);

    final AgentRunner server = Server.createServer(new SleepingIdleStrategy(100), Throwable::printStackTrace);

    AgentRunner.startOnThread(server);

    final String aeronChannel = "aeron:udp?endpoint=localhost:10002";
    final EngineConfiguration engineConfiguration = new EngineConfiguration()
        .libraryAeronChannel(aeronChannel)
        .logFileDir("stress-client-logs");
    engineConfiguration.authenticationStrategy((logon) -> true);

    System.out.println("Client Logs at " + engineConfiguration.logFileDir());

    StressUtil.cleanupOldLogFileDir(engineConfiguration);

    final Random random = new Random(StressConfiguration.SEED);

    final long startTime = System.currentTimeMillis();

    try (FixEngine ignore = FixEngine.launch(engineConfiguration))
    {
        final CyclicBarrier barrier = new CyclicBarrier(NUM_SESSIONS);
        final Thread[] threads = new Thread[NUM_SESSIONS];

        for (int i = 0; i < NUM_SESSIONS; i++)
        {
            System.out.format("Starting session %d / %d%n", i + 1, NUM_SESSIONS);

            final int id = i;
            threads[i] = new Thread(
                () -> runThread(aeronChannel, random, barrier, id));

            threads[i].start();
        }

        for (final Thread thread : threads)
        {
            thread.join();
        }
    }

    server.close();

    System.out.format("Sessions %d. Messages %d per session.%n", NUM_SESSIONS, MESSAGES_EXCHANGED);
    System.out.format("Stress test executed in %dms%n", System.currentTimeMillis() - startTime);
    System.exit(0);
}