Class NioPeerConnector

  • All Implemented Interfaces:
    IPeerConnector

    public class NioPeerConnector
    extends Object
    implements IPeerConnector
    A peer connector which allows simultaneously connect to several peers at a time. This implementation is optimized to be non-blocking thus allowing it to use the TorrentClient.getExecutorService() instead of a dedicated thread.
    • Constructor Detail

      • NioPeerConnector

        public NioPeerConnector​(TorrentClient torrentClient,
                                int maxConcurrentConnecting)
        Creates a new unstarted peer connector.
        Parameters:
        torrentClient - The client for which this connector will connect peers.
        maxConcurrentConnecting - The maximum amount of pending connections at any given time.
    • Method Detail

      • getConnectingCount

        public int getConnectingCount()
        Description copied from interface: IPeerConnector
        Gets the amount of peers are pending to be connected.
        Specified by:
        getConnectingCount in interface IPeerConnector
        Returns:
        The amount of peers which still need to be connected.
      • getConnectingCountFor

        public int getConnectingCountFor​(Torrent torrent)
        Description copied from interface: IPeerConnector
        Calculates how many connections are assigned to the torrent but haven't passed the BitTorrent handshake yet.
        Specified by:
        getConnectingCountFor in interface IPeerConnector
        Parameters:
        torrent - The torrent for which connections must be counted.
        Returns:
        The amount of pending peers.