java.lang.Object
org.klomp.snark.ConnectionAcceptor.TorrentAcceptLoop
- All Implemented Interfaces:
Runnable
- Enclosing class:
ConnectionAcceptor
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PeerAcceptorThe acceptor for the peer handshakes.private final PeerCoordinatorSetThe coordinators to hand accepted peers to.private booleanTrue once the loop should stop.private final TorrentDestThe torrent destination being served.private ThreadThe thread running this loop.Constructor Summary
ConstructorsConstructorDescriptionPrepares to accept connections for one torrent.Method Summary
Modifier and TypeMethodDescriptionvoidadd(PeerCoordinator coordinator) Queue a peer's accept request.voidhalt()Stops the accept loop and releases the destination.booleanisEmpty()Whether no torrents are routed through this loop.voidremove(PeerCoordinator coordinator) Remove a torrent's coordinator from this loop's routing set.voidrun()private voidrunLoop()Runs the accept loop until stopped.private voidsleep(long ms) Sleeps, returning early if interrupted.voidstart()Starts the accept loop if it is not running.
Field Details
_td
The torrent destination being served._pa
The acceptor for the peer handshakes._set
The coordinators to hand accepted peers to._stop
private volatile boolean _stopTrue once the loop should stop._thread
The thread running this loop.
Constructor Details
TorrentAcceptLoop
Prepares to accept connections for one torrent.- Parameters:
td- the torrent destination to advertiseset- the coordinators to hand accepted peers to
Method Details
add
Queue a peer's accept request.- Parameters:
coordinator- the torrent to add to this loop's routing set
remove
Remove a torrent's coordinator from this loop's routing set.- Parameters:
coordinator- the torrent coordinator to drop from the routing set
isEmpty
public boolean isEmpty()Whether no torrents are routed through this loop.- Returns:
- true when no torrents are routed through this loop
start
public void start()Starts the accept loop if it is not running.halt
public void halt()Stops the accept loop and releases the destination.run
runLoop
private void runLoop()Runs the accept loop until stopped.sleep
private void sleep(long ms) Sleeps, returning early if interrupted.- Parameters:
ms- how long to sleep