LimeWire Consolidated API

com.limegroup.gnutella.uploader
Class AbstractUploader

java.lang.Object
  extended by com.limegroup.gnutella.uploader.AbstractUploader
All Implemented Interfaces:
BandwidthTracker, Uploader, Address, Connectable, IpPort
Direct Known Subclasses:
HTTPUploader

public abstract class AbstractUploader
extends Object
implements Uploader

Provides an implementation of the Uploader interface.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.limegroup.gnutella.Uploader
Uploader.UploadStatus
 
Nested classes/interfaces inherited from interface org.limewire.io.IpPort
IpPort.IpComparator, IpPort.IpPortComparator
 
Nested classes/interfaces inherited from interface org.limewire.io.Address
Address.EventType
 
Field Summary
 
Fields inherited from interface com.limegroup.gnutella.Uploader
BITTORRENT_UPLOAD
 
Fields inherited from interface org.limewire.io.Connectable
COMPARATOR, EMPTY_LIST, EMPTY_SET
 
Fields inherited from interface org.limewire.io.IpPort
IP_COMPARATOR
 
Constructor Summary
AbstractUploader(String fileName, HTTPUploadSession session, TcpBandwidthStatistics tcpBandwidthStatistics)
           
 
Method Summary
 void addAmountUploaded(int written)
          Increases the amount of uploaded bytes.
 long amountUploaded()
          Returns the amount that of data that has been uploaded.
 String getAddress()
          Returns the address of the host that initiated this upload.
 String getAddressDescription()
           
 float getAverageBandwidth()
          Returns the overall averaged bandwidth between all calls of measureBandwidth.
 String getCustomIconDescriptor()
           
 FileDesc getFileDesc()
          Returns the FileDesc of the file being uploaded.
 String getFileName()
          returns the name of the file being uploaded.
 long getFileSize()
          returns the length of the file being uploaded.
 int getGnutellaPort()
          return the port of the gnutella-client host (not the HTTP port)
 String getHost()
          returns the string representation of the IP Address of the host being uploaded to.
 boolean getIgnoreTotalAmountUploaded()
          Returns true, if the amount uploaded in previous sessions is not returned by getTotalAmountUploaded().
 int getIndex()
          returns the index of the file being uploaded.
 InetAddress getInetAddress()
          Returns the address of the host that initiated this session.
 InetSocketAddress getInetSocketAddress()
          Returns a combination of getInetAddress and getPort.
 Uploader.UploadStatus getLastTransferState()
          Returns the last transfer state of this uploader.
 float getMeasuredBandwidth()
          Returns the throughput of this in kilobytes/sec (KB/s) between the last two calls to measureBandwidth, or 0.0 if unknown.
 int getPort()
          Returns the Gnutella Port, if one was provided.
 int getQueuePosition()
          Returns the queued position if queued.
 HTTPUploadSession getSession()
          Returns the upload session that is associated with the connection.
 Uploader.UploadStatus getState()
          Returns the current state of this uploader.
 long getTotalAmountUploaded()
          Returns the amount of data that this uploader and all previous uploaders exchanging this file have uploaded.
 UploadType getUploadType()
          Returns the kind of upload this is (shared file, browse host, malformed request, etc..)
 String getUserAgent()
          return the userAgent
 boolean isBrowseHostEnabled()
          returns true if browse host is enabled, false if it is not.
protected  boolean isFirstReply()
          Returns true, if this is this uploader represents the first request.
 boolean isForcedShare()
           
 boolean isInactive()
          Returns whether or not this upload is in what is considered an "inactive" state, such as completed or aborted.
 boolean isPriorityShare()
           
 boolean isTLSCapable()
          Returns true if the socket this is on is currently using TLS.
 void measureBandwidth()
          Measures the data throughput since the last call to measureBandwidth.
 void reinitialize()
          Reinitializes this uploader for a new request.
 void setBrowseHostEnabled(boolean browseHostEnabled)
          Sets the flag returned by isBrowseHostEnabled().
 void setFileDesc(FileDesc fd)
          Sets the file that is being uploaded.
 void setFileSize(long fileSize)
          Returns the file size returned by getFileSize().
 void setGnutellaPort(int port)
          Sets the port returned by getGnutellaPort().
 void setHost(String host)
           
 void setIgnoreTotalAmountUploaded(boolean ignoreTotalAmountUploaded)
          If set to true, the amount uploaded in previous sessions is not returned by getTotalAmountUploaded().
 void setState(Uploader.UploadStatus state)
           
 void setTotalAmountUploadedBefore(int totalAmountReadBefore)
          Sets the amount uploaded in previous sessions.
 void setUploadType(UploadType type)
          Sets the type returned by getUploadType().
 void setUserAgent(String userAgent)
          Sets the user agent returned by getUserAgent().
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.limegroup.gnutella.Uploader
getFile, getNumUploadConnections, getUrn, stop
 
Methods inherited from interface org.limewire.io.Address
equals, hashCode
 

Constructor Detail

AbstractUploader

public AbstractUploader(String fileName,
                        HTTPUploadSession session,
                        TcpBandwidthStatistics tcpBandwidthStatistics)
Method Detail

reinitialize

public void reinitialize()
Reinitializes this uploader for a new request.


setFileDesc

public void setFileDesc(FileDesc fd)
Sets the file that is being uploaded.

Parameters:
fd - the file being uploaded
Throws:
IOException - if the file cannot be read from the disk.

setState

public void setState(Uploader.UploadStatus state)

getQueuePosition

public int getQueuePosition()
Returns the queued position if queued.

Specified by:
getQueuePosition in interface Uploader

addAmountUploaded

public void addAmountUploaded(int written)
Increases the amount of uploaded bytes.

Parameters:
written - number of bytes transferred

isInactive

public boolean isInactive()
Returns whether or not this upload is in what is considered an "inactive" state, such as completed or aborted.

Specified by:
isInactive in interface Uploader
Returns:
true if this upload is in an inactive state, false otherwise

getFileSize

public long getFileSize()
Description copied from interface: Uploader
returns the length of the file being uploaded.

Specified by:
getFileSize in interface Uploader

getIndex

public int getIndex()
Description copied from interface: Uploader
returns the index of the file being uploaded.

Specified by:
getIndex in interface Uploader

getFileName

public String getFileName()
Description copied from interface: Uploader
returns the name of the file being uploaded.

Specified by:
getFileName in interface Uploader

getState

public Uploader.UploadStatus getState()
Description copied from interface: Uploader
Returns the current state of this uploader.

Specified by:
getState in interface Uploader

getLastTransferState

public Uploader.UploadStatus getLastTransferState()
Description copied from interface: Uploader
Returns the last transfer state of this uploader. Transfers states are all states except INTERRUPTED, COMPLETE, and CONNECTING.

Specified by:
getLastTransferState in interface Uploader

getHost

public String getHost()
Description copied from interface: Uploader
returns the string representation of the IP Address of the host being uploaded to.

Specified by:
getHost in interface Uploader

isBrowseHostEnabled

public boolean isBrowseHostEnabled()
Description copied from interface: Uploader
returns true if browse host is enabled, false if it is not.

Specified by:
isBrowseHostEnabled in interface Uploader

getGnutellaPort

public int getGnutellaPort()
Description copied from interface: Uploader
return the port of the gnutella-client host (not the HTTP port)

Specified by:
getGnutellaPort in interface Uploader

getUserAgent

public String getUserAgent()
Description copied from interface: Uploader
return the userAgent

Specified by:
getUserAgent in interface Uploader

isForcedShare

public boolean isForcedShare()

isPriorityShare

public boolean isPriorityShare()

isFirstReply

protected boolean isFirstReply()
Returns true, if this is this uploader represents the first request.


amountUploaded

public long amountUploaded()
Description copied from interface: Uploader
Returns the amount that of data that has been uploaded. For HTTP/1.1 transfers, this number is the amount uploaded for this specific chunk only. Uses Uploader.getTotalAmountUploaded() for the entire amount uploaded.

Note: This method was previously called "amountRead", but the name was changed to make more sense.

Specified by:
amountUploaded in interface Uploader

getTotalAmountUploaded

public long getTotalAmountUploaded()
Description copied from interface: Uploader
Returns the amount of data that this uploader and all previous uploaders exchanging this file have uploaded.

Specified by:
getTotalAmountUploaded in interface Uploader

getFileDesc

public FileDesc getFileDesc()
Description copied from interface: Uploader
Returns the FileDesc of the file being uploaded.

Specified by:
getFileDesc in interface Uploader
Returns:
null if the file can not be found

measureBandwidth

public void measureBandwidth()
Description copied from interface: BandwidthTracker
Measures the data throughput since the last call to measureBandwidth. This value can be read by calling getMeasuredBandwidth.

Specified by:
measureBandwidth in interface BandwidthTracker

getMeasuredBandwidth

public float getMeasuredBandwidth()
                           throws InsufficientDataException
Description copied from interface: BandwidthTracker
Returns the throughput of this in kilobytes/sec (KB/s) between the last two calls to measureBandwidth, or 0.0 if unknown.

Specified by:
getMeasuredBandwidth in interface BandwidthTracker
Throws:
InsufficientDataException

getAverageBandwidth

public float getAverageBandwidth()
Description copied from interface: BandwidthTracker
Returns the overall averaged bandwidth between all calls of measureBandwidth.

Specified by:
getAverageBandwidth in interface BandwidthTracker

getCustomIconDescriptor

public String getCustomIconDescriptor()
Specified by:
getCustomIconDescriptor in interface Uploader
Returns:
a custom icon descriptor, null if the file icon should be used.

getUploadType

public UploadType getUploadType()
Description copied from interface: Uploader
Returns the kind of upload this is (shared file, browse host, malformed request, etc..)

Specified by:
getUploadType in interface Uploader

setUploadType

public void setUploadType(UploadType type)
Sets the type returned by getUploadType().


setBrowseHostEnabled

public void setBrowseHostEnabled(boolean browseHostEnabled)
Sets the flag returned by isBrowseHostEnabled().


setGnutellaPort

public void setGnutellaPort(int port)
Sets the port returned by getGnutellaPort().


setTotalAmountUploadedBefore

public void setTotalAmountUploadedBefore(int totalAmountReadBefore)
Sets the amount uploaded in previous sessions. If totalAmountReadBefore is != 0, getTotalAmountUploaded() will use that value to calculate the total amount uploaded instead of relying on the value maintained by this uploader.


setUserAgent

public void setUserAgent(String userAgent)
Sets the user agent returned by getUserAgent().


toString

public String toString()
Overrides:
toString in class Object

getSession

public HTTPUploadSession getSession()
Returns the upload session that is associated with the connection.


setFileSize

public void setFileSize(long fileSize)
Returns the file size returned by getFileSize().

Parameters:
fileSize - must be greater than 0

getIgnoreTotalAmountUploaded

public boolean getIgnoreTotalAmountUploaded()
Returns true, if the amount uploaded in previous sessions is not returned by getTotalAmountUploaded().

See Also:
setIgnoreTotalAmountUploaded(boolean)

setIgnoreTotalAmountUploaded

public void setIgnoreTotalAmountUploaded(boolean ignoreTotalAmountUploaded)
If set to true, the amount uploaded in previous sessions is not returned by getTotalAmountUploaded().

Note: This is reset to false by reinitialize().

See Also:
getIgnoreTotalAmountUploaded()

setHost

public void setHost(String host)

isTLSCapable

public boolean isTLSCapable()
Returns true if the socket this is on is currently using TLS.

Specified by:
isTLSCapable in interface Connectable

getAddress

public String getAddress()
Returns the address of the host that initiated this upload.

Specified by:
getAddress in interface IpPort
Returns:
the address of this host as a string

getInetAddress

public InetAddress getInetAddress()
Returns the address of the host that initiated this session.

Specified by:
getInetAddress in interface IpPort
Returns:
the InetAddress for this host

getInetSocketAddress

public InetSocketAddress getInetSocketAddress()
Returns a combination of getInetAddress and getPort.

Specified by:
getInetSocketAddress in interface IpPort
Returns:
the InetSocketAddress of this host.

getAddressDescription

public String getAddressDescription()
Specified by:
getAddressDescription in interface Address

getPort

public int getPort()
Returns the Gnutella Port, if one was provided. Otherwise, the remote port from the socket.

Specified by:
getPort in interface IpPort
Returns:
the port this host is listening on

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.