com.crankuptheamps.client
Class DefaultServerChooser

java.lang.Object
  extended by com.crankuptheamps.client.DefaultServerChooser
All Implemented Interfaces:
ServerChooser

public class DefaultServerChooser
extends Object
implements ServerChooser

A simple ServerChooser that keeps a list of AMPS instances and Authenticators, and advances to the next one when failure occurs.


Constructor Summary
DefaultServerChooser()
           
 
Method Summary
 DefaultServerChooser add(String uri)
          Adds a URI to self.
 Authenticator getCurrentAuthenticator()
          Returns the Authenticator instance associated with the current URI.
 String getCurrentURI()
          Returns the current URI.
 String getError()
          Provides additional detail to be included in an exception thrown when the AMPS instance(s) are not available.
 void next()
          Advances the server chooser to the next server it deems appropriate to connect with.
 void reportFailure(Exception exception, ConnectionInfo info)
          Called by the HAClient when an error occurs connecting to the current URI, and/or when an error occurs logging on.
 void reportSuccess(ConnectionInfo info)
          Called by the HAClient when successfully connected and logged on to the current instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultServerChooser

public DefaultServerChooser()
Method Detail

add

public DefaultServerChooser add(String uri)
Adds a URI to self.

Parameters:
uri - The AMPS URI to add to the list.

getCurrentURI

public String getCurrentURI()
Description copied from interface: ServerChooser
Returns the current URI.

Specified by:
getCurrentURI in interface ServerChooser
Returns:
A string with the URI to connect to, or null if no server is available to connect to.

getCurrentAuthenticator

public Authenticator getCurrentAuthenticator()
Description copied from interface: ServerChooser
Returns the Authenticator instance associated with the current URI.

Specified by:
getCurrentAuthenticator in interface ServerChooser
Returns:
An Authenticator or null if none is required for logon.

reportFailure

public void reportFailure(Exception exception,
                          ConnectionInfo info)
Description copied from interface: ServerChooser
Called by the HAClient when an error occurs connecting to the current URI, and/or when an error occurs logging on. Implementors will likely advance the current URI to the next one in a list, or choose to stay with the current one, based on the exception type.

Specified by:
reportFailure in interface ServerChooser
Parameters:
exception - The exception associated with this failure.
info - Information about the connection that failed.

reportSuccess

public void reportSuccess(ConnectionInfo info)
Description copied from interface: ServerChooser
Called by the HAClient when successfully connected and logged on to the current instance.

Specified by:
reportSuccess in interface ServerChooser
Parameters:
info - Information about the successful connection.

next

public void next()
Description copied from interface: ServerChooser
Advances the server chooser to the next server it deems appropriate to connect with.

Specified by:
next in interface ServerChooser

getError

public String getError()
Description copied from interface: ServerChooser
Provides additional detail to be included in an exception thrown when the AMPS instance(s) are not available. Called by the HAClient when creating an exception.

Specified by:
getError in interface ServerChooser
Returns:
An String with information about the connection that failed and the reason for the failure. When no further information is available, returns an empty string.