<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.util;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;

import static uk.co.real_logic.aeron.util.IoUtil.mapExistingFile;
import static uk.co.real_logic.aeron.util.IoUtil.mapNewFile;

/**
 * Encapsulates the allocation and mapping of conductor communication {@link ByteBuffer}s.
 *
 * Assumes one media driver per client instance.
 */
public class ConductorByteBuffers implements AutoCloseable
{
    protected static final String MEDIA_DRIVER_FILE = "media-driver";
    protected static final String CLIENT_FILE = "client";

    private MappedByteBuffer toMediaDriverBuffer;
    private MappedByteBuffer toClientBuffer;

    /**
     * Create and map the conductor buffers between the media driver and the client.
     *
     * @param adminDirName in which to create the buffers.
     * @param bufferSize to be used for the files.
     */
    public ConductorByteBuffers(final String adminDirName, final int bufferSize)
    {
        final File adminDir  = new File(adminDirName);
        IoUtil.checkDirectoryExists(new File(adminDirName), "adminDir");

        final File toMediaDriverFile = new File(adminDir, MEDIA_DRIVER_FILE);
        final File toClientFile = new File(adminDir, CLIENT_FILE);

        try
        {
            toMediaDriverBuffer = mapNewFile(toMediaDriverFile, MEDIA_DRIVER_FILE, bufferSize);
            toClientBuffer = mapNewFile(toClientFile, CLIENT_FILE, bufferSize);
        }
        catch (final IOException ex)
        {
            throw new RuntimeException(ex);
        }
    }

    /**
     * Map the conductor buffers over existing files between the media driver and the client.
     *
     * @param adminDirName in which to create the buffers.
     */
    public ConductorByteBuffers(final String adminDirName)
    {
        final File adminDir  = new File(adminDirName);
        IoUtil.checkDirectoryExists(new File(adminDirName), "adminDir");

        final File toMediaDriverFile = new File(adminDir, MEDIA_DRIVER_FILE);
        final File toClientFile = new File(adminDir, CLIENT_FILE);

        try
        {
            toMediaDriverBuffer = mapExistingFile(toMediaDriverFile, MEDIA_DRIVER_FILE);
            toClientBuffer = mapExistingFile(toClientFile, CLIENT_FILE);
        }
        catch (final IOException ex)
        {
            throw new RuntimeException(ex);
        }
    }

    /**
     * The {@link ByteBuffer} via which messages are send from the client to the media driver.
     *
     * @return the {@link ByteBuffer} via which messages are send from the client to the media driver.
     */
    public ByteBuffer toMediaDriver()
    {
        return toMediaDriverBuffer;
    }

    /**
     * The {@link ByteBuffer} via which messages are send from the media driver to the client.
     *
     * @return the {@link ByteBuffer} via which messages are send from the media driver to the client.
     */
    public ByteBuffer toClient()
    {
        return toClientBuffer;
    }

    /**
     * Un-map buffers and allow for garbage collection.
     */
    public void close()
    {
        IoUtil.unmap(toClientBuffer);
        IoUtil.unmap(toMediaDriverBuffer);
        toClientBuffer = null;
        toMediaDriverBuffer = null;
    }
}<commit_msg>[Java]: Code clean to help clarify logic.<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.util;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;

import static uk.co.real_logic.aeron.util.IoUtil.mapExistingFile;
import static uk.co.real_logic.aeron.util.IoUtil.mapNewFile;

/**
 * Encapsulates the allocation and mapping of conductor communication {@link ByteBuffer}s.
 *
 * Assumes one media driver per client instance.
 */
public class ConductorByteBuffers implements AutoCloseable
{
    protected static final String MEDIA_DRIVER_FILE = "media-driver";
    protected static final String CLIENT_FILE = "client";

    private MappedByteBuffer toMediaDriver;
    private MappedByteBuffer toClient;

    /**
     * Create and map the conductor buffers between the media driver and the client.
     *
     * @param adminDirName in which to create the buffers.
     * @param bufferSize to be used for the files.
     */
    public ConductorByteBuffers(final String adminDirName, final int bufferSize)
    {
        final File adminDir  = new File(adminDirName);
        IoUtil.checkDirectoryExists(new File(adminDirName), "adminDir");

        final File toMediaDriverFile = new File(adminDir, MEDIA_DRIVER_FILE);
        final File toClientFile = new File(adminDir, CLIENT_FILE);

        try
        {
            toMediaDriver = mapNewFile(toMediaDriverFile, MEDIA_DRIVER_FILE, bufferSize);
            toClient = mapNewFile(toClientFile, CLIENT_FILE, bufferSize);
        }
        catch (final IOException ex)
        {
            throw new RuntimeException(ex);
        }
    }

    /**
     * Map the conductor buffers over existing files between the media driver and the client.
     *
     * @param adminDirName in which to create the buffers.
     */
    public ConductorByteBuffers(final String adminDirName)
    {
        final File adminDir  = new File(adminDirName);
        IoUtil.checkDirectoryExists(new File(adminDirName), "adminDir");

        final File toMediaDriverFile = new File(adminDir, MEDIA_DRIVER_FILE);
        final File toClientFile = new File(adminDir, CLIENT_FILE);

        try
        {
            toMediaDriver = mapExistingFile(toMediaDriverFile, MEDIA_DRIVER_FILE);
            toClient = mapExistingFile(toClientFile, CLIENT_FILE);
        }
        catch (final IOException ex)
        {
            throw new RuntimeException(ex);
        }
    }

    /**
     * The {@link ByteBuffer} via which messages are send from the client to the media driver.
     *
     * @return the {@link ByteBuffer} via which messages are send from the client to the media driver.
     */
    public ByteBuffer toMediaDriver()
    {
        return toMediaDriver;
    }

    /**
     * The {@link ByteBuffer} via which messages are send from the media driver to the client.
     *
     * @return the {@link ByteBuffer} via which messages are send from the media driver to the client.
     */
    public ByteBuffer toClient()
    {
        return toClient;
    }

    /**
     * Un-map buffers and allow for garbage collection.
     */
    public void close()
    {
        IoUtil.unmap(toClient);
        IoUtil.unmap(toMediaDriver);
        toClient = null;
        toMediaDriver = null;
    }
}
{'fraction_non_alphanumeric': 0.0750256937307297, 'fraction_numerical': 0.0020554984583761563, 'mean_word_length': 2.8425468904244817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '832737', 'n_tokens_mistral': 2150, 'n_tokens_neox': 2076, 'n_words': 726}