java.lang.Object
org.klomp.snark.ConnectionAcceptor.TorrentAcceptLoop
All Implemented Interfaces:
Runnable
Enclosing class:
ConnectionAcceptor

private class ConnectionAcceptor.TorrentAcceptLoopextends Object implements Runnable
Accept loop for a destination, serving every torrent pooled on it, routed by the info hash in the handshake. Multitorrent only.
  • Field Details

    • _td

      private final TorrentDest _td
      The torrent destination being served.
    • _pa

      private final PeerAcceptor _pa
      The acceptor for the peer handshakes.
    • _set

      private final PeerCoordinatorSet _set
      The coordinators to hand accepted peers to.
    • _stop

      private volatile boolean _stop
      True once the loop should stop.
    • _thread

      private Thread _thread
      The thread running this loop.
  • Constructor Details

    • TorrentAcceptLoop

      public TorrentAcceptLoop(TorrentDest td, PeerCoordinatorSet set)
      Prepares to accept connections for one torrent.
      Parameters:
      td - the torrent destination to advertise
      set - the coordinators to hand accepted peers to
  • Method Details

    • add

      public void add(PeerCoordinator coordinator)
      Queue a peer's accept request.
      Parameters:
      coordinator - the torrent to add to this loop's routing set
    • remove

      public void remove(PeerCoordinator coordinator)
      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

      public void run()
      Specified by:
      run in interface Runnable
    • 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