|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.zib.scalaris.ConnectionPolicy
de.zib.scalaris.DefaultConnectionPolicy
public class DefaultConnectionPolicy
Implements a ConnectionPolicy by choosing nodes randomly.
Sorts nodes into two lists:
badNodes. When a connection
attempt to a node is successful, it will be removed from this list and put
into the good nodes list goodNodes and the node's connection failure
statistics will be reset using PeerNode.resetFailureCount().
Whenever a node is being selected for a new connection (or reconnect), it
will select one randomly from the goodNodes list. If this list is
empty, it will select the least recently failed node from badNodes.
At most maxRetries retries are attempted per operation (see
Connection.connect(),
Connection.doRPC(String, String, com.ericsson.otp.erlang.OtpErlangList)
and
Connection.doRPC(String, String, com.ericsson.otp.erlang.OtpErlangObject[])
) - the number of the current attempt will not be cached in this class. Set
the maximal number of retries using setMaxRetries(int).
Attention: All member's functions are synchronised as there can be a single
connection policy object used by many threads and the access to the
goodNodes and badNodes members are logically linked
together and operations on both need to be performed atomically. Additionally
access to PeerNode objects are synchronised on themselves. It is
therefore important not to use any of this classes methods in blocks that
synchronise on any node object. Otherwise deadlocks might occur!!
| Constructor Summary | |
|---|---|
DefaultConnectionPolicy(List<PeerNode> availableRemoteNodes)
Creates a new connection policy with the given remote nodes. |
|
DefaultConnectionPolicy(PeerNode remoteNode)
Creates a new connection policy working with the given remote node. |
|
| Method Summary | ||
|---|---|---|
void |
availableNodeAdded(PeerNode newNode)
Adds the given node to the goodNodes list if it has no failures,
otherwise it will be added to badNodes. |
|
void |
availableNodeRemoved(PeerNode removedNode)
Removes the node from the goodNodes and badNodes lists. |
|
void |
availableNodesReset()
Resets the goodNodes and badNodes members as the list
of available nodes has been reset. |
|
List<PeerNode> |
getBadNodes()
Gets a copy of the list of good nodes (contains references to the PeerNode objects). |
|
List<PeerNode> |
getGoodNodes()
Gets a copy of the list of good nodes (contains references to the PeerNode objects). |
|
int |
getMaxRetries()
Sets the maximal number of automatic connection retries. |
|
void |
nodeConnectSuccess(PeerNode node)
Sets the node's last successful connect time stamp, resets its failure statistics and moves it to the goodNodes list. |
|
void |
nodeFailed(PeerNode node)
Sets the given node's last failed connect time stamp and moves it to the badNodes list. |
|
void |
nodeFailReset(PeerNode node)
Acts upon a failure reset of the given node. |
|
|
selectNode(int retry,
PeerNode failedNode,
E e)
Selects the node to (re-)connect with until the maximal number of maxRetries has been reached. |
|
void |
setMaxRetries(int maxRetries)
Gets the maximal number of automatic connection retries. |
|
| Methods inherited from class de.zib.scalaris.ConnectionPolicy |
|---|
selectNode |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultConnectionPolicy(PeerNode remoteNode)
remoteNode - the (only) available remote nodepublic DefaultConnectionPolicy(List<PeerNode> availableRemoteNodes)
availableRemoteNodes.
Any time this list is changed, the according methods in this class should
be called, i.e. availableNodeAdded(PeerNode),
availableNodeRemoved(PeerNode), availableNodesReset()
to update the good and bad nodes lists.
availableRemoteNodes - the remote nodes available for connections| Method Detail |
|---|
public void availableNodeAdded(PeerNode newNode)
goodNodes list if it has no failures,
otherwise it will be added to badNodes.
Attention: This method also synchronises on the node.
availableNodeAdded in class ConnectionPolicynewNode - the new nodepublic void availableNodeRemoved(PeerNode removedNode)
goodNodes and badNodes lists.
availableNodeRemoved in class ConnectionPolicyremovedNode - the removed nodepublic void availableNodesReset()
goodNodes and badNodes members as the list
of available nodes has been reset.
availableNodesReset in class ConnectionPolicypublic void nodeFailed(PeerNode node)
badNodes list.
Attention: This method also synchronises on the node.
nodeFailed in class ConnectionPolicynode - the failed nodepublic void nodeFailReset(PeerNode node)
nodeFailReset in class ConnectionPolicynode - the nodepublic void nodeConnectSuccess(PeerNode node)
goodNodes list.
Attention: This method also synchronises on the node.
nodeConnectSuccess in class ConnectionPolicynode - the node
public <E extends Exception> PeerNode selectNode(int retry,
PeerNode failedNode,
E e)
throws E extends Exception
maxRetries has been reached.
Throws an exception if retry > maxRetries and thus stops further
node connection attempts. Otherwise chooses a random good node or (if
there are no good nodes) the least recently failed bad node.
selectNode in class ConnectionPolicyE - the type of the exception that came from the failed connection
and may be re-thrownretry - the n'th retry (initial connect = 0, 1st reconnect = 1,...)failedNode - the node from the previous connection attempt or nulle - the exception that came back from the previous connection
attempt or null
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 ExceptionConnection.connect(),
Connection.doRPC(String, String,
com.ericsson.otp.erlang.OtpErlangList),
Connection.doRPC(String, String,
com.ericsson.otp.erlang.OtpErlangObject[])public int getMaxRetries()
public void setMaxRetries(int maxRetries)
maxRetries - the maxRetries to set (>= 0)public List<PeerNode> getGoodNodes()
PeerNode objects).
public List<PeerNode> getBadNodes()
PeerNode objects).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||