LimeWire Consolidated API

com.limegroup.gnutella.altlocs
Class AbstractAlternateLocation

java.lang.Object
  extended by com.limegroup.gnutella.altlocs.AbstractAlternateLocation
All Implemented Interfaces:
AlternateLocation, HTTPHeaderValue, Comparable<AlternateLocation>
Direct Known Subclasses:
DirectAltLoc, PushAltLoc

public abstract class AbstractAlternateLocation
extends Object
implements AlternateLocation

Abstract super class that encompasses common functionality shared by most implementations of AlternateLocation.


Field Summary
protected  int _count
          maintins a count of how many times this alternate location has been seen.
protected  int hashCode
          Cached hash code that is lazily initialized.
protected  URN SHA1_URN
          Constant for the sha1 urn for this AlternateLocation -- can be null.
 
Fields inherited from interface com.limegroup.gnutella.altlocs.AlternateLocation
ALT_VENDOR, MESH_LEGACY, MESH_PING, MESH_RESPONSE
 
Constructor Summary
protected AbstractAlternateLocation(URN sha1)
           
 
Method Summary
 boolean canBeSent(int meshType)
           
 boolean canBeSentAny()
           
 int compareTo(AlternateLocation other)
          The idea is that this is smaller than any AlternateLocation who has a greater value of _count.
abstract  AlternateLocation createClone()
          could return null
abstract  RemoteFileDesc createRemoteFileDesc(long size, RemoteFileDescFactory remoteFileDescFactory)
          Creates a new RemoteFileDesc from this AlternateLocation
 boolean equals(Object obj)
          Overrides the equals method to accurately compare AlternateLocation instances.
protected abstract  String generateHTTPString()
           
 int getCount()
          Accessor to find if this has been demoted
 URN getSHA1Urn()
          Accessor for the SHA1 urn for this AlternateLocation.
 int hashCode()
          Overrides the hashCode method of Object to meet the contract of hashCode.
 String httpStringValue()
          Returns a string representation of the HTTP header value for this class.
 void increment()
          increment the count.
abstract  boolean isDemoted()
          package access, accessor to the value of _demoted
abstract  boolean isMe()
           
 void send(long now, int meshType)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHA1_URN

protected final URN SHA1_URN
Constant for the sha1 urn for this AlternateLocation -- can be null.


hashCode

protected volatile int hashCode
Cached hash code that is lazily initialized.


_count

protected volatile int _count
maintins a count of how many times this alternate location has been seen. A value of 0 means this alternate location was failed one more time that it has succeeded. Newly created AlternateLocations start out wit a value of 1.

Constructor Detail

AbstractAlternateLocation

protected AbstractAlternateLocation(URN sha1)
Method Detail

getSHA1Urn

public URN getSHA1Urn()
Description copied from interface: AlternateLocation
Accessor for the SHA1 urn for this AlternateLocation.

Specified by:
getSHA1Urn in interface AlternateLocation
Returns:
the SHA1 urn for the this AlternateLocation

getCount

public int getCount()
Description copied from interface: AlternateLocation
Accessor to find if this has been demoted

Specified by:
getCount in interface AlternateLocation

isDemoted

public abstract boolean isDemoted()
Description copied from interface: AlternateLocation
package access, accessor to the value of _demoted

Specified by:
isDemoted in interface AlternateLocation

httpStringValue

public String httpStringValue()
Description copied from interface: HTTPHeaderValue
Returns a string representation of the HTTP header value for this class.

Specified by:
httpStringValue in interface HTTPHeaderValue
Returns:
a string representation of the HTTP header value for this class

createRemoteFileDesc

public abstract RemoteFileDesc createRemoteFileDesc(long size,
                                                    RemoteFileDescFactory remoteFileDescFactory)
Description copied from interface: AlternateLocation
Creates a new RemoteFileDesc from this AlternateLocation

Specified by:
createRemoteFileDesc in interface AlternateLocation
Parameters:
size - the size of the file for the new RemoteFileDesc -- this is necessary to make sure the download bucketing works correctly
Returns:
new RemoteFileDesc based off of this, or null if the RemoteFileDesc could not be created

isMe

public abstract boolean isMe()
Specified by:
isMe in interface AlternateLocation
Returns:
whether this is an alternate location pointing to myself.

increment

public void increment()
Description copied from interface: AlternateLocation
increment the count.

Specified by:
increment in interface AlternateLocation
See Also:
demote

createClone

public abstract AlternateLocation createClone()
Description copied from interface: AlternateLocation
could return null

Specified by:
createClone in interface AlternateLocation

send

public void send(long now,
                 int meshType)
Specified by:
send in interface AlternateLocation

canBeSent

public boolean canBeSent(int meshType)
Specified by:
canBeSent in interface AlternateLocation

canBeSentAny

public boolean canBeSentAny()
Specified by:
canBeSentAny in interface AlternateLocation

equals

public boolean equals(Object obj)
Overrides the equals method to accurately compare AlternateLocation instances. AlternateLocations are equal if their URLs are equal.

Overrides:
equals in class Object
Parameters:
obj - the Object instance to compare to
Returns:
true if the URL of this AlternateLocation is equal to the URL of the AlternateLocation location argument, and otherwise returns false

compareTo

public int compareTo(AlternateLocation other)
The idea is that this is smaller than any AlternateLocation who has a greater value of _count. There is one exception to this rule -- a demoted AlternateLocation has a higher value irrespective of count.

This is because we want to have a sorted set of AlternateLocation where any demoted AlternateLocation is put at the end of the list because it probably does not work.

Further we want to get AlternateLocations with smaller counts to be propogated more, since this will serve to get better load balancing of uploader.

Specified by:
compareTo in interface Comparable<AlternateLocation>

generateHTTPString

protected abstract String generateHTTPString()

hashCode

public int hashCode()
Overrides the hashCode method of Object to meet the contract of hashCode. Since we override equals, it is necessary to also override hashcode to ensure that two "equal" alternate locations return the same hashCode, less we unleash unknown havoc on the hash-based collections.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.