de.zib.scalaris
Class ConnectionPolicy

java.lang.Object
  extended by de.zib.scalaris.ConnectionPolicy
Direct Known Subclasses:
DefaultConnectionPolicy, FixedNodeConnectionPolicy

public abstract class ConnectionPolicy
extends Object

Defines a policy on how to select a node to connect to from a set of possible nodes and whether to automatically re-connect.

Since:
2.3
Version:
2.3
Author:
Nico Kruber, kruber@zib.de
See Also:
ConnectionFactory

Constructor Summary
ConnectionPolicy(List<PeerNode> availableRemoteNodes)
          Creates a connection policy with the given set of nodes available for connections.
ConnectionPolicy(PeerNode remoteNode)
          Creates a connection policy with one available node to connect to.
 
Method Summary
 void availableNodeAdded(PeerNode newNode)
          Signals the connection policy that the given node has been added to the list of available nodes.
 void availableNodeRemoved(PeerNode removedNode)
          Signals the connection policy that the given node has been removed from the list of available nodes.
 void availableNodesReset()
          Signals the connection policy that the list of available nodes has been reset (cleared).
 void nodeConnectSuccess(PeerNode node)
          Acts upon a successful connect attempt of the given node.
 void nodeFailed(PeerNode node)
          Acts upon a failure of the given node.
 void nodeFailReset(PeerNode node)
          Acts upon a failure reset of the given node.
 PeerNode selectNode()
          Selects the node to connect with when establishing a connection (no failed node, no exception that has already been thrown).
abstract
<E extends Exception>
PeerNode
selectNode(int retry, PeerNode failedNode, E e)
          Selects the node to (re-)connect with.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPolicy

public ConnectionPolicy(PeerNode remoteNode)
Creates a connection policy with one available node to connect to. Provided for convenience.

Parameters:
remoteNode - the node available for connections

ConnectionPolicy

public ConnectionPolicy(List<PeerNode> availableRemoteNodes)
Creates a connection policy with the given set of nodes available for connections.

Parameters:
availableRemoteNodes - available nodes to connect to
Method Detail

availableNodeAdded

public void availableNodeAdded(PeerNode newNode)
Signals the connection policy that the given node has been added to the list of available nodes.

Parameters:
newNode - the new node

availableNodeRemoved

public void availableNodeRemoved(PeerNode removedNode)
Signals the connection policy that the given node has been removed from the list of available nodes.

Parameters:
removedNode - the removed node

availableNodesReset

public void availableNodesReset()
Signals the connection policy that the list of available nodes has been reset (cleared).


nodeFailed

public void nodeFailed(PeerNode node)
Acts upon a failure of the given node. Sets the node's last failed connect time stamp.

Parameters:
node - the failed node

nodeFailReset

public void nodeFailReset(PeerNode node)
Acts upon a failure reset of the given node. Resets the node's last failure state.

Parameters:
node - the node

nodeConnectSuccess

public void nodeConnectSuccess(PeerNode node)
Acts upon a successful connect attempt of the given node. Sets the node's last successful connect time stamp and resets its failure statistics.

Parameters:
node - the node

selectNode

public PeerNode selectNode()
                    throws UnsupportedOperationException
Selects the node to connect with when establishing a connection (no failed node, no exception that has already been thrown). Provided for convenience.

Returns:
the node to use for the connection
Throws:
UnsupportedOperationException - is thrown if the operation can not be performed, e.g. the list is empty
See Also:
ConnectionFactory

selectNode

public abstract <E extends Exception> PeerNode selectNode(int retry,
                                                          PeerNode failedNode,
                                                          E e)
                             throws E extends Exception,
                                    UnsupportedOperationException
Selects the node to (re-)connect with. If no re-connection is desired, throw an exception!

Type Parameters:
E - the type of the exception that came from the failed connection and may be re-thrown
Parameters:
retry - the n'th retry (initial connect = 0, 1st reconnect = 1,...)
failedNode - the node from the previous connection attempt or null
e - the exception that came back from the previous connection attempt or null
Returns:
the new node to connect with
Throws:
E - if thrown, automatic re-connection attempts will stop
UnsupportedOperationException - is thrown if the operation can not be performed, e.g. the list is empty
E extends Exception
See Also:
Connection.connect(), Connection.doRPC(String, String, com.ericsson.otp.erlang.OtpErlangList), Connection.doRPC(String, String, com.ericsson.otp.erlang.OtpErlangObject[])