org.xnap.transfer
Class AbstractTransfer

java.lang.Object
  extended by org.xnap.transfer.AbstractTransfer
All Implemented Interfaces:
Transfer
Direct Known Subclasses:
AbstractDownload, AbstractUpload, AzureusDownload, AzureusPeerDownload, DccDownload, GiFTDownload, JTellaDownload, LimeWireUpload, OpenNapDirectBrowseUpload, OpenNapDownload, OpenNapUpload, OvernetUpload

public abstract class AbstractTransfer
extends java.lang.Object
implements Transfer


Field Summary
protected static org.apache.log4j.Logger logger
           
static int MIN_RECALC_INTERVAL
          Wait 50 milli seconds before calculating rate for the first time.
static int RECALC_INTERVAL
           
static int SOCKET_TIMEOUT
          The recommended default socket timeout.
 
Fields inherited from interface org.xnap.transfer.Transfer
TRANSFER_TIMEOUT
 
Constructor Summary
AbstractTransfer()
           
 
Method Summary
 void addStateListener(StateListener listener)
          Adds a status listener.
 void cleared()
          Does nothing.
 long getAverageRate()
          Returns the average transfer rate.
protected abstract  long getBytesTransferred()
          Returns how many bytes have been transferred since the transfer was started.
 long getCurrentRate()
          Returns the current download rate.
 java.lang.String getDescription()
          Returns null.
 long getElapsedTime()
          Returns the number of milli seconds that have passed since the transfer has been started.
 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.
 int getQueuePosition()
          Returns -1.
 int getRemainingTime()
          Returns the remaining time until the download is finished.
 Segment[] getSegments()
          Returns the segments for segmented downloads.
 void removeStateListener(StateListener listener)
          Remove a state listener.
protected  void stateChanged()
          Notifies all StateListeners that the state has changed.
 java.lang.String toString()
           
protected  void transferStarted()
          Sub classes should invoke this method when the transfer has started.
protected  void transferStopped()
          Sub classes should invoke this method when the transfer has stopped.
 
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
getActions, getFile, getPeer, getPlugin, getStatus, getTotalBytesTransferred, isDone, isRunning
 

Field Detail

RECALC_INTERVAL

public static final int RECALC_INTERVAL
See Also:
Constant Field Values

MIN_RECALC_INTERVAL

public static final int MIN_RECALC_INTERVAL
Wait 50 milli seconds before calculating rate for the first time. Otherwise we will get fantastically high ones.

See Also:
Constant Field Values

SOCKET_TIMEOUT

public static final int SOCKET_TIMEOUT
The recommended default socket timeout.

See Also:
Constant Field Values

logger

protected static org.apache.log4j.Logger logger
Constructor Detail

AbstractTransfer

public AbstractTransfer()
Method Detail

addStateListener

public void addStateListener(StateListener listener)
Description copied from interface: Transfer
Adds a status listener.

Specified by:
addStateListener in interface Transfer

cleared

public void cleared()
Does nothing.

Specified by:
cleared in interface Transfer

getAverageRate

public long getAverageRate()
Returns the average transfer rate.

Specified by:
getAverageRate in interface Transfer
Returns:
byte / s

getBytesTransferred

protected abstract long getBytesTransferred()
Returns how many bytes have been transferred since the transfer was started.

Returns:
number of transferred bytes
See Also:
getCurrentRate()

getCurrentRate

public long getCurrentRate()
Returns the current download rate. Take at least a RECALC_INTERVAL into account to avoid jumping values all the time.

Specified by:
getCurrentRate in interface Transfer
Returns:
byte / s

getDescription

public java.lang.String getDescription()
Returns null.

Specified by:
getDescription in interface Transfer
Returns:
null, if no meta information is available

getElapsedTime

public long getElapsedTime()
Returns the number of milli seconds that have passed since the transfer has been started.


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 Transfer

getFilesize

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

Specified by:
getFilesize in interface Transfer

getIcon

public javax.swing.Icon getIcon()
Returns null.

Specified by:
getIcon in interface Transfer

getQueuePosition

public int getQueuePosition()
Returns -1.

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

getRemainingTime

public int getRemainingTime()
Description copied from interface: Transfer
Returns the remaining time until the download is finished.

Specified by:
getRemainingTime in interface Transfer
Returns:
the remaining time in s or -1 if unknown

removeStateListener

public void removeStateListener(StateListener listener)
Description copied from interface: Transfer
Remove a state listener.

Specified by:
removeStateListener in interface Transfer

stateChanged

protected void stateChanged()
Notifies all StateListeners that the state has changed.


toString

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

getSegments

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

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

transferStarted

protected void transferStarted()
Sub classes should invoke this method when the transfer has started.


transferStopped

protected void transferStopped()
Sub classes should invoke this method when the transfer has stopped.



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