wjhk.jupload2.upload
Class FilePreparationThread

java.lang.Object
  extended by java.lang.Thread
      extended by wjhk.jupload2.upload.FilePreparationThread
All Implemented Interfaces:
Runnable

public class FilePreparationThread
extends Thread

This thread is responsible for preparing all files for upload. It stores each prepared file in the preparedFileQueue, for further processing.

Author:
etienne_sf

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
(package private)  FileData[] fileDataArray
          The array of files to send, from the FilePanel
(package private)  wjhk.jupload2.gui.filepanel.FilePanel filePanel
          The current file list.
(package private)  FileUploadManagerThread fileUploadManagerThread
          The thread which globally manages the upload
(package private)  int nbFilesToSent
          The total of files that must be sent.
(package private)  int nbPreparedFiles
          Number of files that are prepared for upload.
(package private)  long nbTotalNumberOfPreparedBytes
          Sum of the length for all prepared files.
(package private)  JProgressBar preparationProgressBar
          The JUploadPanel progress bar, to follow the file preparation progress.
(package private)  BlockingQueue<UploadFileData> preparedFileQueue
          The queue where each prepared file will be stored, for further processing
(package private)  JUploadPanel uploadPanel
          A shortcut to the upload panel
(package private)  UploadPolicy uploadPolicy
          The current upload policy.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FilePreparationThread(BlockingQueue<UploadFileData> preparedFileQueue, FileUploadManagerThread fileUploadManagerThread, UploadPolicy uploadPolicy)
           
 
Method Summary
 int getNbFilesToSent()
           
 int getNbPreparedFiles()
           
 long getNbTotalNumberOfPreparedBytes()
           
 double getTotalFileBytesToSend()
          Returns the total number of bytes to upload.
 void run()
          The actual command to prepare files.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fileDataArray

FileData[] fileDataArray
The array of files to send, from the FilePanel


nbPreparedFiles

int nbPreparedFiles
Number of files that are prepared for upload. A file is prepared for upload, if the FileData.beforeUpload() has been called.


nbFilesToSent

int nbFilesToSent
The total of files that must be sent. It is initialized by the total number of files in the list, and is decremented each time an error occurs during a file preparation, and the user wants to go on.


nbTotalNumberOfPreparedBytes

long nbTotalNumberOfPreparedBytes
Sum of the length for all prepared files. This allow the calculation of the estimatedTotalLength.

See Also:
anotherFileIsPrepared(UploadFileData)

preparationProgressBar

JProgressBar preparationProgressBar
The JUploadPanel progress bar, to follow the file preparation progress.


uploadPanel

JUploadPanel uploadPanel
A shortcut to the upload panel


uploadPolicy

UploadPolicy uploadPolicy
The current upload policy.


fileUploadManagerThread

FileUploadManagerThread fileUploadManagerThread
The thread which globally manages the upload


filePanel

wjhk.jupload2.gui.filepanel.FilePanel filePanel
The current file list.


preparedFileQueue

BlockingQueue<UploadFileData> preparedFileQueue
The queue where each prepared file will be stored, for further processing

Constructor Detail

FilePreparationThread

public FilePreparationThread(BlockingQueue<UploadFileData> preparedFileQueue,
                             FileUploadManagerThread fileUploadManagerThread,
                             UploadPolicy uploadPolicy)
Parameters:
preparedFileQueue -
fileUploadManagerThread -
uploadPolicy -
Method Detail

run

public final void run()
The actual command to prepare files.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Thread.run(), FileData.beforeUpload()

getTotalFileBytesToSend

public double getTotalFileBytesToSend()
Returns the total number of bytes to upload. This takes into account only the prepared file content. It ignores the possible head and tails of the request (for instance: http headers...). This gives a good idea of the total amount to send, and allows is suffisiant to properly manage the upload progress bar.
The total number of bytes can only be calculated when all files are prepared. When this method is called before this, an estimation is done for non prepared files, based on the average size of the already prepared files.

Returns:
The real or estimated total number of bytes to send

getNbPreparedFiles

public int getNbPreparedFiles()
Returns:
the nbPreparedFiles

getNbFilesToSent

public int getNbFilesToSent()
Returns:
the nbFilesToSent

getNbTotalNumberOfPreparedBytes

public long getNbTotalNumberOfPreparedBytes()
Returns:
the nbTotalNumberOfPreparedBytes