voldemort.cluster.failuredetector
Class AbstractFailureDetector

java.lang.Object
  extended by voldemort.cluster.failuredetector.AbstractFailureDetector
All Implemented Interfaces:
FailureDetector
Direct Known Subclasses:
AsyncRecoveryFailureDetector, BannagePeriodFailureDetector

public abstract class AbstractFailureDetector
extends java.lang.Object
implements FailureDetector

AbstractFailureDetector serves as a building block for FailureDetector implementations.


Field Summary
protected  FailureDetectorConfig failureDetectorConfig
           
protected  java.util.Map<java.lang.Integer,voldemort.cluster.failuredetector.NodeStatus> idNodeStatusMap
           
protected  java.util.concurrent.ConcurrentHashMap<FailureDetectorListener,java.lang.Object> listeners
           
protected  org.apache.log4j.Logger logger
           
 
Constructor Summary
protected AbstractFailureDetector(FailureDetectorConfig failureDetectorConfig)
           
 
Method Summary
 void addFailureDetectorListener(FailureDetectorListener failureDetectorListener)
          Adds a FailureDetectorListener instance that can receive event callbacks about node availability state changes.
protected  void checkArgs(Node node, long requestTime)
           
protected  void checkNodeArg(Node node)
           
 void destroy()
          Cleans up any open resources in preparation for shutdown.
 int getAvailableNodeCount()
          Returns the number of nodes that are considered to be available at the time of calling.
 java.lang.String getAvailableNodes()
           
 FailureDetectorConfig getConfig()
          Retrieves the FailureDetectorConfig instance with which this FailureDetector was constructed.
 long getLastChecked(Node node)
          Returns the number of milliseconds since the node was last checked for availability.
 int getNodeCount()
          Returns the number of nodes that are in the set of all nodes at the time of calling.
protected  voldemort.cluster.failuredetector.NodeStatus getNodeStatus(Node node)
           
 java.lang.String getUnavailableNodes()
           
 void removeFailureDetectorListener(FailureDetectorListener failureDetectorListener)
          Removes a FailureDetectorListener instance from the event listener list.
protected  void setAvailable(Node node)
           
protected  void setUnavailable(Node node, UnreachableStoreException e)
           
 void waitForAvailability(Node node)
          waitForAvailability causes the calling thread to block until the given Node is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface voldemort.cluster.failuredetector.FailureDetector
isAvailable, recordException, recordSuccess
 

Field Detail

failureDetectorConfig

protected final FailureDetectorConfig failureDetectorConfig

listeners

protected final java.util.concurrent.ConcurrentHashMap<FailureDetectorListener,java.lang.Object> listeners

idNodeStatusMap

protected final java.util.Map<java.lang.Integer,voldemort.cluster.failuredetector.NodeStatus> idNodeStatusMap

logger

protected final org.apache.log4j.Logger logger
Constructor Detail

AbstractFailureDetector

protected AbstractFailureDetector(FailureDetectorConfig failureDetectorConfig)
Method Detail

addFailureDetectorListener

public void addFailureDetectorListener(FailureDetectorListener failureDetectorListener)
Description copied from interface: FailureDetector
Adds a FailureDetectorListener instance that can receive event callbacks about node availability state changes.

Notes:

  1. Make sure to clean up the listener by invoking removeFailureDetectorListener
  2. Make sure that the FailureDetectorListener implementation properly implements the hashCode/equals methods

      Note for implementors: When adding a FailureDetectorListener that has already been added, this should not add a second instance but should effectively be a no-op.

      Specified by:
      addFailureDetectorListener in interface FailureDetector
      Parameters:
      failureDetectorListener - FailureDetectorListener that receives events
      See Also:
      FailureDetector.removeFailureDetectorListener(voldemort.cluster.failuredetector.FailureDetectorListener)

removeFailureDetectorListener

public void removeFailureDetectorListener(FailureDetectorListener failureDetectorListener)
Description copied from interface: FailureDetector
Removes a FailureDetectorListener instance from the event listener list.

Note for implementors: When removing a FailureDetectorListener that has already been removed or was never in the list, this should not raise any errors but should effectively be a no-op.

Specified by:
removeFailureDetectorListener in interface FailureDetector
Parameters:
failureDetectorListener - FailureDetectorListener that was receiving events
See Also:
FailureDetector.addFailureDetectorListener(voldemort.cluster.failuredetector.FailureDetectorListener)

getConfig

public FailureDetectorConfig getConfig()
Description copied from interface: FailureDetector
Retrieves the FailureDetectorConfig instance with which this FailureDetector was constructed.

Specified by:
getConfig in interface FailureDetector
Returns:
FailureDetectorConfig

getAvailableNodes

public java.lang.String getAvailableNodes()

getUnavailableNodes

public java.lang.String getUnavailableNodes()

getAvailableNodeCount

public int getAvailableNodeCount()
Description copied from interface: FailureDetector
Returns the number of nodes that are considered to be available at the time of calling. Letting n = the results of getNodeCount(), the return value is bounded in the range [0..n].

Specified by:
getAvailableNodeCount in interface FailureDetector
Returns:
Number of available nodes
See Also:
FailureDetector.getNodeCount()

getNodeCount

public int getNodeCount()
Description copied from interface: FailureDetector
Returns the number of nodes that are in the set of all nodes at the time of calling.

Specified by:
getNodeCount in interface FailureDetector
Returns:
Number of nodes
See Also:
FailureDetector.getAvailableNodeCount()

waitForAvailability

public void waitForAvailability(Node node)
                         throws java.lang.InterruptedException
Description copied from interface: FailureDetector
waitForAvailability causes the calling thread to block until the given Node is available. If the node is already available, this will simply return.

Specified by:
waitForAvailability in interface FailureDetector
Parameters:
node - Node on which to wait
Throws:
java.lang.InterruptedException - Thrown if the thread is interrupted

getLastChecked

public long getLastChecked(Node node)
Description copied from interface: FailureDetector
Returns the number of milliseconds since the node was last checked for availability. Because of its lack of precision, this should really only be used for status/reporting.

Specified by:
getLastChecked in interface FailureDetector
Parameters:
node - Node to check
Returns:
Number of milliseconds since the node was last checked for availability

destroy

public void destroy()
Description copied from interface: FailureDetector
Cleans up any open resources in preparation for shutdown.

Note for implementors: After this method is called it is assumed that attempts to call the other methods will either silently fail, throw errors, or return stale information.

Specified by:
destroy in interface FailureDetector

setAvailable

protected void setAvailable(Node node)

setUnavailable

protected void setUnavailable(Node node,
                              UnreachableStoreException e)

getNodeStatus

protected voldemort.cluster.failuredetector.NodeStatus getNodeStatus(Node node)

checkNodeArg

protected void checkNodeArg(Node node)

checkArgs

protected void checkArgs(Node node,
                         long requestTime)


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu