de.phleisch.app.itsucks.job.download.impl
Class UrlDownloadJob

java.lang.Object
  extended by de.phleisch.app.itsucks.job.impl.AbstractJob
      extended by de.phleisch.app.itsucks.job.download.impl.UrlDownloadJob
All Implemented Interfaces:
DownloadJob, Job, java.io.Serializable, java.lang.Cloneable

public class UrlDownloadJob
extends AbstractJob
implements DownloadJob, java.lang.Cloneable

This is the implementation of a job for downloading files. It contains a URL to the file or directory to be downloaded.

Author:
olli
See Also:
Serialized Form

Nested Class Summary
protected  class UrlDownloadJob.ProgressListener
           
static class UrlDownloadJob.RetryBehaviour
           
 
Field Summary
static java.lang.String JOB_PROGRESS_PROPERTY
          Constant used to determine when the progress property has changed.
protected  boolean mAbort
           
protected  long mBytesDownloaded
           
protected  DataProcessorManager mDataProcessorManager
           
protected  UrlDataRetriever mDataRetriever
           
protected  DataRetrieverManager mDataRetrieverManager
           
protected  int mDepth
           
protected  ResumeUrlDataRetriever mFileResumeRetriever
           
protected  int mMaxRetryCount
           
protected  Metadata mMetadata
           
protected  java.lang.ref.WeakReference<UrlDownloadJob> mParent
           
protected  float mProgress
           
protected  ProgressInputStream mProgressInputStream
           
protected  UrlDownloadJob.RetryBehaviour mRetryBehaviour
           
protected  java.io.File mSavePath
           
protected  boolean mSaveToDisk
           
protected  int mTryCount
           
protected  boolean mTryResume
           
protected  java.net.URL mUrl
           
protected  long mWaitUntil
           
 
Fields inherited from class de.phleisch.app.itsucks.job.impl.AbstractJob
mGroupContext, mJobManager
 
Fields inherited from interface de.phleisch.app.itsucks.job.Job
JOB_PRIORITY_PROPERTY, JOB_STATE_PROPERTY, MAX_PRIORITY, MIN_PRIORITY, STATE_ALREADY_PROCESSED, STATE_ASSIGNED, STATE_CLOSED, STATE_ERROR, STATE_FAILED, STATE_FINISHED, STATE_IGNORED, STATE_IN_PROGRESS, STATE_IN_PROGRESS_RETRY, STATE_OPEN, STATE_REOPEN
 
Constructor Summary
UrlDownloadJob()
           
 
Method Summary
 void abort()
          Aborts the job when running.
 UrlDownloadJob clone()
           
protected  void download()
           
protected  void executeDownload()
           
protected  void executeProcessorChain()
           
 long getBytesDownloaded()
          Returns the count of bytes which are downloaded
 UrlDataRetriever getDataRetriever()
           
 int getDepth()
          Gets the recursive depth of the job.
 int getMaxRetryCount()
          Returns the maximum count of retries when an retryable error occurs.
 Metadata getMetadata()
          Gets the metadata of the data retriever.
 Job getParent()
          Parent is saved as wek reference to save memory.
 float getProgress()
          Returns the current download progress.
 UrlDownloadJob.RetryBehaviour getRetryBehaviour()
           
 int getRetryCount()
          Returns the actual retry count.
 java.io.File getSavePath()
          Returns the base save path for saving downloaded files.
 java.net.URL getUrl()
          Gets the URL to be downloaded.
 boolean isSaveToDisk()
           
 boolean isTryResume()
           
protected  void prepareResume(DataProcessorChain dataProcessorChain, long resumeOffset)
           
 void run()
          Starts the execution of the job.
 void setDataProcessorManager(DataProcessorManager pDataProcessorManager)
          Sets the data processor manager.
 void setDataRetrieverManager(DataRetrieverManager pDataRetrieverManager)
          Sets the data retriever manager.
 void setDepth(int pDepth)
          Sets the recursive depth of the job.
 void setMaxRetryCount(int pMaxRetryCount)
          Sets the maximum count of retries when an retryable error occurs.
 void setParent(UrlDownloadJob pParent)
          Sets the parent of the job.
 void setRetryBehaviour(UrlDownloadJob.RetryBehaviour pRetryBehaviour)
           
 void setSavePath(java.io.File pSavePath)
          Sets the base save path for saving downloaded files.
 void setSaveToDisk(boolean pSaveToDisk)
          Sets if this file should be saved as file.
 void setTryResume(boolean pTryResume)
          Set if this job should try to resume partial downloaded files.
 void setUrl(java.net.URL pUrl)
          Sets the url to be downloaded.
 java.lang.String toString()
           
protected  void tryResume()
           
 
Methods inherited from class de.phleisch.app.itsucks.job.impl.AbstractJob
addPropertyChangeListener, firePropertyChange, getGroupContext, getId, getJobManager, getName, getParameter, getParameterList, getPriority, getState, hashCode, isClosed, isIgnoreFilter, removePropertyChangeListener, setGroupContext, setId, setIgnoreFilter, setJobManager, setName, setParameter, setPriority, setState
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.phleisch.app.itsucks.job.Job
addPropertyChangeListener, getGroupContext, getId, getJobManager, getName, getParameter, getParameterList, getPriority, getState, isClosed, isIgnoreFilter, removePropertyChangeListener, setGroupContext, setId, setIgnoreFilter, setJobManager, setName, setParameter, setPriority, setState
 

Field Detail

JOB_PROGRESS_PROPERTY

public static final java.lang.String JOB_PROGRESS_PROPERTY
Constant used to determine when the progress property has changed. The old value in the PropertyChangeEvent will be the old progress and the new value will be the new progress.

See Also:
getProgress(), AbstractJob.addPropertyChangeListener(java.beans.PropertyChangeListener), Constant Field Values

mSaveToDisk

protected boolean mSaveToDisk

mTryResume

protected boolean mTryResume

mAbort

protected boolean mAbort

mSavePath

protected java.io.File mSavePath

mUrl

protected java.net.URL mUrl

mParent

protected java.lang.ref.WeakReference<UrlDownloadJob> mParent

mDepth

protected int mDepth

mMaxRetryCount

protected int mMaxRetryCount

mTryCount

protected int mTryCount

mDataProcessorManager

protected transient DataProcessorManager mDataProcessorManager

mDataRetrieverManager

protected transient DataRetrieverManager mDataRetrieverManager

mDataRetriever

protected transient UrlDataRetriever mDataRetriever

mFileResumeRetriever

protected transient ResumeUrlDataRetriever mFileResumeRetriever

mProgressInputStream

protected transient ProgressInputStream mProgressInputStream

mProgress

protected float mProgress

mBytesDownloaded

protected long mBytesDownloaded

mMetadata

protected transient Metadata mMetadata

mRetryBehaviour

protected UrlDownloadJob.RetryBehaviour mRetryBehaviour

mWaitUntil

protected long mWaitUntil
Constructor Detail

UrlDownloadJob

public UrlDownloadJob()
Method Detail

run

public void run()
         throws java.lang.Exception
Description copied from interface: Job
Starts the execution of the job. It returns when the job is finished.

Specified by:
run in interface Job
Specified by:
run in class AbstractJob
Throws:
java.lang.Exception

download

protected void download()
                 throws java.io.IOException
Throws:
java.io.IOException

executeDownload

protected void executeDownload()
                        throws java.io.IOException
Throws:
java.io.IOException

tryResume

protected void tryResume()
                  throws java.io.IOException
Throws:
java.io.IOException

executeProcessorChain

protected void executeProcessorChain()
                              throws java.io.IOException
Throws:
java.io.IOException

prepareResume

protected void prepareResume(DataProcessorChain dataProcessorChain,
                             long resumeOffset)
                      throws java.io.IOException
Throws:
java.io.IOException

abort

public void abort()
Description copied from interface: Job
Aborts the job when running.

Specified by:
abort in interface Job
Specified by:
abort in class AbstractJob

getUrl

public java.net.URL getUrl()
Gets the URL to be downloaded.

Returns:

setUrl

public void setUrl(java.net.URL pUrl)
Sets the url to be downloaded.

Parameters:
pUrl -

setDataRetrieverManager

public void setDataRetrieverManager(DataRetrieverManager pDataRetrieverManager)
Sets the data retriever manager.

Parameters:
pDataRetrieverManager -

setDataProcessorManager

public void setDataProcessorManager(DataProcessorManager pDataProcessorManager)
Sets the data processor manager.

Parameters:
pDataProcessorManager -

getDepth

public int getDepth()
Description copied from interface: DownloadJob
Gets the recursive depth of the job.

Specified by:
getDepth in interface DownloadJob
Returns:

setDepth

public void setDepth(int pDepth)
Sets the recursive depth of the job.

Parameters:
pDepth -

getParent

public Job getParent()
Parent is saved as wek reference to save memory. Therefore this reference do not count.

Returns:
the parent of the job, null if none.

setParent

public void setParent(UrlDownloadJob pParent)
Sets the parent of the job. This method also copies the configuration from the parent to this instance.

Parameters:
pParent -

isSaveToDisk

public boolean isSaveToDisk()
Specified by:
isSaveToDisk in interface DownloadJob
Returns:
true if this file should be saved as file.

setSaveToDisk

public void setSaveToDisk(boolean pSaveToDisk)
Sets if this file should be saved as file.

Parameters:
pSaveToFile -

getSavePath

public java.io.File getSavePath()
Description copied from interface: DownloadJob
Returns the base save path for saving downloaded files.

Specified by:
getSavePath in interface DownloadJob
Returns:

setSavePath

public void setSavePath(java.io.File pSavePath)
Sets the base save path for saving downloaded files.

Parameters:
pSavePath -

isTryResume

public boolean isTryResume()

setTryResume

public void setTryResume(boolean pTryResume)
Set if this job should try to resume partial downloaded files. Default is true.

Parameters:
pTryResume -

getDataRetriever

public UrlDataRetriever getDataRetriever()
Specified by:
getDataRetriever in interface DownloadJob
Returns:
the data retriever used to download from the url.

getProgress

public float getProgress()
Description copied from interface: DownloadJob
Returns the current download progress.

Specified by:
getProgress in interface DownloadJob
Returns:

getMaxRetryCount

public int getMaxRetryCount()
Description copied from interface: DownloadJob
Returns the maximum count of retries when an retryable error occurs.

Specified by:
getMaxRetryCount in interface DownloadJob
Returns:

setMaxRetryCount

public void setMaxRetryCount(int pMaxRetryCount)
Sets the maximum count of retries when an retryable error occurs.

Parameters:
pMaxRetryCount -

getRetryCount

public int getRetryCount()
Description copied from interface: DownloadJob
Returns the actual retry count.

Specified by:
getRetryCount in interface DownloadJob
Returns:

getRetryBehaviour

public UrlDownloadJob.RetryBehaviour getRetryBehaviour()

setRetryBehaviour

public void setRetryBehaviour(UrlDownloadJob.RetryBehaviour pRetryBehaviour)

getBytesDownloaded

public long getBytesDownloaded()
Description copied from interface: DownloadJob
Returns the count of bytes which are downloaded

Specified by:
getBytesDownloaded in interface DownloadJob
Returns:

getMetadata

public Metadata getMetadata()
Description copied from interface: DownloadJob
Gets the metadata of the data retriever.

Specified by:
getMetadata in interface DownloadJob
Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

public UrlDownloadJob clone()
Overrides:
clone in class java.lang.Object


Copyright © 2010. All Rights Reserved.