org.xnap.plugin.opennap.net
Class OpenNapDownload

java.lang.Object
  extended by org.xnap.transfer.AbstractTransfer
      extended by org.xnap.plugin.opennap.net.OpenNapDownload
All Implemented Interfaces:
java.util.EventListener, StateListener, ExceptionListener, MessageListener, SocketListener, Download, Transfer

public class OpenNapDownload
extends AbstractTransfer
implements Download, ExceptionListener, MessageListener, SocketListener, StateListener

Downloads a file.


Field Summary
static State AQUIRING_SLOT
          Operation has been aborted.
static int MAX_RESPONSE_LAG
          If no reponse is received within MAX_RESPONSE_LAG milli seconds the peer is considered to be offline and the download is stopped.
static int MAX_WANT_QUEUE
          Do not send //WantQueue more times than this.
static int QUEUED_REQUEST_FACTOR
          Requests are sent in REQUEST_INTERVAL * QUEUED_REQUEST_FACTOR if the download is remotely queued.
static int REQUEST_INTERVAL
          Requests are sent in this interval if this download could not be remotely queued.
static int WAITING_TIMEOUT
          The maximum time to wait for a connect from the other peer in case of a firewalled download.
 
Fields inherited from class org.xnap.transfer.AbstractTransfer
MIN_RECALC_INTERVAL, RECALC_INTERVAL, SOCKET_TIMEOUT
 
Fields inherited from interface org.xnap.transfer.Transfer
TRANSFER_TIMEOUT
 
Constructor Summary
OpenNapDownload(OpenNapDownloadContainer parent, OpenNapSearchResult result)
           
 
Method Summary
 void exceptionThrown(java.lang.Exception e)
           
 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.
 java.io.File getFile()
          Returns the file the transfer is using.
 long getFilesize()
          Returns the final filesize.
 Peer getPeer()
          Returns the peer.
 Plugin getPlugin()
          Returns the plugin.
 int getQueuePosition()
          Returns -1.
 OpenNapSearchResult getResult()
           
 OpenNapSegment getSegment()
           
 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 isDone()
          Returns true if the transfer is finished.
 boolean isQueued()
           
 boolean isRestartable()
           
 boolean isRunning()
          Returns true if the transfer is running.
 void messageReceived(ServerMessage m)
          Handles messages received from the server as response to the download request.
 boolean socketReceived(IncomingSocket s)
          Invoked when an incoming connect is recognized.
 void stateChanged(StateEvent e)
          Invoked when the user download slot state changes.
 
Methods inherited from class org.xnap.transfer.AbstractTransfer
addStateListener, cleared, getAverageRate, getCurrentRate, getDescription, getElapsedTime, getFilename, getIcon, getRemainingTime, removeStateListener, stateChanged, toString, transferStarted, transferStopped
 
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, cleared, getAverageRate, getCurrentRate, getDescription, getFilename, getIcon, getRemainingTime, removeStateListener
 

Field Detail

MAX_WANT_QUEUE

public static final int MAX_WANT_QUEUE
Do not send //WantQueue more times than this. Once should be enough anyway.

See Also:
Constant Field Values

REQUEST_INTERVAL

public static final int REQUEST_INTERVAL
Requests are sent in this interval if this download could not be remotely queued.

See Also:
Constant Field Values

QUEUED_REQUEST_FACTOR

public static final int QUEUED_REQUEST_FACTOR
Requests are sent in REQUEST_INTERVAL * QUEUED_REQUEST_FACTOR if the download is remotely queued.

See Also:
Constant Field Values

MAX_RESPONSE_LAG

public static final int MAX_RESPONSE_LAG
If no reponse is received within MAX_RESPONSE_LAG milli seconds the peer is considered to be offline and the download is stopped.

This should be greater than REQUEST_INTERVAL * QUEUED_REQUEST_FACTOR.

See Also:
Constant Field Values

WAITING_TIMEOUT

public static final int WAITING_TIMEOUT
The maximum time to wait for a connect from the other peer in case of a firewalled download.

See Also:
Constant Field Values

AQUIRING_SLOT

public static final State AQUIRING_SLOT
Operation has been aborted.

Constructor Detail

OpenNapDownload

public OpenNapDownload(OpenNapDownloadContainer parent,
                       OpenNapSearchResult result)
Method Detail

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()

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

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

getFilesize

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

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

getPeer

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

Specified by:
getPeer in interface Transfer

getPlugin

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

Specified by:
getPlugin in interface Transfer

getResult

public OpenNapSearchResult getResult()

getSegment

public OpenNapSegment getSegment()

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

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

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

isRestartable

public boolean isRestartable()

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

isQueued

public boolean isQueued()

socketReceived

public boolean socketReceived(IncomingSocket s)
Description copied from interface: SocketListener
Invoked when an incoming connect is recognized.

Specified by:
socketReceived in interface SocketListener
Returns:
true, if the socket was accepted

getQueuePosition

public int getQueuePosition()
Description copied from class: AbstractTransfer
Returns -1.

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

stateChanged

public void stateChanged(StateEvent e)
Invoked when the user download slot state changes.

Specified by:
stateChanged in interface StateListener

exceptionThrown

public void exceptionThrown(java.lang.Exception e)
Specified by:
exceptionThrown in interface ExceptionListener

messageReceived

public void messageReceived(ServerMessage m)
Handles messages received from the server as response to the download request. Notifies the parent download container if download is ready to start or if it should be removed due to an error message received from the server.

Specified by:
messageReceived in interface MessageListener


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