com.aelitis.azureus.plugins.extseed
Class ExternalSeedPeer

java.lang.Object
  extended by com.aelitis.azureus.plugins.extseed.ExternalSeedPeer
All Implemented Interfaces:
ExternalSeedReaderListener, Peer

public class ExternalSeedPeer
extends Object
implements Peer, ExternalSeedReaderListener


Field Summary
 
Fields inherited from interface org.gudy.azureus2.plugins.peers.Peer
CLOSING, CONNECTING, DISCONNECTED, HANDSHAKING, PR_PRIORITY_CONNECTION, PR_PROTOCOL, PR_PROTOCOL_QUALIFIER, TRANSFERING
 
Constructor Summary
protected ExternalSeedPeer(ExternalSeedPlugin _plugin, Download _download, ExternalSeedReader _reader)
           
 
Method Summary
 void addListener(PeerListener listener)
          Add peer listener.
 void addListener(PeerListener2 listener)
          Add peer listener.
protected  void addPeer()
           
 void addRateLimiter(RateLimiter limiter, boolean is_upload)
           
 boolean addRequest(PeerReadRequest request)
           
 void bindConnection(ConnectionStub stub)
           
 void cancelRequest(PeerReadRequest request)
           
protected  boolean checkConnection()
           
 void close(String reason, boolean closedOnError, boolean attemptReconnect)
           
protected  void fireEvent(int type, Object data)
           
 boolean[] getAvailable()
           
 String getClient()
           
 Connection getConnection()
          Get the network connection that backs this peer.
protected  Download getDownload()
           
 List getExpiredRequests()
           
 byte[] getHandshakeReservedBytes()
           
 byte[] getId()
           
 String getIp()
          Get the peer's local TCP connection port.
 PeerManager getManager()
           
 int getMaximumNumberOfRequests()
           
 String getName()
           
 int getNumberOfRequests()
           
 int getOutgoingRequestCount()
           
 int[] getOutgoingRequestedPieceNumbers()
           
 int getPercentDone()
           
 int getPercentDoneInThousandNotation()
           
 int getPercentDoneOfCurrentIncomingRequest()
           
 int getPercentDoneOfCurrentOutgoingRequest()
           
 int getPort()
           
 int[] getPriorityOffsets()
           
 Map getProperties()
           
 RateLimiter[] getRateLimiters(boolean is_upload)
           
protected  ExternalSeedReader getReader()
           
 List<PeerReadRequest> getRequests()
           
 long getSnubbedTime()
           
 int getState()
           
 PeerStats getStats()
           
 Message[] getSupportedMessages()
          Get the list of messages that this peer and us mutually understand.
 int getTCPListenPort()
          Get the TCP port this peer is listening for incoming connections on.
 int getUDPListenPort()
          Get the UDP port this peer is listening for incoming connections on.
 int getUDPNonDataListenPort()
          Get the UDP port this peer is listening on for non-data connections
 URL getURL()
           
 Object getUserData(Object key)
           
 boolean isChoked()
           
 boolean isChoking()
           
 boolean isDownloadPossible()
          This is much list isTransferAvailable(), except is more comprehensive.
 boolean isIncoming()
           
 boolean isInterested()
           
 boolean isInteresting()
           
 boolean isOptimisticUnchoke()
           
 boolean isPieceAvailable(int pieceNumber)
           
 boolean isPriorityConnection()
           
 boolean isSeed()
           
 boolean isSnubbed()
           
 boolean isTransferAvailable()
           
 int readBytes(int max)
          Rate control - gives the maximum number of bytes that can be read from this connection at this time and returns the actual number read
 void remove()
           
 void removeListener(PeerListener listener)
          Remove peer listener.
 void removeListener(PeerListener2 listener)
          Remove peer listener.
protected  void removePeer()
           
 void removeRateLimiter(RateLimiter limiter, boolean is_upload)
           
 void requestAllocationComplete()
           
 boolean requestAllocationStarts(int[] base_priorities)
           
 void requestCancelled(PeerReadRequest request)
           
 void requestComplete(PeerReadRequest request, PooledByteBuffer data)
           
 void requestFailed(PeerReadRequest request)
           
protected  boolean sameAs(ExternalSeedPeer other)
           
protected  void setManager(PeerManager _manager)
           
 void setOptimisticUnchoke(boolean _is_optimistic)
           
 void setPriorityConnection(boolean is_priority)
           
 void setSnubbed(boolean b)
           
protected  void setState(int newState)
           
 void setUserData(Object key, Object value)
           
 boolean supportsMessaging()
          Whether or not this peer supports the advanced messaging API.
 int writeBytes(int max)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExternalSeedPeer

protected ExternalSeedPeer(ExternalSeedPlugin _plugin,
                           Download _download,
                           ExternalSeedReader _reader)
Method Detail

sameAs

protected boolean sameAs(ExternalSeedPeer other)

setManager

protected void setManager(PeerManager _manager)

getManager

public PeerManager getManager()
Specified by:
getManager in interface Peer

getDownload

protected Download getDownload()

bindConnection

public void bindConnection(ConnectionStub stub)
Specified by:
bindConnection in interface Peer

getReader

protected ExternalSeedReader getReader()

setState

protected void setState(int newState)

checkConnection

protected boolean checkConnection()

addPeer

protected void addPeer()

removePeer

protected void removePeer()

requestComplete

public void requestComplete(PeerReadRequest request,
                            PooledByteBuffer data)
Specified by:
requestComplete in interface ExternalSeedReaderListener

requestCancelled

public void requestCancelled(PeerReadRequest request)
Specified by:
requestCancelled in interface ExternalSeedReaderListener

requestFailed

public void requestFailed(PeerReadRequest request)
Specified by:
requestFailed in interface ExternalSeedReaderListener

getState

public int getState()
Specified by:
getState in interface Peer

getId

public byte[] getId()
Specified by:
getId in interface Peer

getURL

public URL getURL()

getIp

public String getIp()
Description copied from interface: Peer
Get the peer's local TCP connection port.

Specified by:
getIp in interface Peer
Returns:
local port

getTCPListenPort

public int getTCPListenPort()
Description copied from interface: Peer
Get the TCP port this peer is listening for incoming connections on.

Specified by:
getTCPListenPort in interface Peer
Returns:
TCP port, or 0 if port is unknown

getUDPListenPort

public int getUDPListenPort()
Description copied from interface: Peer
Get the UDP port this peer is listening for incoming connections on.

Specified by:
getUDPListenPort in interface Peer
Returns:
UDP port, or 0 if port is unknown

getUDPNonDataListenPort

public int getUDPNonDataListenPort()
Description copied from interface: Peer
Get the UDP port this peer is listening on for non-data connections

Specified by:
getUDPNonDataListenPort in interface Peer
Returns:

getPort

public int getPort()
Specified by:
getPort in interface Peer

getAvailable

public final boolean[] getAvailable()
Specified by:
getAvailable in interface Peer

isPieceAvailable

public final boolean isPieceAvailable(int pieceNumber)
Specified by:
isPieceAvailable in interface Peer
Parameters:
pieceNumber - int
Returns:
true if this peers makes this piece available

isTransferAvailable

public boolean isTransferAvailable()
Specified by:
isTransferAvailable in interface Peer

isDownloadPossible

public boolean isDownloadPossible()
Description copied from interface: Peer
This is much list isTransferAvailable(), except is more comprehensive. That is; it checks a few more factors, within the object for speed, so that a more timely status is considered and the caller doesn't need to try to check each thing on it's own.

Specified by:
isDownloadPossible in interface Peer
Returns:
true if several factors say downloading can be tried.

isChoked

public boolean isChoked()
Specified by:
isChoked in interface Peer

isChoking

public boolean isChoking()
Specified by:
isChoking in interface Peer

isInterested

public boolean isInterested()
Specified by:
isInterested in interface Peer

isInteresting

public boolean isInteresting()
Specified by:
isInteresting in interface Peer

isSeed

public boolean isSeed()
Specified by:
isSeed in interface Peer

isSnubbed

public boolean isSnubbed()
Specified by:
isSnubbed in interface Peer

getSnubbedTime

public long getSnubbedTime()
Specified by:
getSnubbedTime in interface Peer

setSnubbed

public void setSnubbed(boolean b)
Specified by:
setSnubbed in interface Peer

isOptimisticUnchoke

public boolean isOptimisticUnchoke()
Specified by:
isOptimisticUnchoke in interface Peer

setOptimisticUnchoke

public void setOptimisticUnchoke(boolean _is_optimistic)
Specified by:
setOptimisticUnchoke in interface Peer

getStats

public PeerStats getStats()
Specified by:
getStats in interface Peer

isIncoming

public boolean isIncoming()
Specified by:
isIncoming in interface Peer

getPercentDone

public int getPercentDone()
Specified by:
getPercentDone in interface Peer
Returns:

getPercentDoneInThousandNotation

public int getPercentDoneInThousandNotation()
Specified by:
getPercentDoneInThousandNotation in interface Peer

getClient

public String getClient()
Specified by:
getClient in interface Peer

getExpiredRequests

public List getExpiredRequests()
Specified by:
getExpiredRequests in interface Peer

getRequests

public List<PeerReadRequest> getRequests()
Specified by:
getRequests in interface Peer

getMaximumNumberOfRequests

public int getMaximumNumberOfRequests()
Specified by:
getMaximumNumberOfRequests in interface Peer

getNumberOfRequests

public int getNumberOfRequests()
Specified by:
getNumberOfRequests in interface Peer

getPriorityOffsets

public int[] getPriorityOffsets()
Specified by:
getPriorityOffsets in interface Peer

requestAllocationStarts

public boolean requestAllocationStarts(int[] base_priorities)
Specified by:
requestAllocationStarts in interface Peer

requestAllocationComplete

public void requestAllocationComplete()
Specified by:
requestAllocationComplete in interface Peer

addRequest

public boolean addRequest(PeerReadRequest request)
Specified by:
addRequest in interface Peer

cancelRequest

public void cancelRequest(PeerReadRequest request)
Specified by:
cancelRequest in interface Peer

close

public void close(String reason,
                  boolean closedOnError,
                  boolean attemptReconnect)
Specified by:
close in interface Peer

remove

public void remove()

addListener

public void addListener(PeerListener listener)
Description copied from interface: Peer
Add peer listener.

Specified by:
addListener in interface Peer

removeListener

public void removeListener(PeerListener listener)
Description copied from interface: Peer
Remove peer listener.

Specified by:
removeListener in interface Peer

addListener

public void addListener(PeerListener2 listener)
Description copied from interface: Peer
Add peer listener.

Specified by:
addListener in interface Peer

removeListener

public void removeListener(PeerListener2 listener)
Description copied from interface: Peer
Remove peer listener.

Specified by:
removeListener in interface Peer

fireEvent

protected void fireEvent(int type,
                         Object data)

getConnection

public Connection getConnection()
Description copied from interface: Peer
Get the network connection that backs this peer.

Specified by:
getConnection in interface Peer
Returns:
connection

supportsMessaging

public boolean supportsMessaging()
Description copied from interface: Peer
Whether or not this peer supports the advanced messaging API.

Specified by:
supportsMessaging in interface Peer
Returns:
true if extended messaging is supported, false if not

getSupportedMessages

public Message[] getSupportedMessages()
Description copied from interface: Peer
Get the list of messages that this peer and us mutually understand.

Specified by:
getSupportedMessages in interface Peer
Returns:
messages available for use, or null of supported is yet unknown

readBytes

public int readBytes(int max)
Description copied from interface: Peer
Rate control - gives the maximum number of bytes that can be read from this connection at this time and returns the actual number read

Specified by:
readBytes in interface Peer
Returns:

writeBytes

public int writeBytes(int max)
Specified by:
writeBytes in interface Peer

addRateLimiter

public void addRateLimiter(RateLimiter limiter,
                           boolean is_upload)
Specified by:
addRateLimiter in interface Peer
Parameters:
limiter - create via ConnectionManager
is_upload - false -> download limit

removeRateLimiter

public void removeRateLimiter(RateLimiter limiter,
                              boolean is_upload)
Specified by:
removeRateLimiter in interface Peer

getRateLimiters

public RateLimiter[] getRateLimiters(boolean is_upload)
Specified by:
getRateLimiters in interface Peer

getPercentDoneOfCurrentIncomingRequest

public int getPercentDoneOfCurrentIncomingRequest()
Specified by:
getPercentDoneOfCurrentIncomingRequest in interface Peer

getOutgoingRequestedPieceNumbers

public int[] getOutgoingRequestedPieceNumbers()
Specified by:
getOutgoingRequestedPieceNumbers in interface Peer

getOutgoingRequestCount

public int getOutgoingRequestCount()
Specified by:
getOutgoingRequestCount in interface Peer

getPercentDoneOfCurrentOutgoingRequest

public int getPercentDoneOfCurrentOutgoingRequest()
Specified by:
getPercentDoneOfCurrentOutgoingRequest in interface Peer

getProperties

public Map getProperties()

getName

public String getName()

setUserData

public void setUserData(Object key,
                        Object value)
Specified by:
setUserData in interface Peer

getUserData

public Object getUserData(Object key)
Specified by:
getUserData in interface Peer

getHandshakeReservedBytes

public byte[] getHandshakeReservedBytes()
Specified by:
getHandshakeReservedBytes in interface Peer

isPriorityConnection

public boolean isPriorityConnection()
Specified by:
isPriorityConnection in interface Peer

setPriorityConnection

public void setPriorityConnection(boolean is_priority)
Specified by:
setPriorityConnection in interface Peer