Class RedisBackedNodeRegistry

java.lang.Object
org.openqa.selenium.grid.distributor.redis.RedisBackedNodeRegistry
All Implemented Interfaces:
Closeable, AutoCloseable, NodeRegistry, HasReadyState

public class RedisBackedNodeRegistry extends Object implements NodeRegistry
Redis-backed implementation of NodeRegistry. Node HTTP proxy objects are kept in JVM-local memory (a live network connection cannot be serialized), but all grid model state is delegated to RedisBackedGridModel.

Multiple Distributor replicas can share the same Redis instance. Health checks are coordinated via Redis leader-election locks so each node is checked exactly once per cycle across all replicas.

  • Constructor Details

  • Method Details

    • register

      public void register(NodeStatus status)
      Description copied from interface: NodeRegistry
      Register a node status received from an event.
      Specified by:
      register in interface NodeRegistry
      Parameters:
      status - The node status to register.
    • add

      public void add(Node node)
      Description copied from interface: NodeRegistry
      Add a node to this registry.
      Specified by:
      add in interface NodeRegistry
      Parameters:
      node - The node to add.
    • remove

      public void remove(NodeId nodeId)
      Description copied from interface: NodeRegistry
      Removes a node from this registry.
      Specified by:
      remove in interface NodeRegistry
      Parameters:
      nodeId - The id of the node to remove.
    • drain

      public boolean drain(NodeId nodeId)
      Description copied from interface: NodeRegistry
      Set a node to draining state.
      Specified by:
      drain in interface NodeRegistry
      Parameters:
      nodeId - The id of the node to drain.
      Returns:
      true if the node was set to draining, false otherwise.
    • updateNodeAvailability

      public void updateNodeAvailability(URI nodeUri, NodeId id, Availability availability)
      Description copied from interface: NodeRegistry
      Updates a node's availability status.
      Specified by:
      updateNodeAvailability in interface NodeRegistry
      Parameters:
      nodeUri - The URI of the node.
      id - The id of the node.
      availability - The new availability status.
    • runHealthChecks

      public void runHealthChecks()
      Description copied from interface: NodeRegistry
      Run health checks on all nodes.
      Specified by:
      runHealthChecks in interface NodeRegistry
    • refresh

      public void refresh()
      Description copied from interface: NodeRegistry
      Refreshes all nodes by running a health check on each one.
      Specified by:
      refresh in interface NodeRegistry
    • getStatus

      public DistributorStatus getStatus()
      Description copied from interface: NodeRegistry
      Gets a snapshot of all registered nodes.
      Specified by:
      getStatus in interface NodeRegistry
      Returns:
      The current status of the distributor.
    • getAvailableNodes

      public Set<NodeStatus> getAvailableNodes()
      Description copied from interface: NodeRegistry
      Gets all available nodes that are not DOWN or DRAINING and has free slots.
      Specified by:
      getAvailableNodes in interface NodeRegistry
      Returns:
      Set of available node statuses.
    • getUpNodes

      public Set<NodeStatus> getUpNodes()
      Description copied from interface: NodeRegistry
      Get all nodes that are UP.
      Specified by:
      getUpNodes in interface NodeRegistry
      Returns:
      Set of UP node statuses.
    • getNode

      public Node getNode(NodeId id)
      Description copied from interface: NodeRegistry
      Gets a node by its ID.
      Specified by:
      getNode in interface NodeRegistry
      Parameters:
      id - The node ID to look up.
      Returns:
      The node, or null if not found.
    • getNode

      public @Nullable Node getNode(URI uri)
      Description copied from interface: NodeRegistry
      Get node by URI.
      Specified by:
      getNode in interface NodeRegistry
      Parameters:
      uri - The node URI to look up.
      Returns:
      The node if found, null otherwise.
    • getUpNodeCount

      public long getUpNodeCount()
      Description copied from interface: NodeRegistry
      Gets the total number of nodes that are UP.
      Specified by:
      getUpNodeCount in interface NodeRegistry
      Returns:
      The number of UP nodes.
    • getDownNodeCount

      public long getDownNodeCount()
      Description copied from interface: NodeRegistry
      Gets the total number of nodes that are DOWN.
      Specified by:
      getDownNodeCount in interface NodeRegistry
      Returns:
      The number of DOWN nodes.
    • isReady

      public boolean isReady()
      Specified by:
      isReady in interface HasReadyState
    • reserve

      public boolean reserve(SlotId slotId)
      Description copied from interface: NodeRegistry
      Reserve a slot for a session.
      Specified by:
      reserve in interface NodeRegistry
      Parameters:
      slotId - The slot ID to reserve.
      Returns:
      Whether the reservation was successful.
    • setSession

      public void setSession(SlotId slotId, @Nullable Session session)
      Description copied from interface: NodeRegistry
      Set a session for a particular slot.
      Specified by:
      setSession in interface NodeRegistry
      Parameters:
      slotId - The slot ID.
      session - The session to associate with the slot, or null to clear.
    • getActiveSlots

      public int getActiveSlots()
      Description copied from interface: NodeRegistry
      Get the number of active slots.
      Specified by:
      getActiveSlots in interface NodeRegistry
    • getIdleSlots

      public int getIdleSlots()
      Description copied from interface: NodeRegistry
      Get the number of idle slots.
      Specified by:
      getIdleSlots in interface NodeRegistry
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable