org.gudy.azureus2.core3.disk.impl
Class DiskManagerPieceImpl

java.lang.Object
  extended by org.gudy.azureus2.core3.disk.impl.DiskManagerPieceImpl
All Implemented Interfaces:
DiskManagerPiece

public class DiskManagerPieceImpl
extends Object
implements DiskManagerPiece


Field Summary
protected  boolean[] written
           
 
Constructor Summary
DiskManagerPieceImpl(DiskManagerHelper _disk_manager, int pieceIndex, int length)
           
 
Method Summary
 boolean calcDone()
           
 boolean calcNeeded()
           
 void clearNeeded()
           
 int getBlockSize(int blockNumber)
           
 int getLength()
           
 DiskManager getManager()
           
 int getNbBlocks()
           
 int getNbWritten()
           
 int getPieceNumber()
           
 short getReadCount()
           
 String getString()
           
 boolean[] getWritten()
          written[] can be null, in which case if the piece is Done, all blocks are complete otherwise no blocks are complete
 boolean isChecking()
           
 boolean isDone()
           
 boolean isDownloadable()
          This must not be used to qualify pieces in End Game Mode.
 boolean isInteresting()
           
 boolean isNeeded()
           
 boolean isNeedsCheck()
           
 boolean isSkipped()
          returns true if all the files that the piece spans are skipped
 boolean isWritten()
           
 boolean isWritten(int blockNumber)
           
 void reDownloadBlock(int blockNumber)
           
 void reset()
           
 void setChecking()
           
 void setDone(boolean b)
           
 void setDoneSupport(boolean b)
          this is ONLY used by the disk manager to update the done state while synchronized i.e.
 void setDownloadable()
           
 void setNeeded()
           
 void setNeeded(boolean b)
           
 void setReadCount(short c)
           
 void setWritten(int blockNumber)
           
 boolean spansFiles()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

written

protected volatile boolean[] written
Constructor Detail

DiskManagerPieceImpl

public DiskManagerPieceImpl(DiskManagerHelper _disk_manager,
                            int pieceIndex,
                            int length)
Method Detail

getManager

public DiskManager getManager()
Specified by:
getManager in interface DiskManagerPiece

getPieceNumber

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

getLength

public int getLength()
Specified by:
getLength in interface DiskManagerPiece
Returns:
int number of bytes in the piece

getNbBlocks

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

getReadCount

public short getReadCount()
Specified by:
getReadCount in interface DiskManagerPiece

setReadCount

public void setReadCount(short c)
Specified by:
setReadCount in interface DiskManagerPiece

getBlockSize

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

isSkipped

public boolean isSkipped()
Description copied from interface: DiskManagerPiece
returns true if all the files that the piece spans are skipped

Specified by:
isSkipped in interface DiskManagerPiece
Returns:

isNeeded

public boolean isNeeded()
Specified by:
isNeeded in interface DiskManagerPiece
Returns:
true if any file the piece covers is neither Do Not Download nor Delete. This is not a real-time indicator. Also, the results are not reliable for pieces that are Done. Use calcNeeded() for guaranteed correct and up to date results
See Also:
calcNeeded(), clearNeeded(), setNeeded(), setNeeded(boolean)

calcNeeded

public boolean calcNeeded()
Specified by:
calcNeeded in interface DiskManagerPiece

spansFiles

public boolean spansFiles()
Specified by:
spansFiles in interface DiskManagerPiece

clearNeeded

public void clearNeeded()
Specified by:
clearNeeded in interface DiskManagerPiece

setNeeded

public void setNeeded()
Specified by:
setNeeded in interface DiskManagerPiece

setNeeded

public void setNeeded(boolean b)
Specified by:
setNeeded in interface DiskManagerPiece

isWritten

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

getWritten

public boolean[] getWritten()
written[] can be null, in which case if the piece is Done, all blocks are complete otherwise no blocks are complete

Specified by:
getWritten in interface DiskManagerPiece

isWritten

public boolean isWritten(int blockNumber)
Specified by:
isWritten in interface DiskManagerPiece
Parameters:
blockNumber - int
Returns:
true if the given blockNumber has already been written to disk

getNbWritten

public int getNbWritten()
Specified by:
getNbWritten in interface DiskManagerPiece

setWritten

public void setWritten(int blockNumber)
Specified by:
setWritten in interface DiskManagerPiece

isChecking

public boolean isChecking()
Specified by:
isChecking in interface DiskManagerPiece

setChecking

public void setChecking()
Specified by:
setChecking in interface DiskManagerPiece

isNeedsCheck

public boolean isNeedsCheck()
Specified by:
isNeedsCheck in interface DiskManagerPiece

calcDone

public boolean calcDone()
Specified by:
calcDone in interface DiskManagerPiece

isDone

public boolean isDone()
Specified by:
isDone in interface DiskManagerPiece
Returns:
true when the hash check has passed and the DiskManager has asyncronously updated the Done status. There is nothing further to be done regarding downloading for pieces that are Done.

setDone

public void setDone(boolean b)
Specified by:
setDone in interface DiskManagerPiece

setDoneSupport

public void setDoneSupport(boolean b)
this is ONLY used by the disk manager to update the done state while synchronized i.e. don't use it else where!

Parameters:
b -

setDownloadable

public void setDownloadable()
Specified by:
setDownloadable in interface DiskManagerPiece

isDownloadable

public boolean isDownloadable()
Description copied from interface: DiskManagerPiece
This must not be used to qualify pieces in End Game Mode.

Specified by:
isDownloadable in interface DiskManagerPiece
Returns:
true if a piece is Needed but is not fully; Requested, Downloaded, Written, Checking, or Done.

isInteresting

public boolean isInteresting()
Specified by:
isInteresting in interface DiskManagerPiece
Returns:
true if the piece is Needed and not Done

reset

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

reDownloadBlock

public void reDownloadBlock(int blockNumber)
Specified by:
reDownloadBlock in interface DiskManagerPiece

getString

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