de.zib.scalaris
Class NodeDiscovery

java.lang.Object
  extended by de.zib.scalaris.NodeDiscovery
All Implemented Interfaces:
Runnable

public class NodeDiscovery
extends Object
implements Runnable

Provides a node discovery service. When started with startWithFixedDelay(long) or startWithFixedDelay(long, long, TimeUnit), periodically connects to a Scalaris node and gets information about other Scalaris nodes. These will then be added to the given ConnectionFactory where old nodes with connection failures will be removed in favour of newly discovered nodes.

Since:
3.16
Version:
3.16
Author:
Nico Kruber, kruber@zib.de

Nested Class Summary
static interface NodeDiscovery.NewNodeHandler
          Handler that is invoked whenever a new node is found by the NodeDiscovery thread.
 
Constructor Summary
NodeDiscovery(ConnectionFactory cf)
          Constructor
NodeDiscovery(ConnectionPool cPool)
          Constructor
 
Method Summary
 ConnectionFactory getCf()
          Gets the ConnectionFactory to work with.
 int getMaxNodes()
          Gets the maximum number of nodes that should remain in the ConnectionFactory cf.
 int getMinAgeToRemove()
          Gets the minimum time in seconds since the last successful connection for a node to be removed in favour of newly discovered nodes.
 void run()
          Executed a single call to a known Scalaris node asking for other known nodes.
 void setMaxNodes(int maxNodes)
          Sets the maximum number of nodes that should remain in the ConnectionFactory cf.
 void setMinAgeToRemove(int minAgeToRemove)
          Sets the minimum time in seconds since the last successful connection for a node to be removed in favour of newly discovered nodes.
 void startWithFixedDelay(long delay)
          Starts the node discovery service at the given fixed delay.
 void startWithFixedDelay(long initialDelay, long delay, TimeUnit unit)
          Starts the node discovery service at the given fixed delay.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeDiscovery

public NodeDiscovery(ConnectionFactory cf)
Constructor

Parameters:
cf - the ConnectionFactory to add nodes to / remove nodes from

NodeDiscovery

public NodeDiscovery(ConnectionPool cPool)
Constructor

Parameters:
cPool - the ConnectionPool to interact with
Method Detail

startWithFixedDelay

public void startWithFixedDelay(long delay)
Starts the node discovery service at the given fixed delay.

Parameters:
delay - the delay between the termination of one execution and the commencement of the next

startWithFixedDelay

public void startWithFixedDelay(long initialDelay,
                                long delay,
                                TimeUnit unit)
Starts the node discovery service at the given fixed delay.

Parameters:
initialDelay - the time to delay first execution
delay - the delay between the termination of one execution and the commencement of the next
unit - the time unit of the initialDelay and delay parameters

run

public void run()
Executed a single call to a known Scalaris node asking for other known nodes. These nodes will then be added to the ConnectionFactory cf.

Specified by:
run in interface Runnable

getMaxNodes

public final int getMaxNodes()
Gets the maximum number of nodes that should remain in the ConnectionFactory cf.

Returns:
the maxNodes member

setMaxNodes

public final void setMaxNodes(int maxNodes)
Sets the maximum number of nodes that should remain in the ConnectionFactory cf.

Parameters:
maxNodes - the maxNodes to set

getMinAgeToRemove

public final int getMinAgeToRemove()
Gets the minimum time in seconds since the last successful connection for a node to be removed in favour of newly discovered nodes.

Returns:
the minAgeToRemove member

setMinAgeToRemove

public final void setMinAgeToRemove(int minAgeToRemove)
Sets the minimum time in seconds since the last successful connection for a node to be removed in favour of newly discovered nodes.

Parameters:
minAgeToRemove - the minAgeToRemove to set

getCf

public final ConnectionFactory getCf()
Gets the ConnectionFactory to work with.

Returns:
the connection factory