Class NodeHealthTracker

java.lang.Object
com.loomcache.client.NodeHealthTracker

public class NodeHealthTracker extends Object
Tracks node health based on success/failure rates.

Health state transitions: - HEALTHY → SUSPECTED: 3+ consecutive failures - SUSPECTED → UNHEALTHY: 10+ consecutive failures - UNHEALTHY → HEALTHY: 3+ consecutive successes

  • Constructor Details

    • NodeHealthTracker

      public NodeHealthTracker()
  • Method Details

    • recordSuccess

      public void recordSuccess(String nodeId)
      Record a successful operation for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
    • recordFailure

      public void recordFailure(String nodeId)
      Record a failed operation for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
    • getStatus

      public NodeHealthTracker.HealthStatus getStatus(String nodeId)
      Get the current health status of a node.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      the health status (defaults to HEALTHY if no data)
    • isHealthy

      public boolean isHealthy(String nodeId)
      Check if a node is healthy.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      true if the node is HEALTHY, false otherwise
    • getConsecutiveFailures

      public int getConsecutiveFailures(String nodeId)
      Get the number of consecutive failures for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      consecutive failure count
    • getConsecutiveSuccesses

      public int getConsecutiveSuccesses(String nodeId)
      Get the number of consecutive successes for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      consecutive success count
    • getTotalFailures

      public long getTotalFailures(String nodeId)
      Get total failures for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      total failure count
    • getTotalSuccesses

      public long getTotalSuccesses(String nodeId)
      Get total successes for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      total success count
    • reset

      public void reset(String nodeId)
      Reset health state for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
    • clear

      public void clear()
      Clear all health tracking data.
    • getLastFailureTime

      public long getLastFailureTime(String nodeId)
      Get the timestamp of the last failure for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      last failure time in milliseconds, or 0 if no failures
    • getLastSuccessTime

      public long getLastSuccessTime(String nodeId)
      Get the timestamp of the last success for a node.
      Parameters:
      nodeId - the node identifier (must not be null)
      Returns:
      last success time in milliseconds, or 0 if no successes