<commit_before>/*
 * Copyright 2014 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.real_logic.aeron.benchmarks;

import org.HdrHistogram.Histogram;
import uk.co.real_logic.aeron.Aeron;
import uk.co.real_logic.aeron.DataHandler;
import uk.co.real_logic.aeron.Publication;
import uk.co.real_logic.aeron.Subscription;
import uk.co.real_logic.aeron.common.BackoffIdleStrategy;
import uk.co.real_logic.aeron.common.BitUtil;
import uk.co.real_logic.aeron.common.concurrent.AtomicBuffer;
import uk.co.real_logic.aeron.driver.MediaDriver;

import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;

import static uk.co.real_logic.aeron.benchmarks.BenchmarkUtil.*;

/**
 * Goal: test for latency of ping-pong timings.
 *
 * For infinite amount of time: Send a messages
 */
// TODO: parametrise by backoff strategies
public class PingPongLatencyTestRunner
{
    private static final int CAPACITY = BitUtil.SIZE_OF_LONG;
    private static final AtomicBuffer PUBLISHING_BUFFER = new AtomicBuffer(ByteBuffer.allocateDirect(CAPACITY));
    private static final int NUMBER_OF_MESSAGES = 100_000_000;

    private static long sentTime;

    public static void main(final String[] args) throws Exception
    {
        BenchmarkUtil.useSharedMemoryOnLinux();

        final DataHandler handler = (buffer, offset, length, sessionId, flags) -> sentTime = buffer.getLong(offset);
        final Histogram histogram = new Histogram(10_000_000, 5);

        try (final MediaDriver driver = MediaDriver.launch();
             final Aeron publishingClient = Aeron.connect(new Aeron.Context());
             final Aeron consumingClient = Aeron.connect(new Aeron.Context());
             final Publication publication = publishingClient.addPublication(CHANNEL, STREAM_ID);
             final Subscription subscription = consumingClient.addSubscription(CHANNEL, STREAM_ID, handler))
        {
            publish(publication);
            subscribe(subscription, histogram);

            while (true)
            {
                try
                {
                    Thread.sleep(Long.MAX_VALUE);
                }
                catch (Throwable e)
                {
                    e.printStackTrace();
                }
            }
        }
    }

    private static void subscribe(final Subscription subscription, final Histogram histogram)
    {
        new Thread("subscriber")
        {
            public void run()
            {<commit_msg>[Java] Removed unnecessary exception handler.<commit_after>/*
 * Copyright 2014 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.real_logic.aeron.benchmarks;

import org.HdrHistogram.Histogram;
import uk.co.real_logic.aeron.Aeron;
import uk.co.real_logic.aeron.DataHandler;
import uk.co.real_logic.aeron.Publication;
import uk.co.real_logic.aeron.Subscription;
import uk.co.real_logic.aeron.common.BackoffIdleStrategy;
import uk.co.real_logic.aeron.common.BitUtil;
import uk.co.real_logic.aeron.common.concurrent.AtomicBuffer;
import uk.co.real_logic.aeron.driver.MediaDriver;

import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;

import static uk.co.real_logic.aeron.benchmarks.BenchmarkUtil.*;

/**
 * Goal: test for latency of ping-pong timings.
 *
 * For infinite amount of time: Send a messages
 */
// TODO: parametrise by backoff strategies
public class PingPongLatencyTestRunner
{
    private static final int CAPACITY = BitUtil.SIZE_OF_LONG;
    private static final AtomicBuffer PUBLISHING_BUFFER = new AtomicBuffer(ByteBuffer.allocateDirect(CAPACITY));
    private static final int NUMBER_OF_MESSAGES = 100_000_000;

    private static long sentTime;

    public static void main(final String[] args) throws Exception
    {
        BenchmarkUtil.useSharedMemoryOnLinux();

        final DataHandler handler = (buffer, offset, length, sessionId, flags) -> sentTime = buffer.getLong(offset);
        final Histogram histogram = new Histogram(10_000_000, 5);

        try (final MediaDriver driver = MediaDriver.launch();
             final Aeron publishingClient = Aeron.connect(new Aeron.Context());
             final Aeron consumingClient = Aeron.connect(new Aeron.Context());
             final Publication publication = publishingClient.addPublication(CHANNEL, STREAM_ID);
             final Subscription subscription = consumingClient.addSubscription(CHANNEL, STREAM_ID, handler))
        {
            publish(publication);
            subscribe(subscription, histogram);

            while (true)
            {
                Thread.sleep(Long.MAX_VALUE);
            }
        }
    }

    private static void subscribe(final Subscription subscription, final Histogram histogram)
    {
        new Thread("subscriber")
        {
            public void run()
            {
{'fraction_non_alphanumeric': 0.0832332246438991, 'fraction_numerical': 0.008923974600995366, 'mean_word_length': 3.1274787535410766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3408204', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1553, 'n_words': 465}