com.limegroup.gnutella.bootstrap
Class BootstrapServerManager

java.lang.Object
  extended by com.limegroup.gnutella.bootstrap.BootstrapServerManager

public class BootstrapServerManager
extends java.lang.Object

A list of GWebCache servers. Provides methods to fetch address addresses from these servers, find the addresses of more such servers, and update the addresses of these and other servers.

Information on the GWebCache protocol can be found at http://zero-g.net/gwebcache/specs.html


Field Summary
static java.io.File bootstrapServers
           
static int CACHE_OFF
          GWebCache use is turned off.
static int FETCH_IN_PROGRESS
          The fetch wasn't scheduled because one is in progress.
static int FETCH_SCHEDULED
          A fetch was scheduled.
static int FETCHED_TOO_MANY
          Too many endpoints were already fetch, the fetch wasn't scheduled.
static int MAX_HOSTS_PER_REQUEST
          The maximum number of hosts to try per request.
static int NO_CACHES_LEFT
          All caches were already contacted atleast once.
static int UPDATE_DELAY_MSEC
          The amount of time in milliseconds between update requests.
 
Constructor Summary
protected BootstrapServerManager()
          Creates a new BootstrapServerManager.
 
Method Summary
 void addBootstrapServer(BootstrapServer server)
          Adds server to this.
 void bootstrapServersAdded()
          Notification that all bootstrap servers have been added.
 void fetchBootstrapServersAsync()
          Asynchronously fetches other bootstrap URLs and stores them in this.
 int fetchEndpointsAsync()
          Asynchronously fetches host addresses from bootstrap servers and stores them in the HostCatcher.
 int fetchEndpointsAsyncV2()
          Asynchronously fetches host addresses from bootstrap servers and stores them in the HostCatcher.
 java.util.Iterator getBootstrapServers()
          Returns an iterator of the bootstrap servers in this, each as a BootstrapServer, in any order.
static BootstrapServerManager instance()
          Accessor for the BootstrapServerManager instance.
 boolean isEndpointFetchInProgress()
          Determines whether or not an endpoint fetch is in progress.
protected  int randomServer()
          Returns an random valid index of SERVERS.
protected  void removeServer(BootstrapServer server)
          Removes the server.
 void resetData()
          Resets information related to the caches & endpoints we've fetched.
 void sendUpdatesAsync(ServerInfo myIP)
          Asynchronously sends an update message to a cache.
 void sendUpdatesAsyncV2(ServerInfo myIP)
          Asynchronously sends an update message to a cache.
protected  int size()
          Returns the number of servers in this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bootstrapServers

public static final java.io.File bootstrapServers

CACHE_OFF

public static final int CACHE_OFF
GWebCache use is turned off.

See Also:
Constant Field Values

FETCH_SCHEDULED

public static final int FETCH_SCHEDULED
A fetch was scheduled.

See Also:
Constant Field Values

FETCH_IN_PROGRESS

public static final int FETCH_IN_PROGRESS
The fetch wasn't scheduled because one is in progress.

See Also:
Constant Field Values

FETCHED_TOO_MANY

public static final int FETCHED_TOO_MANY
Too many endpoints were already fetch, the fetch wasn't scheduled.

See Also:
Constant Field Values

NO_CACHES_LEFT

public static final int NO_CACHES_LEFT
All caches were already contacted atleast once.

See Also:
Constant Field Values

MAX_HOSTS_PER_REQUEST

public static int MAX_HOSTS_PER_REQUEST
The maximum number of hosts to try per request. Prevents us from consuming all hosts if disconnected. Non-final for testing.


UPDATE_DELAY_MSEC

public static int UPDATE_DELAY_MSEC
The amount of time in milliseconds between update requests. Public and non-final for testing purposes.

Constructor Detail

BootstrapServerManager

protected BootstrapServerManager()
Creates a new BootstrapServerManager. Protected for testing.

Method Detail

instance

public static BootstrapServerManager instance()
Accessor for the BootstrapServerManager instance.

Returns:
the BootstrapServerManager instance

addBootstrapServer

public void addBootstrapServer(BootstrapServer server)
Adds server to this.


bootstrapServersAdded

public void bootstrapServersAdded()
Notification that all bootstrap servers have been added.


resetData

public void resetData()
Resets information related to the caches & endpoints we've fetched.


isEndpointFetchInProgress

public boolean isEndpointFetchInProgress()
Determines whether or not an endpoint fetch is in progress.


getBootstrapServers

public java.util.Iterator getBootstrapServers()
Returns an iterator of the bootstrap servers in this, each as a BootstrapServer, in any order. To prevent ConcurrentModification problems, the caller should hold this' lock while using the iterator.

Returns:
an Iterator of BootstrapServer.

fetchBootstrapServersAsync

public void fetchBootstrapServersAsync()
Asynchronously fetches other bootstrap URLs and stores them in this. Stops after getting "enough" endpoints or exhausting all caches. Uses the "urlfile=1" message.


fetchEndpointsAsync

public int fetchEndpointsAsync()
Asynchronously fetches host addresses from bootstrap servers and stores them in the HostCatcher. Stops after getting "enough" endpoints or exhausting all caches. Does nothing if another endpoint request is in progress. Uses the "hostfile=1" message.


fetchEndpointsAsyncV2

public int fetchEndpointsAsyncV2()
Asynchronously fetches host addresses from bootstrap servers and stores them in the HostCatcher. Stops after getting "enough" endpoints or exhausting all caches. Does nothing if another endpoint request is in progress. Uses the "hostfile=1" message.


sendUpdatesAsync

public void sendUpdatesAsync(ServerInfo myIP)
Asynchronously sends an update message to a cache. May do nothing if nothing to update. Uses the "url" and "ip" messages.

Parameters:
myIP - my listening address and port
Throws:
NullPointerException - if the ip param is null

sendUpdatesAsyncV2

public void sendUpdatesAsyncV2(ServerInfo myIP)
Asynchronously sends an update message to a cache. May do nothing if nothing to update. Uses the "url" and "ip" messages.

Parameters:
myIP - my listening address and port
Throws:
NullPointerException - if the ip param is null

size

protected int size()
Returns the number of servers in this.


randomServer

protected int randomServer()
Returns an random valid index of SERVERS. Protected so we can override in test cases. PRECONDITION: SERVERS.size>0.


removeServer

protected void removeServer(BootstrapServer server)
Removes the server.