com.aelitis.azureus.core.peermanager.utils
Class OutgoingBTPieceMessageHandler

java.lang.Object
  extended by com.aelitis.azureus.core.peermanager.utils.OutgoingBTPieceMessageHandler

public class OutgoingBTPieceMessageHandler
extends Object

Front-end manager for handling requested outgoing bittorrent Piece messages. Peers often make piece requests in batch, with multiple requests always outstanding, all of which won't necessarily be honored (i.e. we choke them), so we don't want to waste time reading in the piece data from disk ahead of time for all the requests. Thus, we only want to perform read-aheads for a small subset of the requested data at any given time, which is what this handler does, before passing the messages onto the outgoing message queue for transmission.


Constructor Summary
OutgoingBTPieceMessageHandler(PEPeer _peer, OutgoingMessageQueue _outgoing_message_q, OutgoingBTPieceMessageHandlerAdapter _adapter, byte _piece_version)
          Create a new handler for outbound piece messages, reading piece data from the given disk manager and transmitting the messages out the given message queue.
 
Method Summary
 boolean addPieceRequest(int piece_number, int piece_offset, int length)
          Register a new piece data request.
 void destroy()
           
 int getRequestCount()
           
 int[] getRequestedPieceNumbers()
          Get a list of piece numbers being requested
 boolean isStalledPendingLoad()
           
 void removeAllPieceRequests()
          Remove all outstanding piece data requests.
 void removePieceRequest(int piece_number, int piece_offset, int length)
          Remove an outstanding piece data request.
 void setPieceVersion(byte version)
           
 void setRequestReadAhead(int num_to_read_ahead)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutgoingBTPieceMessageHandler

public OutgoingBTPieceMessageHandler(PEPeer _peer,
                                     OutgoingMessageQueue _outgoing_message_q,
                                     OutgoingBTPieceMessageHandlerAdapter _adapter,
                                     byte _piece_version)
Create a new handler for outbound piece messages, reading piece data from the given disk manager and transmitting the messages out the given message queue.

Parameters:
disk_manager -
outgoing_message_q -
Method Detail

setPieceVersion

public void setPieceVersion(byte version)

addPieceRequest

public boolean addPieceRequest(int piece_number,
                               int piece_offset,
                               int length)
Register a new piece data request.

Parameters:
piece_number -
piece_offset -
length -

removePieceRequest

public void removePieceRequest(int piece_number,
                               int piece_offset,
                               int length)
Remove an outstanding piece data request.

Parameters:
piece_number -
piece_offset -
length -

removeAllPieceRequests

public void removeAllPieceRequests()
Remove all outstanding piece data requests.


setRequestReadAhead

public void setRequestReadAhead(int num_to_read_ahead)

destroy

public void destroy()

getRequestedPieceNumbers

public int[] getRequestedPieceNumbers()
Get a list of piece numbers being requested

Returns:
list of Long values

getRequestCount

public int getRequestCount()

isStalledPendingLoad

public boolean isStalledPendingLoad()