Package org.johnnei.javatorrent.tracker
Class NioPeerConnector
- java.lang.Object
-
- org.johnnei.javatorrent.tracker.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 theTorrentClient.getExecutorService()instead of a dedicated thread.
-
-
Constructor Summary
Constructors Constructor Description NioPeerConnector(TorrentClient torrentClient, int maxConcurrentConnecting)Creates a new unstarted peer connector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidenqueuePeer(PeerConnectInfo peer)Queues a peer to be connectedintgetConnectingCount()Gets the amount of peers are pending to be connected.intgetConnectingCountFor(Torrent torrent)Calculates how many connections are assigned to the torrent but haven't passed the BitTorrent handshake yet.voidstart()Starts the peer connectorvoidstop()Stops the peer connector.
-
-
-
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
-
enqueuePeer
public void enqueuePeer(PeerConnectInfo peer)
Description copied from interface:IPeerConnectorQueues a peer to be connected- Specified by:
enqueuePeerin interfaceIPeerConnector- Parameters:
peer- the peer to be connected
-
start
public void start()
Description copied from interface:IPeerConnectorStarts the peer connector- Specified by:
startin interfaceIPeerConnector
-
stop
public void stop()
Description copied from interface:IPeerConnectorStops the peer connector.- Specified by:
stopin interfaceIPeerConnector
-
getConnectingCount
public int getConnectingCount()
Description copied from interface:IPeerConnectorGets the amount of peers are pending to be connected.- Specified by:
getConnectingCountin interfaceIPeerConnector- Returns:
- The amount of peers which still need to be connected.
-
getConnectingCountFor
public int getConnectingCountFor(Torrent torrent)
Description copied from interface:IPeerConnectorCalculates how many connections are assigned to the torrent but haven't passed the BitTorrent handshake yet.- Specified by:
getConnectingCountForin interfaceIPeerConnector- Parameters:
torrent- The torrent for which connections must be counted.- Returns:
- The amount of pending peers.
-
-