<commit_before>package com.turn.ttorrent.client.network;

import com.turn.ttorrent.client.peer.PeerActivityListener;
import com.turn.ttorrent.common.LoggerUtils;
import com.turn.ttorrent.common.PeersStorageProvider;
import com.turn.ttorrent.common.TorrentsStorageProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.*;

public class ConnectionManager {

  private static final Logger logger = LoggerFactory.getLogger(ConnectionManager.class);

  public static final int PORT_RANGE_START = 6881;
  public static final int PORT_RANGE_END = 6889;

  private final Selector selector;
  private final InetAddress inetAddress;
  private final CountDownLatch myWorkerShutdownChecker;
  private final ChannelListenerFactory channelListenerFactory;
  private ConnectionWorker myConnectionWorker;
  private ServerSocketChannel myServerSocketChannel;
  private InetSocketAddress myBindAddress;
  private final ExecutorService myExecutorService;
  private Future<?> myWorkerFuture;

  public ConnectionManager(InetAddress inetAddress,
                           PeersStorageProvider peersStorageProvider,
                           TorrentsStorageProvider torrentsStorageProvider,
                           PeerActivityListener peerActivityListener,
                           ExecutorService executorService) throws IOException {
    this(inetAddress, new ChannelListenerFactoryImpl(peersStorageProvider, torrentsStorageProvider, peerActivityListener), executorService);
  }

  public ConnectionManager(InetAddress inetAddress,
                           ChannelListenerFactory channelListenerFactory,
                           ExecutorService executorService) throws IOException {
    this.myExecutorService = executorService;
    this.selector = Selector.open();
    this.inetAddress = inetAddress;
    this.channelListenerFactory = channelListenerFactory;
    this.myWorkerShutdownChecker = new CountDownLatch(1);
  }

  public void initAndRunWorker() throws IOException {
    myServerSocketChannel = selector.provider().openServerSocketChannel();
    myServerSocketChannel.configureBlocking(false);

    for (int port = PORT_RANGE_START; port < PORT_RANGE_END; port++) {
      try {<commit_msg>added volatile modifiers to connection manager fields<commit_after>package com.turn.ttorrent.client.network;

import com.turn.ttorrent.client.peer.PeerActivityListener;
import com.turn.ttorrent.common.LoggerUtils;
import com.turn.ttorrent.common.PeersStorageProvider;
import com.turn.ttorrent.common.TorrentsStorageProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.*;

public class ConnectionManager {

  private static final Logger logger = LoggerFactory.getLogger(ConnectionManager.class);

  public static final int PORT_RANGE_START = 6881;
  public static final int PORT_RANGE_END = 6889;

  private final Selector selector;
  private final InetAddress inetAddress;
  private final CountDownLatch myWorkerShutdownChecker;
  private final ChannelListenerFactory channelListenerFactory;
  private volatile ConnectionWorker myConnectionWorker;
  private volatile ServerSocketChannel myServerSocketChannel;
  private InetSocketAddress myBindAddress;
  private final ExecutorService myExecutorService;
  private volatile Future<?> myWorkerFuture;

  public ConnectionManager(InetAddress inetAddress,
                           PeersStorageProvider peersStorageProvider,
                           TorrentsStorageProvider torrentsStorageProvider,
                           PeerActivityListener peerActivityListener,
                           ExecutorService executorService) throws IOException {
    this(inetAddress, new ChannelListenerFactoryImpl(peersStorageProvider, torrentsStorageProvider, peerActivityListener), executorService);
  }

  public ConnectionManager(InetAddress inetAddress,
                           ChannelListenerFactory channelListenerFactory,
                           ExecutorService executorService) throws IOException {
    this.myExecutorService = executorService;
    this.selector = Selector.open();
    this.inetAddress = inetAddress;
    this.channelListenerFactory = channelListenerFactory;
    this.myWorkerShutdownChecker = new CountDownLatch(1);
  }

  public void initAndRunWorker() throws IOException {
    myServerSocketChannel = selector.provider().openServerSocketChannel();
    myServerSocketChannel.configureBlocking(false);

    for (int port = PORT_RANGE_START; port < PORT_RANGE_END; port++) {
      try {
{'fraction_non_alphanumeric': 0.06135216952573158, 'fraction_numerical': 0.004439959636730575, 'mean_word_length': 4.375271149674621, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5397025', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1222, 'n_words': 281}