Class DiskManagerPieceImpl
java.lang.Object
com.biglybt.core.disk.impl.DiskManagerPieceImpl
- All Implemented Interfaces:
DiskManagerPiece
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DiskManagerHelperprivate booleanprivate final shortthe number of blocks in this piece: can be short as this gives up to .5GB piece sizes with 16K blocksprivate static final byteprivate static final byteprivate static final byteprivate static final byteprivate static final byteprivate static final byteprivate static final byteprivate final intprivate shortit's *very* important to accurately maintain the "done" state of a piece.private byteprivate byteprotected boolean[] -
Constructor Summary
ConstructorsConstructorDescriptionDiskManagerPieceImpl(DiskManagerHelper _disk_manager, int pieceIndex, int length) -
Method Summary
Modifier and TypeMethodDescriptionbooleancalcDone()booleanvoidvoidclearWritten(int blockNumber) intgetBlockSize(int blockNumber) intintintintshortintboolean[]written[] can be null, in which case if the piece is Done, all blocks are complete otherwise no blocks are completebooleanbooleanisDone()booleanThis must not be used to qualify pieces in End Game Mode.booleanbooleanbooleanbooleanisNeeded()booleanbooleanreturns true if all the files that the piece spans are skippedbooleanbooleanisWritten(int blockNumber) voidreDownloadBlock(int blockNumber) voidreset()voidvoidsetDone(boolean b) voidsetDoneSupport(boolean b) this is ONLY used by the disk manager to update the done state while synchronized i.e.voidvoidvoidvoidvoidsetNeeded(boolean b) voidsetReadCount(short c) voidsetWritten(int blockNumber) boolean
-
Field Details
-
PIECE_STATUS_NEEDED
private static final byte PIECE_STATUS_NEEDED- See Also:
-
PIECE_STATUS_WRITTEN
private static final byte PIECE_STATUS_WRITTEN- See Also:
-
PIECE_STATUS_CHECKING
private static final byte PIECE_STATUS_CHECKING- See Also:
-
PIECE_STATUS2_MERGE_READ
private static final byte PIECE_STATUS2_MERGE_READ- See Also:
-
PIECE_STATUS2_MERGE_WRITE
private static final byte PIECE_STATUS2_MERGE_WRITE- See Also:
-
PIECE_STATUS_MASK_DOWNLOADABLE
private static final byte PIECE_STATUS_MASK_DOWNLOADABLE- See Also:
-
PIECE_STATUS_MASK_NEEDS_CHECK
private static final byte PIECE_STATUS_MASK_NEEDS_CHECK- See Also:
-
diskManager
-
pieceNumber
private final int pieceNumber -
nbBlocks
private final short nbBlocksthe 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_countit'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 Details
-
DiskManagerPieceImpl
-
-
Method Details
-
getManager
- Specified by:
getManagerin interfaceDiskManagerPiece
-
getPieceNumber
public int getPieceNumber()- Specified by:
getPieceNumberin interfaceDiskManagerPiece
-
getLength
public int getLength()- Specified by:
getLengthin interfaceDiskManagerPiece- Returns:
- int number of bytes in the piece
-
getNbBlocks
public int getNbBlocks()- Specified by:
getNbBlocksin interfaceDiskManagerPiece
-
getReadCount
public short getReadCount()- Specified by:
getReadCountin interfaceDiskManagerPiece
-
setReadCount
public void setReadCount(short c) - Specified by:
setReadCountin interfaceDiskManagerPiece
-
getBlockSize
public int getBlockSize(int blockNumber) - Specified by:
getBlockSizein interfaceDiskManagerPiece
-
isSkipped
public boolean isSkipped()Description copied from interface:DiskManagerPiecereturns true if all the files that the piece spans are skipped- Specified by:
isSkippedin interfaceDiskManagerPiece- Returns:
-
isNeeded
public boolean isNeeded()- Specified by:
isNeededin 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:
calcNeededin interfaceDiskManagerPiece
-
spansFiles
public boolean spansFiles()- Specified by:
spansFilesin interfaceDiskManagerPiece
-
getPieceList
- Specified by:
getPieceListin interfaceDiskManagerPiece
-
clearNeeded
public void clearNeeded()- Specified by:
clearNeededin interfaceDiskManagerPiece
-
setNeeded
public void setNeeded()- Specified by:
setNeededin interfaceDiskManagerPiece
-
setNeeded
public void setNeeded(boolean b) - Specified by:
setNeededin interfaceDiskManagerPiece
-
isWritten
public boolean isWritten()- Specified by:
isWrittenin 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:
getWrittenin interfaceDiskManagerPiece
-
isWritten
public boolean isWritten(int blockNumber) - Specified by:
isWrittenin interfaceDiskManagerPiece- Parameters:
blockNumber- int- Returns:
- true if the given blockNumber has already been written to disk
-
getNbWritten
public int getNbWritten()- Specified by:
getNbWrittenin interfaceDiskManagerPiece
-
setWritten
public void setWritten(int blockNumber) - Specified by:
setWrittenin interfaceDiskManagerPiece
-
clearWritten
public void clearWritten(int blockNumber) - Specified by:
clearWrittenin interfaceDiskManagerPiece
-
isChecking
public boolean isChecking()- Specified by:
isCheckingin interfaceDiskManagerPiece
-
setChecking
public void setChecking()- Specified by:
setCheckingin interfaceDiskManagerPiece
-
isNeedsCheck
public boolean isNeedsCheck()- Specified by:
isNeedsCheckin interfaceDiskManagerPiece
-
calcDone
public boolean calcDone()- Specified by:
calcDonein interfaceDiskManagerPiece
-
isDone
public boolean isDone()- Specified by:
isDonein interfaceDiskManagerPiece- Returns:
- true when the hash check has passed and the DiskManager has asynchronously 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:
setDonein 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:
setDownloadablein interfaceDiskManagerPiece
-
isDownloadable
public boolean isDownloadable()Description copied from interface:DiskManagerPieceThis must not be used to qualify pieces in End Game Mode.- Specified by:
isDownloadablein interfaceDiskManagerPiece- Returns:
- true if a piece is Needed but is not fully; Requested, Downloaded, Written, Checking, or Done.
-
isInteresting
public boolean isInteresting()- Specified by:
isInterestingin interfaceDiskManagerPiece- Returns:
- true if the piece is Needed and not Done
-
getRemaining
public int getRemaining()- Specified by:
getRemainingin interfaceDiskManagerPiece
-
reset
public void reset()- Specified by:
resetin interfaceDiskManagerPiece
-
reDownloadBlock
public void reDownloadBlock(int blockNumber) - Specified by:
reDownloadBlockin interfaceDiskManagerPiece
-
setMergeRead
public void setMergeRead()- Specified by:
setMergeReadin interfaceDiskManagerPiece
-
isMergeRead
public boolean isMergeRead()- Specified by:
isMergeReadin interfaceDiskManagerPiece
-
setMergeWrite
public void setMergeWrite()- Specified by:
setMergeWritein interfaceDiskManagerPiece
-
isMergeWrite
public boolean isMergeWrite()- Specified by:
isMergeWritein interfaceDiskManagerPiece
-
getString
- Specified by:
getStringin interfaceDiskManagerPiece
-