org.gudy.azureus2.core3.peer.impl
Class PEPieceImpl

java.lang.Object
  extended by org.gudy.azureus2.core3.peer.impl.PEPieceImpl
All Implemented Interfaces:
PEPiece

public class PEPieceImpl
extends Object
implements PEPiece


Field Summary
protected static AEMonitor class_mon
           
 
Constructor Summary
PEPieceImpl(PEPeerManager _manager, DiskManagerPiece _dm_piece, int _pieceSpeed)
          piece for tracking partially downloaded pieces
 
Method Summary
 void addWrite(int blockNumber, String sender, byte[] hash, boolean correct)
          record details of a piece's blocks that have been completed for bad peer detection purposes
protected  void addWrite(PEPieceWriteImpl write)
           
 void checkRequests()
          This will scan each block looking for requested blocks.
 void clearDownloaded(int offset)
          This flags the block at the given offset as NOT having been downloaded and the whole piece as not having been fully downloaded
 void clearRequested(int blockNumber)
          This method clears the requested information for the given block unless the block has already been downloaded, in which case the writer's IP is recorded as a request for the block.
 void getAndMarkBlock(PEPeer peer, int index)
           
 int[] getAndMarkBlocks(PEPeer peer, int nbWanted, int[] request_hint, boolean reverse_order)
          This method scans a piece for the first unrequested block.
 int getAvailability()
           
 int getBlockNumber(int offset)
           
 int getBlockSize(int blockNumber)
           
 long getCreationTime()
          The time the pePiece was [re]created
 DiskManagerPiece getDMPiece()
           
 boolean[] getDownloaded()
           
 long getLastDownloadTime(long now)
           
 int getLength()
           
 PEPeerManager getManager()
           
 int getNbBlocks()
           
 int getNbRequests()
           
 int getNbUnrequested()
           
 int getNbWritten()
          This support method returns how many blocks have already been written from the dmPiece
 int getPieceNumber()
           
 List getPieceWrites()
           
 List getPieceWrites(int blockNumber)
           
 List getPieceWrites(PEPeer peer)
           
 List getPieceWrites(String ip)
           
 Object getRealTimeData()
           
 String getReservedBy()
           
 int getResumePriority()
           
 int getSpeed()
           
 String getString()
           
 long getTimeSinceLastActivity()
          How many ms since a write to the piece, or since the piece was created if no last write time is known.
 String[] getWriters()
           
 boolean[] getWritten()
          This support method returns the dmPiece's written array
 boolean hasUndownloadedBlock()
           
 boolean hasUnrequestedBlock()
           
 boolean isDownloaded()
           
 boolean isDownloaded(int blockNumber)
          Tells if a block has been downloaded
 boolean isRequestable()
           
 boolean isRequested()
           
 boolean isRequested(int blockNumber)
          Tells if a block has been requested
 boolean isWritten()
           
 boolean isWritten(int block)
           
 void reDownloadBlock(int blockNumber)
          for a block that's already downloadedt, mark up the piece so that the block will get downloaded again.
 void reDownloadBlocks(String address)
          finds all blocks downloaded by the given address and marks them up for re-downloading
 void reset()
           
 void setDownloaded(int offset)
          This flags the block at the given offset as having been downloaded If all blocks are now downloaed, sets the dmPiece as downloaded
 void setLastRequestedPeerSpeed(int peerSpeed)
           
 void setRealTimeData(Object o)
           
 void setRequestable()
           
 void setRequested()
           
 boolean setRequested(PEPeer peer, int blockNumber)
          Assumption - single threaded with getAndMarkBlock
 void setReservedBy(String peer)
           
 void setResumePriority(int p)
           
 void setSpeed(int newSpeed)
           
 void setWritten(String peer, int blockNumber)
          This marks a given block as having been written by the given peer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

class_mon

protected static final AEMonitor class_mon
Constructor Detail

PEPieceImpl

public PEPieceImpl(PEPeerManager _manager,
                   DiskManagerPiece _dm_piece,
                   int _pieceSpeed)
piece for tracking partially downloaded pieces

Parameters:
_manager - the PEPeerManager
_dm_piece - the backing dmPiece
_pieceSpeed - the speed threshold for potential new requesters
Method Detail

getDMPiece

public DiskManagerPiece getDMPiece()
Specified by:
getDMPiece in interface PEPiece

getCreationTime

public long getCreationTime()
Description copied from interface: PEPiece
The time the pePiece was [re]created

Specified by:
getCreationTime in interface PEPiece

getTimeSinceLastActivity

public long getTimeSinceLastActivity()
Description copied from interface: PEPiece
How many ms since a write to the piece, or since the piece was created if no last write time is known. The return value will be 0 when there's no writes and the piece is new.

Specified by:
getTimeSinceLastActivity in interface PEPiece
Returns:
long

getLastDownloadTime

public long getLastDownloadTime(long now)
Specified by:
getLastDownloadTime in interface PEPiece

isRequested

public boolean isRequested(int blockNumber)
Tells if a block has been requested

Specified by:
isRequested in interface PEPiece
Parameters:
blockNumber - the block in question
Returns:
true if the block is Requested already

isDownloaded

public boolean isDownloaded(int blockNumber)
Tells if a block has been downloaded

Specified by:
isDownloaded in interface PEPiece
Parameters:
blockNumber - the block in question
Returns:
true if the block is downloaded already

setDownloaded

public void setDownloaded(int offset)
This flags the block at the given offset as having been downloaded If all blocks are now downloaed, sets the dmPiece as downloaded

Specified by:
setDownloaded in interface PEPiece
Parameters:
blockNumber -

clearDownloaded

public void clearDownloaded(int offset)
This flags the block at the given offset as NOT having been downloaded and the whole piece as not having been fully downloaded

Specified by:
clearDownloaded in interface PEPiece
Parameters:
blockNumber -

isDownloaded

public boolean isDownloaded()
Specified by:
isDownloaded in interface PEPiece

getDownloaded

public boolean[] getDownloaded()
Specified by:
getDownloaded in interface PEPiece

hasUndownloadedBlock

public boolean hasUndownloadedBlock()
Specified by:
hasUndownloadedBlock in interface PEPiece

setWritten

public void setWritten(String peer,
                       int blockNumber)
This marks a given block as having been written by the given peer

Specified by:
setWritten in interface PEPiece
Parameters:
peer - the peer that sent the data
blockNumber - the block we're operating on

clearRequested

public void clearRequested(int blockNumber)
This method clears the requested information for the given block unless the block has already been downloaded, in which case the writer's IP is recorded as a request for the block.

Specified by:
clearRequested in interface PEPiece

isRequested

public boolean isRequested()
Specified by:
isRequested in interface PEPiece

setRequested

public void setRequested()
Specified by:
setRequested in interface PEPiece

checkRequests

public void checkRequests()
This will scan each block looking for requested blocks. For each one, it'll verify if the PEPeer for it still exists and is still willing and able to upload data. If not, it'll unmark the block as requested.


hasUnrequestedBlock

public boolean hasUnrequestedBlock()
Specified by:
hasUnrequestedBlock in interface PEPiece
Returns:
true if the piece has any blocks that are not; Downloaded, Requested, or Written

getAndMarkBlocks

public int[] getAndMarkBlocks(PEPeer peer,
                              int nbWanted,
                              int[] request_hint,
                              boolean reverse_order)
This method scans a piece for the first unrequested block. Upon finding it, it counts how many are unrequested up to nbWanted. The blocks are marked as requested by the PEPeer Assumption - single threaded access to this TODO: this should return the largest span equal or smaller than nbWanted OR, probably a different method should do that, so this one can support 'more sequential' picking

Specified by:
getAndMarkBlocks in interface PEPiece

getAndMarkBlock

public void getAndMarkBlock(PEPeer peer,
                            int index)
Specified by:
getAndMarkBlock in interface PEPiece

getNbRequests

public int getNbRequests()
Specified by:
getNbRequests in interface PEPiece

getNbUnrequested

public int getNbUnrequested()
Specified by:
getNbUnrequested in interface PEPiece

setRequested

public boolean setRequested(PEPeer peer,
                            int blockNumber)
Assumption - single threaded with getAndMarkBlock

Specified by:
setRequested in interface PEPiece

isRequestable

public boolean isRequestable()
Specified by:
isRequestable in interface PEPiece

getBlockSize

public int getBlockSize(int blockNumber)
Specified by:
getBlockSize in interface PEPiece

getBlockNumber

public int getBlockNumber(int offset)
Specified by:
getBlockNumber in interface PEPiece
Parameters:
offset - int bytes into piece
Returns:
block int number corresponding to given offset

getNbBlocks

public int getNbBlocks()
Specified by:
getNbBlocks in interface PEPiece

getPieceWrites

public List getPieceWrites()

getPieceWrites

public List getPieceWrites(int blockNumber)

getPieceWrites

public List getPieceWrites(PEPeer peer)

getPieceWrites

public List getPieceWrites(String ip)

reset

public void reset()
Specified by:
reset in interface PEPiece

getRealTimeData

public Object getRealTimeData()
Specified by:
getRealTimeData in interface PEPiece

setRealTimeData

public void setRealTimeData(Object o)
Specified by:
setRealTimeData in interface PEPiece

addWrite

protected void addWrite(PEPieceWriteImpl write)

addWrite

public void addWrite(int blockNumber,
                     String sender,
                     byte[] hash,
                     boolean correct)
Description copied from interface: PEPiece
record details of a piece's blocks that have been completed for bad peer detection purposes

Specified by:
addWrite in interface PEPiece

getWriters

public String[] getWriters()
Specified by:
getWriters in interface PEPiece

getSpeed

public int getSpeed()
Specified by:
getSpeed in interface PEPiece

setSpeed

public void setSpeed(int newSpeed)
Specified by:
setSpeed in interface PEPiece

setLastRequestedPeerSpeed

public void setLastRequestedPeerSpeed(int peerSpeed)
Specified by:
setLastRequestedPeerSpeed in interface PEPiece

getManager

public PEPeerManager getManager()
Specified by:
getManager in interface PEPiece
Returns:
Returns the manager.

setReservedBy

public void setReservedBy(String peer)
Specified by:
setReservedBy in interface PEPiece

getReservedBy

public String getReservedBy()
Specified by:
getReservedBy in interface PEPiece

reDownloadBlock

public void reDownloadBlock(int blockNumber)
for a block that's already downloadedt, mark up the piece so that the block will get downloaded again. This is used when the piece fails hash-checking.


reDownloadBlocks

public void reDownloadBlocks(String address)
finds all blocks downloaded by the given address and marks them up for re-downloading

Parameters:
address - String

setResumePriority

public void setResumePriority(int p)
Specified by:
setResumePriority in interface PEPiece
Parameters:
p - the Resume Priority to set, for display purposes

getResumePriority

public int getResumePriority()
Specified by:
getResumePriority in interface PEPiece
Returns:
int ResumePriority (startPriority + resuming adjustments)

getAvailability

public int getAvailability()
Specified by:
getAvailability in interface PEPiece
Returns:
int of availability in the swarm for this piece
See Also:
org.gudy.azureus2.core3.peer.PEPeerManager.getAvailability(int pieceNumber)

getNbWritten

public int getNbWritten()
This support method returns how many blocks have already been written from the dmPiece

Specified by:
getNbWritten in interface PEPiece
Returns:
int from dmPiece.getNbWritten()
See Also:
org.gudy.azureus2.core3.disk.DiskManagerPiece.getNbWritten()

getWritten

public boolean[] getWritten()
This support method returns the dmPiece's written array

Returns:
boolean[] from the dmPiece
See Also:
org.gudy.azureus2.core3.disk.DiskManagerPiece.getWritten()

isWritten

public boolean isWritten()
Specified by:
isWritten in interface PEPiece

isWritten

public boolean isWritten(int block)
Specified by:
isWritten in interface PEPiece

getPieceNumber

public int getPieceNumber()
Specified by:
getPieceNumber in interface PEPiece

getLength

public int getLength()
Specified by:
getLength in interface PEPiece

setRequestable

public void setRequestable()

getString

public String getString()
Specified by:
getString in interface PEPiece