Package com.biglybt.core.disk.impl
Class DiskManagerPieceImpl
- java.lang.Object
-
- com.biglybt.core.disk.impl.DiskManagerPieceImpl
-
- All Implemented Interfaces:
DiskManagerPiece
public class DiskManagerPieceImpl extends java.lang.Object implements DiskManagerPiece
-
-
Field Summary
Fields Modifier and Type Field Description private DiskManagerHelper
diskManager
private boolean
done
private short
nbBlocks
the number of blocks in this piece: can be short as this gives up to .5GB piece sizes with 16K blocksprivate static byte
PIECE_STATUS_CHECKING
private static byte
PIECE_STATUS_MASK_DOWNLOADABLE
private static byte
PIECE_STATUS_MASK_NEEDS_CHECK
private static byte
PIECE_STATUS_NEEDED
private static byte
PIECE_STATUS_WRITTEN
private static byte
PIECE_STATUS2_MERGE_READ
private static byte
PIECE_STATUS2_MERGE_WRITE
private int
pieceNumber
private short
read_count
it's *very* important to accurately maintain the "done" state of a piece.private byte
statusFlags
private byte
statusFlags2
protected boolean[]
written
-
Constructor Summary
Constructors Constructor Description DiskManagerPieceImpl(DiskManagerHelper _disk_manager, int pieceIndex, int length)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
calcDone()
boolean
calcNeeded()
void
clearNeeded()
void
clearWritten(int blockNumber)
int
getBlockSize(int blockNumber)
int
getLength()
DiskManager
getManager()
int
getNbBlocks()
int
getNbWritten()
DMPieceList
getPieceList()
int
getPieceNumber()
short
getReadCount()
int
getRemaining()
java.lang.String
getString()
boolean[]
getWritten()
written[] can be null, in which case if the piece is Done, all blocks are complete otherwise no blocks are completeboolean
isChecking()
boolean
isDone()
boolean
isDownloadable()
This must not be used to qualify pieces in End Game Mode.boolean
isInteresting()
boolean
isMergeRead()
boolean
isMergeWrite()
boolean
isNeeded()
boolean
isNeedsCheck()
boolean
isSkipped()
returns true if all the files that the piece spans are skippedboolean
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
setMergeRead()
void
setMergeWrite()
void
setNeeded()
void
setNeeded(boolean b)
void
setReadCount(short c)
void
setWritten(int blockNumber)
boolean
spansFiles()
-
-
-
Field Detail
-
PIECE_STATUS_NEEDED
private static final byte PIECE_STATUS_NEEDED
- See Also:
- Constant Field Values
-
PIECE_STATUS_WRITTEN
private static final byte PIECE_STATUS_WRITTEN
- See Also:
- Constant Field Values
-
PIECE_STATUS_CHECKING
private static final byte PIECE_STATUS_CHECKING
- See Also:
- Constant Field Values
-
PIECE_STATUS2_MERGE_READ
private static final byte PIECE_STATUS2_MERGE_READ
- See Also:
- Constant Field Values
-
PIECE_STATUS2_MERGE_WRITE
private static final byte PIECE_STATUS2_MERGE_WRITE
- See Also:
- Constant Field Values
-
PIECE_STATUS_MASK_DOWNLOADABLE
private static final byte PIECE_STATUS_MASK_DOWNLOADABLE
- See Also:
- Constant Field Values
-
PIECE_STATUS_MASK_NEEDS_CHECK
private static final byte PIECE_STATUS_MASK_NEEDS_CHECK
- See Also:
- Constant Field Values
-
diskManager
private final DiskManagerHelper diskManager
-
pieceNumber
private final int pieceNumber
-
nbBlocks
private final short nbBlocks
the number of blocks in this piece: can be short as this gives up to .5GB piece sizes with 16K blocks
-
written
protected volatile boolean[] written
-
statusFlags
private byte statusFlags
-
statusFlags2
private byte statusFlags2
-
read_count
private short read_count
it's *very* important to accurately maintain the "done" state of a piece. Currently the statusFlags are updated in a non-thread-safe manner so a 'done' field is maintained separately. Synchronizing access to statusFlags or done would cause a tremendous performance hit.
-
done
private boolean done
-
-
Constructor Detail
-
DiskManagerPieceImpl
public DiskManagerPieceImpl(DiskManagerHelper _disk_manager, int pieceIndex, int length)
-
-
Method Detail
-
getManager
public DiskManager getManager()
- Specified by:
getManager
in interfaceDiskManagerPiece
-
getPieceNumber
public int getPieceNumber()
- Specified by:
getPieceNumber
in interfaceDiskManagerPiece
-
getLength
public int getLength()
- Specified by:
getLength
in interfaceDiskManagerPiece
- Returns:
- int number of bytes in the piece
-
getNbBlocks
public int getNbBlocks()
- Specified by:
getNbBlocks
in interfaceDiskManagerPiece
-
getReadCount
public short getReadCount()
- Specified by:
getReadCount
in interfaceDiskManagerPiece
-
setReadCount
public void setReadCount(short c)
- Specified by:
setReadCount
in interfaceDiskManagerPiece
-
getBlockSize
public int getBlockSize(int blockNumber)
- Specified by:
getBlockSize
in interfaceDiskManagerPiece
-
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 interfaceDiskManagerPiece
- Returns:
-
isNeeded
public boolean isNeeded()
- Specified by:
isNeeded
in interfaceDiskManagerPiece
- 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
-
calcNeeded
public boolean calcNeeded()
- Specified by:
calcNeeded
in interfaceDiskManagerPiece
-
spansFiles
public boolean spansFiles()
- Specified by:
spansFiles
in interfaceDiskManagerPiece
-
getPieceList
public DMPieceList getPieceList()
- Specified by:
getPieceList
in interfaceDiskManagerPiece
-
clearNeeded
public void clearNeeded()
- Specified by:
clearNeeded
in interfaceDiskManagerPiece
-
setNeeded
public void setNeeded()
- Specified by:
setNeeded
in interfaceDiskManagerPiece
-
setNeeded
public void setNeeded(boolean b)
- Specified by:
setNeeded
in interfaceDiskManagerPiece
-
isWritten
public boolean isWritten()
- Specified by:
isWritten
in interfaceDiskManagerPiece
-
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 interfaceDiskManagerPiece
-
isWritten
public boolean isWritten(int blockNumber)
- Specified by:
isWritten
in interfaceDiskManagerPiece
- Parameters:
blockNumber
- int- Returns:
- true if the given blockNumber has already been written to disk
-
getNbWritten
public int getNbWritten()
- Specified by:
getNbWritten
in interfaceDiskManagerPiece
-
setWritten
public void setWritten(int blockNumber)
- Specified by:
setWritten
in interfaceDiskManagerPiece
-
clearWritten
public void clearWritten(int blockNumber)
- Specified by:
clearWritten
in interfaceDiskManagerPiece
-
isChecking
public boolean isChecking()
- Specified by:
isChecking
in interfaceDiskManagerPiece
-
setChecking
public void setChecking()
- Specified by:
setChecking
in interfaceDiskManagerPiece
-
isNeedsCheck
public boolean isNeedsCheck()
- Specified by:
isNeedsCheck
in interfaceDiskManagerPiece
-
calcDone
public boolean calcDone()
- Specified by:
calcDone
in interfaceDiskManagerPiece
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfaceDiskManagerPiece
- 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 interfaceDiskManagerPiece
-
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 interfaceDiskManagerPiece
-
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 interfaceDiskManagerPiece
- 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 interfaceDiskManagerPiece
- Returns:
- true if the piece is Needed and not Done
-
getRemaining
public int getRemaining()
- Specified by:
getRemaining
in interfaceDiskManagerPiece
-
reset
public void reset()
- Specified by:
reset
in interfaceDiskManagerPiece
-
reDownloadBlock
public void reDownloadBlock(int blockNumber)
- Specified by:
reDownloadBlock
in interfaceDiskManagerPiece
-
setMergeRead
public void setMergeRead()
- Specified by:
setMergeRead
in interfaceDiskManagerPiece
-
isMergeRead
public boolean isMergeRead()
- Specified by:
isMergeRead
in interfaceDiskManagerPiece
-
setMergeWrite
public void setMergeWrite()
- Specified by:
setMergeWrite
in interfaceDiskManagerPiece
-
isMergeWrite
public boolean isMergeWrite()
- Specified by:
isMergeWrite
in interfaceDiskManagerPiece
-
getString
public java.lang.String getString()
- Specified by:
getString
in interfaceDiskManagerPiece
-
-