com.aelitis.azureus.core.lws
Class LWSDiskManager

java.lang.Object
  extended by com.aelitis.azureus.core.lws.LWSDiskManager
All Implemented Interfaces:
DiskManager, DiskManagerHelper

public class LWSDiskManager
extends Object
implements DiskManagerHelper


Nested Class Summary
protected static class LWSDiskManager.sePiece
           
 
Nested classes/interfaces inherited from interface org.gudy.azureus2.core3.disk.DiskManager
DiskManager.GettingThere, DiskManager.OperationStatus
 
Field Summary
 
Fields inherited from interface org.gudy.azureus2.core3.disk.DiskManager
ALLOCATING, BLOCK_SIZE, BLOCK_SIZE_KB, CHECKING, ET_INSUFFICIENT_SPACE, ET_NONE, ET_OTHER, FAULTY, INITIALIZING, READY
 
Constructor Summary
protected LWSDiskManager(LightWeightSeed _lws, File _save_file)
           
 
Method Summary
 void accessModeChanged(DiskManagerFileInfoImpl file, int old_mode, int new_mode)
           
 void addListener(DiskManagerListener l)
           
 boolean checkBlockConsistencyForHint(String originator, int pieceNumber, int offset, int length)
           
 boolean checkBlockConsistencyForRead(String originator, boolean peer_request, int pieceNumber, int offset, int length)
          method for checking that the block details are sensible
 boolean checkBlockConsistencyForWrite(String originator, int pieceNumber, int offset, DirectByteBuffer data)
          method for checking that the block details are sensible
 DiskManagerCheckRequest createCheckRequest(int pieceNumber, Object user_data)
          Create a request to check a particular piece
 DiskManagerReadRequest createReadRequest(int pieceNumber, int offset, int length)
           
 DiskManagerWriteRequest createWriteRequest(int pieceNumber, int offset, DirectByteBuffer data, Object user_data)
           
 void downloadEnded(DiskManager.OperationStatus op_status)
           
 void downloadRemoved()
           
 void enqueueCheckRequest(DiskManagerCheckRequest request, DiskManagerCheckRequestListener listener)
          enqueue an asynchronous single piece check
 void enqueueCompleteRecheckRequest(DiskManagerCheckRequest request, DiskManagerCheckRequestListener listener)
          recheck the entire torrent asynchronously, reporting each piece to the listener
 void enqueueReadRequest(DiskManagerReadRequest request, DiskManagerReadRequestListener listener)
          Enqueue an async disk read request.
 void enqueueWriteRequest(DiskManagerWriteRequest request, DiskManagerWriteRequestListener listener)
          enqueue an async write request
 boolean filesExist()
           
 void generateEvidence(IndentWriter writer)
           
 long getAllocated()
           
 int getCacheMode()
           
protected  DMChecker getChecker()
           
 int getCompleteRecheckStatus()
          returns -1 if no recheck in progress, percentage complete in 1000 notation otherwise
 DiskAccessController getDiskAccessController()
           
 DownloadManagerState getDownloadState()
           
 String getErrorMessage()
           
 int getErrorType()
           
protected  DiskManagerFileInfoImpl[] getFileInfo(DMPieceMapperFile[] pm_files, File save_location)
           
 DiskManagerFileInfo[] getFiles()
           
 DiskManagerFileInfoSet getFileSet()
           
 String getInternalName()
           
 int getLastPieceLength()
           
 int getMoveProgress()
          When a download's data is moving (for completion or removal events) this gives the progress in 1000 notation.
 String getName()
           
 int getNbPieces()
           
 int getPercentDone()
          Get the percentage done during checking, allocation or initializing
 int getPercentDoneExcludingDND()
           
 DiskManagerPiece getPiece(int index)
           
 byte[] getPieceHash(int piece_number)
           
 int getPieceLength()
           
 int getPieceLength(int piece_number)
           
 DMPieceList getPieceList(int piece_number)
           
 DMPieceMap getPieceMap()
          DON'T CACHE the DMPieceMap - as it is designed to be discarded when not in use
 DiskManagerPiece[] getPieces()
           
 long getPriorityChangeMarker()
           
 long[] getReadStats()
           
 DiskManagerRecheckScheduler getRecheckScheduler()
           
 long getRemaining()
          Get remaining bytes to completion *including* DND files
 long getRemainingExcludingDND()
           
 File getSaveLocation()
           
 long getSizeExcludingDND()
           
 int getState()
           
 String getStorageType(int fileIndex)
           
 String[] getStorageTypes()
           
 TOTorrent getTorrent()
           
 long getTotalLength()
           
 boolean hasListener(DiskManagerListener l)
           
 boolean hasOutstandingCheckRequestForPiece(int piece_number)
           
 boolean hasOutstandingReadRequestForPiece(int piece_number)
           
 boolean hasOutstandingWriteRequestForPiece(int piece_number)
           
 boolean isDone(int piece_num)
           
 boolean isInteresting(int piece_num)
           
 boolean isStopped()
           
 void moveDataFiles(File new_parent_dir, String new_name, DiskManager.OperationStatus op_status)
           
 void priorityChanged(DiskManagerFileInfo file)
           
 DirectByteBuffer readBlock(int pieceNumber, int offset, int length)
           
 void removeListener(DiskManagerListener l)
           
 void saveResumeData(boolean interim_save)
           
 void saveState()
          Save the individual file priorities map to DownloadManager.getData( "file_priorities" ).
 void setAllocated(long num)
           
 void setFailed(DiskManagerFileInfo file, String reason)
           
 void setFailed(String reason)
          Stops the disk manager and informs the download manager that things have gone wrong.
 void setPercentDone(int num)
           
 void setPieceCheckingEnabled(boolean enabled)
           
 void setPieceDone(DiskManagerPieceImpl dmPiece, boolean done)
           
 void skippedFileSetChanged(DiskManagerFileInfo file)
           
 void start()
          Start checking/allocating
 boolean stop(boolean closing)
          Stop can go async if the download is in a 'starting' state - if so this method returns true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LWSDiskManager

protected LWSDiskManager(LightWeightSeed _lws,
                         File _save_file)
Method Detail

getName

public String getName()

getCacheMode

public int getCacheMode()
Specified by:
getCacheMode in interface DiskManager

getReadStats

public long[] getReadStats()
Specified by:
getReadStats in interface DiskManager

start

public void start()
Description copied from interface: DiskManager
Start checking/allocating

Specified by:
start in interface DiskManager

getFileInfo

protected DiskManagerFileInfoImpl[] getFileInfo(DMPieceMapperFile[] pm_files,
                                                File save_location)

setPieceDone

public void setPieceDone(DiskManagerPieceImpl dmPiece,
                         boolean done)
Specified by:
setPieceDone in interface DiskManagerHelper

stop

public boolean stop(boolean closing)
Description copied from interface: DiskManager
Stop can go async if the download is in a 'starting' state - if so this method returns true

Specified by:
stop in interface DiskManager
Returns:

isStopped

public boolean isStopped()
Specified by:
isStopped in interface DiskManager

filesExist

public boolean filesExist()
Specified by:
filesExist in interface DiskManager
Returns:
whether all files exist and sizes match

createWriteRequest

public DiskManagerWriteRequest createWriteRequest(int pieceNumber,
                                                  int offset,
                                                  DirectByteBuffer data,
                                                  Object user_data)
Specified by:
createWriteRequest in interface DiskManager

enqueueWriteRequest

public void enqueueWriteRequest(DiskManagerWriteRequest request,
                                DiskManagerWriteRequestListener listener)
Description copied from interface: DiskManager
enqueue an async write request

Specified by:
enqueueWriteRequest in interface DiskManager

hasOutstandingWriteRequestForPiece

public boolean hasOutstandingWriteRequestForPiece(int piece_number)
Specified by:
hasOutstandingWriteRequestForPiece in interface DiskManager

hasOutstandingReadRequestForPiece

public boolean hasOutstandingReadRequestForPiece(int piece_number)
Specified by:
hasOutstandingReadRequestForPiece in interface DiskManager

hasOutstandingCheckRequestForPiece

public boolean hasOutstandingCheckRequestForPiece(int piece_number)
Specified by:
hasOutstandingCheckRequestForPiece in interface DiskManager

readBlock

public DirectByteBuffer readBlock(int pieceNumber,
                                  int offset,
                                  int length)
Specified by:
readBlock in interface DiskManager

createReadRequest

public DiskManagerReadRequest createReadRequest(int pieceNumber,
                                                int offset,
                                                int length)
Specified by:
createReadRequest in interface DiskManager

enqueueReadRequest

public void enqueueReadRequest(DiskManagerReadRequest request,
                               DiskManagerReadRequestListener listener)
Description copied from interface: DiskManager
Enqueue an async disk read request.

Specified by:
enqueueReadRequest in interface DiskManager

createCheckRequest

public DiskManagerCheckRequest createCheckRequest(int pieceNumber,
                                                  Object user_data)
Description copied from interface: DiskManager
Create a request to check a particular piece

Specified by:
createCheckRequest in interface DiskManager
Parameters:
pieceNumber - -1 for a complete recheck request
Returns:

enqueueCheckRequest

public void enqueueCheckRequest(DiskManagerCheckRequest request,
                                DiskManagerCheckRequestListener listener)
Description copied from interface: DiskManager
enqueue an asynchronous single piece check

Specified by:
enqueueCheckRequest in interface DiskManager

enqueueCompleteRecheckRequest

public void enqueueCompleteRecheckRequest(DiskManagerCheckRequest request,
                                          DiskManagerCheckRequestListener listener)
Description copied from interface: DiskManager
recheck the entire torrent asynchronously, reporting each piece to the listener

Specified by:
enqueueCompleteRecheckRequest in interface DiskManager

setPieceCheckingEnabled

public void setPieceCheckingEnabled(boolean enabled)
Specified by:
setPieceCheckingEnabled in interface DiskManager

saveResumeData

public void saveResumeData(boolean interim_save)
Specified by:
saveResumeData in interface DiskManager

getPieces

public DiskManagerPiece[] getPieces()
Specified by:
getPieces in interface DiskManager

getPiece

public DiskManagerPiece getPiece(int index)
Specified by:
getPiece in interface DiskManager

isInteresting

public boolean isInteresting(int piece_num)
Specified by:
isInteresting in interface DiskManager
Returns:
true if the pieceNumber is Needed and not Done

isDone

public boolean isDone(int piece_num)
Specified by:
isDone in interface DiskManager

getNbPieces

public int getNbPieces()
Specified by:
getNbPieces in interface DiskManager

getFiles

public DiskManagerFileInfo[] getFiles()
Specified by:
getFiles in interface DiskManager

getFileSet

public DiskManagerFileInfoSet getFileSet()
Specified by:
getFileSet in interface DiskManager

getState

public int getState()
Specified by:
getState in interface DiskManager

getTotalLength

public long getTotalLength()
Specified by:
getTotalLength in interface DiskManager

getPieceLength

public int getPieceLength()
Specified by:
getPieceLength in interface DiskManager

getPieceLength

public int getPieceLength(int piece_number)
Specified by:
getPieceLength in interface DiskManager

getLastPieceLength

public int getLastPieceLength()

getRemaining

public long getRemaining()
Description copied from interface: DiskManager
Get remaining bytes to completion *including* DND files

Specified by:
getRemaining in interface DiskManager

getRemainingExcludingDND

public long getRemainingExcludingDND()
Specified by:
getRemainingExcludingDND in interface DiskManager

getPercentDone

public int getPercentDone()
Description copied from interface: DiskManager
Get the percentage done during checking, allocation or initializing

Specified by:
getPercentDone in interface DiskManager
Returns:
percent done * 1000 (1000 = 100%)

getPercentDoneExcludingDND

public int getPercentDoneExcludingDND()
Specified by:
getPercentDoneExcludingDND in interface DiskManager

getSizeExcludingDND

public long getSizeExcludingDND()
Specified by:
getSizeExcludingDND in interface DiskManager

getErrorMessage

public String getErrorMessage()
Specified by:
getErrorMessage in interface DiskManager

getErrorType

public int getErrorType()
Specified by:
getErrorType in interface DiskManager

downloadEnded

public void downloadEnded(DiskManager.OperationStatus op_status)
Specified by:
downloadEnded in interface DiskManager

moveDataFiles

public void moveDataFiles(File new_parent_dir,
                          String new_name,
                          DiskManager.OperationStatus op_status)
Specified by:
moveDataFiles in interface DiskManager

getCompleteRecheckStatus

public int getCompleteRecheckStatus()
Description copied from interface: DiskManager
returns -1 if no recheck in progress, percentage complete in 1000 notation otherwise

Specified by:
getCompleteRecheckStatus in interface DiskManager
Returns:

getMoveProgress

public int getMoveProgress()
Description copied from interface: DiskManager
When a download's data is moving (for completion or removal events) this gives the progress in 1000 notation. -1 if nothing's going on

Specified by:
getMoveProgress in interface DiskManager
Returns:

checkBlockConsistencyForWrite

public boolean checkBlockConsistencyForWrite(String originator,
                                             int pieceNumber,
                                             int offset,
                                             DirectByteBuffer data)
Description copied from interface: DiskManager
method for checking that the block details are sensible

Specified by:
checkBlockConsistencyForWrite in interface DiskManager
Returns:

checkBlockConsistencyForRead

public boolean checkBlockConsistencyForRead(String originator,
                                            boolean peer_request,
                                            int pieceNumber,
                                            int offset,
                                            int length)
Description copied from interface: DiskManager
method for checking that the block details are sensible

Specified by:
checkBlockConsistencyForRead in interface DiskManager
Returns:

checkBlockConsistencyForHint

public boolean checkBlockConsistencyForHint(String originator,
                                            int pieceNumber,
                                            int offset,
                                            int length)
Specified by:
checkBlockConsistencyForHint in interface DiskManager

addListener

public void addListener(DiskManagerListener l)
Specified by:
addListener in interface DiskManager

removeListener

public void removeListener(DiskManagerListener l)
Specified by:
removeListener in interface DiskManager

hasListener

public boolean hasListener(DiskManagerListener l)
Specified by:
hasListener in interface DiskManager

saveState

public void saveState()
Description copied from interface: DiskManager
Save the individual file priorities map to DownloadManager.getData( "file_priorities" ).

Specified by:
saveState in interface DiskManager

getDiskAccessController

public DiskAccessController getDiskAccessController()
Specified by:
getDiskAccessController in interface DiskManagerHelper

getPieceMap

public DMPieceMap getPieceMap()
Description copied from interface: DiskManager
DON'T CACHE the DMPieceMap - as it is designed to be discarded when not in use

Specified by:
getPieceMap in interface DiskManager
Returns:

getPieceList

public DMPieceList getPieceList(int piece_number)
Specified by:
getPieceList in interface DiskManager
Specified by:
getPieceList in interface DiskManagerHelper

getChecker

protected DMChecker getChecker()

getPieceHash

public byte[] getPieceHash(int piece_number)
                    throws TOTorrentException
Specified by:
getPieceHash in interface DiskManagerHelper
Throws:
TOTorrentException

getRecheckScheduler

public DiskManagerRecheckScheduler getRecheckScheduler()
Specified by:
getRecheckScheduler in interface DiskManagerHelper

downloadRemoved

public void downloadRemoved()
Specified by:
downloadRemoved in interface DiskManager

setFailed

public void setFailed(String reason)
Description copied from interface: DiskManagerHelper
Stops the disk manager and informs the download manager that things have gone wrong.

Specified by:
setFailed in interface DiskManagerHelper

setFailed

public void setFailed(DiskManagerFileInfo file,
                      String reason)
Specified by:
setFailed in interface DiskManagerHelper

getAllocated

public long getAllocated()
Specified by:
getAllocated in interface DiskManagerHelper

setAllocated

public void setAllocated(long num)
Specified by:
setAllocated in interface DiskManagerHelper

setPercentDone

public void setPercentDone(int num)
Specified by:
setPercentDone in interface DiskManagerHelper

getTorrent

public TOTorrent getTorrent()
Specified by:
getTorrent in interface DiskManager
Specified by:
getTorrent in interface DiskManagerHelper

getStorageTypes

public String[] getStorageTypes()
Specified by:
getStorageTypes in interface DiskManagerHelper

getStorageType

public String getStorageType(int fileIndex)
Specified by:
getStorageType in interface DiskManagerHelper

accessModeChanged

public void accessModeChanged(DiskManagerFileInfoImpl file,
                              int old_mode,
                              int new_mode)
Specified by:
accessModeChanged in interface DiskManagerHelper

skippedFileSetChanged

public void skippedFileSetChanged(DiskManagerFileInfo file)
Specified by:
skippedFileSetChanged in interface DiskManagerHelper

priorityChanged

public void priorityChanged(DiskManagerFileInfo file)
Specified by:
priorityChanged in interface DiskManagerHelper

getSaveLocation

public File getSaveLocation()
Specified by:
getSaveLocation in interface DiskManager

getInternalName

public String getInternalName()
Specified by:
getInternalName in interface DiskManagerHelper

getDownloadState

public DownloadManagerState getDownloadState()
Specified by:
getDownloadState in interface DiskManagerHelper

getPriorityChangeMarker

public long getPriorityChangeMarker()
Specified by:
getPriorityChangeMarker in interface DiskManager

generateEvidence

public void generateEvidence(IndentWriter writer)
Specified by:
generateEvidence in interface DiskManager