org.xnap.plugin.opennap.net
Class OpenNapDownloadContainer

java.lang.Object
  extended by org.xnap.transfer.AbstractTransfer
      extended by org.xnap.transfer.AbstractDownload
          extended by org.xnap.plugin.opennap.net.OpenNapDownloadContainer
All Implemented Interfaces:
SearchHandler, Download, Queueable, Transfer, TransferContainer

public class OpenNapDownloadContainer
extends AbstractDownload
implements Queueable, SearchHandler


Field Summary
static int INITIAL_SEARCH_INTERVAL
          The initial auto search interval.
static int MAX_SEARCH_COUNT
          Maximum number of auto searches.
static int MAX_SEARCH_INTERVAL
          The upper bound for the search interval.
 
Fields inherited from class org.xnap.transfer.AbstractTransfer
logger, MIN_RECALC_INTERVAL, RECALC_INTERVAL, SOCKET_TIMEOUT
 
Fields inherited from interface org.xnap.transfer.Transfer
TRANSFER_TIMEOUT
 
Constructor Summary
OpenNapDownloadContainer(OpenNapDownloadContainerData data)
          Invoked by OpenNapResumeRepository when restoring download from resume data.
OpenNapDownloadContainer(OpenNapSearchResult[] results)
           
 
Method Summary
 boolean add(OpenNapSearchResult result, boolean matchFilter)
          Creates a new download for result and adds it as a child.
 void cleared()
          Notifies the OpenNapTransferManager that the download was removed.
 javax.swing.Action[] getActions()
          Returns the actions that can performed by the transfer.
 long getBytesTransferred()
          Returns how many bytes have been transferred since the transfer was started.
 long getEnqueueTime()
          Returns the time when the queueable was enqueued in milli seconds.
 java.io.File getFile()
          Returns the file the transfer is using.
 java.lang.String getFilename()
          Returns the filename that should be presented to the user.
 long getFilesize()
          Returns the final filesize.
 javax.swing.Icon getIcon()
          Returns null.
 Peer getPeer()
          Returns the peer.
 Plugin getPlugin()
          Returns the plugin.
 int getPriority()
          Returns 1.
 int getQueuePosition()
          Returns the position in the DownloadManager queue.
 SearchFilter getSearchFilter()
           
 Segment[] getSegments()
          Returns the segments for segmented downloads.
 java.lang.String getStatus()
          Returns the current status that should be presented to the user.
 long getTotalBytesTransferred()
          Returns how many bytes have been transferred.
 boolean isAutoSearchingEnabled()
           
 boolean isDone()
          Returns true if the transfer is finished.
 boolean isRunning()
          Returns true if the transfer is running.
 void resultReceived(SearchResult result)
          Invoked when result is received.
 void setAutoSearchingEnabled(boolean autoSearchingEnabled)
           
 void setFilename(java.lang.String filename)
           
 void setQueuePosition(int position)
          Invoked by the queue to update the position.
 void setSearchFilter(SearchFilter filter)
           
 boolean startTransfer()
          Invoked when the user manually starts the download or if it reaches to the top of the queue.
 void stateChanged(Search search)
          Invoked when the state of search changes.
 void stop()
           
protected  void transferStarted()
          Invoked by OpenNapDownload children when DOWNLOADING state is entered.
protected  void transferStopped()
          Invoked by OpenNapDownload children when DOWNLOADING state is left.
 
Methods inherited from class org.xnap.transfer.AbstractDownload
add, addListListener, clearDone, getChildCount, getChildren, iterator, remove, removeListListener
 
Methods inherited from class org.xnap.transfer.AbstractTransfer
addStateListener, getAverageRate, getCurrentRate, getDescription, getElapsedTime, getRemainingTime, removeStateListener, stateChanged, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xnap.transfer.Transfer
addStateListener, getAverageRate, getCurrentRate, getDescription, getRemainingTime, removeStateListener
 

Field Detail

INITIAL_SEARCH_INTERVAL

public static final int INITIAL_SEARCH_INTERVAL
The initial auto search interval. The interval is doubled with each search.

See Also:
Constant Field Values

MAX_SEARCH_INTERVAL

public static final int MAX_SEARCH_INTERVAL
The upper bound for the search interval.

See Also:
Constant Field Values

MAX_SEARCH_COUNT

public static final int MAX_SEARCH_COUNT
Maximum number of auto searches.

See Also:
Constant Field Values
Constructor Detail

OpenNapDownloadContainer

public OpenNapDownloadContainer(OpenNapSearchResult[] results)

OpenNapDownloadContainer

public OpenNapDownloadContainer(OpenNapDownloadContainerData data)
Invoked by OpenNapResumeRepository when restoring download from resume data.

Method Detail

add

public boolean add(OpenNapSearchResult result,
                   boolean matchFilter)
Creates a new download for result and adds it as a child. If a download for result is already existing, starts it if not running.

Returns:
true, if download for result was added or already existing; false, otherwise

cleared

public void cleared()
Notifies the OpenNapTransferManager that the download was removed. Invoked by DownloadManager when the download is done and clear finished is executed by user.

Specified by:
cleared in interface Transfer
Overrides:
cleared in class AbstractTransfer

getEnqueueTime

public long getEnqueueTime()
Description copied from interface: Queueable
Returns the time when the queueable was enqueued in milli seconds.

Specified by:
getEnqueueTime in interface Queueable

getFilename

public java.lang.String getFilename()
Description copied from interface: Transfer
Returns the filename that should be presented to the user.

Specified by:
getFilename in interface Queueable
Specified by:
getFilename in interface Transfer
Overrides:
getFilename in class AbstractTransfer
See Also:
Transfer.getFilename()

getFilesize

public long getFilesize()
Description copied from interface: Transfer
Returns the final filesize.

Specified by:
getFilesize in interface Queueable
Specified by:
getFilesize in interface Transfer
Overrides:
getFilesize in class AbstractTransfer
See Also:
Transfer.getFilesize()

getPlugin

public Plugin getPlugin()
Description copied from interface: Transfer
Returns the plugin.

Specified by:
getPlugin in interface Transfer

getActions

public javax.swing.Action[] getActions()
Description copied from interface: Transfer
Returns the actions that can performed by the transfer.

Specified by:
getActions in interface Transfer
See Also:
xnap.transfer.Transfer#getActions()

getBytesTransferred

public long getBytesTransferred()
Description copied from class: AbstractTransfer
Returns how many bytes have been transferred since the transfer was started.

Specified by:
getBytesTransferred in class AbstractTransfer
Returns:
number of transferred bytes
See Also:
AbstractTransfer.getCurrentRate()

getFile

public java.io.File getFile()
Description copied from interface: Transfer
Returns the file the transfer is using.

Specified by:
getFile in interface Transfer
Returns:
null, if file is unknown; the file, otherwise
See Also:
xnap.transfer.Transfer#getFile()

getIcon

public javax.swing.Icon getIcon()
Description copied from class: AbstractTransfer
Returns null.

Specified by:
getIcon in interface Transfer
Overrides:
getIcon in class AbstractTransfer

getPriority

public int getPriority()
Returns 1.

Specified by:
getPriority in interface Queueable

getQueuePosition

public int getQueuePosition()
Returns the position in the DownloadManager queue.

Specified by:
getQueuePosition in interface Queueable
Specified by:
getQueuePosition in interface Transfer
Overrides:
getQueuePosition in class AbstractTransfer
Returns:
-1, if the transfer is not queued, the position otherwise.

getPeer

public Peer getPeer()
Description copied from interface: Transfer
Returns the peer.

Specified by:
getPeer in interface Queueable
Specified by:
getPeer in interface Transfer
See Also:
xnap.transfer.Transfer#getPeer()

getSearchFilter

public SearchFilter getSearchFilter()
Returns:
a copy of the filter used for searching; null, if no search filter has been set, yet (i.e. download was started from browse)

getSegments

public Segment[] getSegments()
Description copied from interface: Transfer
Returns the segments for segmented downloads.

Specified by:
getSegments in interface Transfer
Overrides:
getSegments in class AbstractTransfer
Returns:
null, if segments are not supported (which means that there is only one segment that represents the whole file)

getStatus

public java.lang.String getStatus()
Description copied from interface: Transfer
Returns the current status that should be presented to the user.

Specified by:
getStatus in interface Transfer
See Also:
xnap.transfer.Transfer#getStatus()

getTotalBytesTransferred

public long getTotalBytesTransferred()
Description copied from interface: Transfer
Returns how many bytes have been transferred.

Specified by:
getTotalBytesTransferred in interface Transfer
Returns:
number of transferred bytes
See Also:
xnap.transfer.Transfer#getTotalBytesTransferred()

isAutoSearchingEnabled

public boolean isAutoSearchingEnabled()

isDone

public boolean isDone()
Description copied from interface: Transfer
Returns true if the transfer is finished.

Specified by:
isDone in interface Transfer
Returns:
true, if thread has ended and the transfer can be cleared; false if, not yet started or still running

isRunning

public boolean isRunning()
Description copied from interface: Transfer
Returns true if the transfer is running.

Specified by:
isRunning in interface Transfer
Returns:
true, if data is transferred or a connect is in progress; false, if queued, not yet started or done

resultReceived

public void resultReceived(SearchResult result)
Description copied from interface: SearchHandler
Invoked when result is received.

Specified by:
resultReceived in interface SearchHandler

setAutoSearchingEnabled

public void setAutoSearchingEnabled(boolean autoSearchingEnabled)

setFilename

public void setFilename(java.lang.String filename)

setSearchFilter

public void setSearchFilter(SearchFilter filter)
Parameters:
filter - the search filter

stateChanged

public void stateChanged(Search search)
Invoked when the state of search changes.

Specified by:
stateChanged in interface SearchHandler

setQueuePosition

public void setQueuePosition(int position)
Description copied from interface: Queueable
Invoked by the queue to update the position.

Specified by:
setQueuePosition in interface Queueable
Parameters:
position - if 0, the item has been dequeued from the queue and startQueued() has been called.

startTransfer

public boolean startTransfer()
Invoked when the user manually starts the download or if it reaches to the top of the queue.

Specified by:
startTransfer in interface Queueable
Returns:
true, if item has accepted the running state and should be dequeued; false, if item wants to remain queued

stop

public void stop()

transferStarted

protected void transferStarted()
Invoked by OpenNapDownload children when DOWNLOADING state is entered.

Overrides:
transferStarted in class AbstractTransfer

transferStopped

protected void transferStopped()
Invoked by OpenNapDownload children when DOWNLOADING state is left.

Overrides:
transferStopped in class AbstractTransfer


Copyright © 2001-2005 XNap Team. All Rights Reserved.