Class DefaultNodeStore

java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.DefaultNodeStore
All Implemented Interfaces:
NodeStore

public final class DefaultNodeStore extends Object implements NodeStore
Default implementation of NodeStore using concurrent collections.
  • Field Details

    • DEFAULT_NUMBER_OF_NODES

      public static final int DEFAULT_NUMBER_OF_NODES
      Default initial capacity for the node mappings.
      See Also:
    • DEFAULT_NUMBER_OF_COMPONENTS

      public static final int DEFAULT_NUMBER_OF_COMPONENTS
      Default initial capacity for components per node.
      See Also:
    • DEFAULT_NUMBER_OF_AWAITS

      public static final int DEFAULT_NUMBER_OF_AWAITS
      Default initial capacity for awaiting callbacks.
      See Also:
  • Constructor Details

    • DefaultNodeStore

      public DefaultNodeStore()
      Creates a DefaultNodeStore with default expected capacities and default ordering.
    • DefaultNodeStore

      public DefaultNodeStore(int numberOfNodes)
      Creates a DefaultNodeStore with the specified expected number of nodes and default ordering.
      Parameters:
      numberOfNodes - the expected number of nodes
    • DefaultNodeStore

      public DefaultNodeStore(int numberOfNodes, int numberOfAwaits)
      Creates a DefaultNodeStore with the specified expected number of nodes and awaits, using default ordering.
      Parameters:
      numberOfNodes - the expected number of nodes
      numberOfAwaits - the expected number of awaits
    • DefaultNodeStore

      public DefaultNodeStore(@Nullable Comparator<BabelNodeComponent> comparator)
      Creates a DefaultNodeStore with default expected capacities and the specified component comparator.
      Parameters:
      comparator - the comparator to order components with, or null to use default ordering
    • DefaultNodeStore

      public DefaultNodeStore(int numberOfNodes, @Nullable Comparator<BabelNodeComponent> comparator)
      Creates a DefaultNodeStore with the specified expected number of nodes and component comparator.
      Parameters:
      numberOfNodes - the expected number of nodes
      comparator - the comparator to order components with, or null to use default ordering
    • DefaultNodeStore

      public DefaultNodeStore(int numberOfNodes, int numberOfAwaits, @Nullable Comparator<BabelNodeComponent> comparator)
      Creates a DefaultNodeStore with the specified expected number of nodes, awaits, and component comparator.
      Parameters:
      numberOfNodes - the expected number of nodes
      numberOfAwaits - the expected number of awaits
      comparator - the comparator to order components with, or null to use default ordering
  • Method Details

    • getComponentsOfType

      public <T extends BabelNodeComponent> SortedSet<T> getComponentsOfType(BabelNode node, Class<T> type)
      Description copied from interface: NodeStore
      Gets all components of a specific type (e.g., IPBabelNodeComponent.class) attached to a node. Implementations should ideally return this sorted by reachability priority and in an immutable view.
      Specified by:
      getComponentsOfType in interface NodeStore
      Type Parameters:
      T - the type of the component
      Parameters:
      node - the node to query
      type - the class representing the component type
      Returns:
      a sorted set of components of the requested type attached to the node
    • addComponent

      public SortedSet<BabelNodeComponent> addComponent(BabelNode node, BabelNodeComponent component)
      Description copied from interface: NodeStore
      Adds a newly discovered component to the store. Invoking this will trigger any callbacks registered via NodeStore.awaitComponent(BabelNode, Class, Runnable, Consumer).
      Specified by:
      addComponent in interface NodeStore
      Parameters:
      node - the node to which the component is added
      component - the component to add
      Returns:
      a sorted set of components attached to the node after the addition
    • removeComponent

      public boolean removeComponent(BabelNode node, BabelNodeComponent component)
      Description copied from interface: NodeStore
      Removes a stale or dead component from the store. Essential for evicting IPs that no longer respond to heartbeats.
      Specified by:
      removeComponent in interface NodeStore
      Parameters:
      node - the node from which the component is removed
      component - the component to remove
      Returns:
      true if the component was present and removed, false otherwise
    • resolutionFailed

      public void resolutionFailed(BabelNode node, Class<? extends BabelNodeComponent> type)
      Description copied from interface: NodeStore
      Signals that the resolver protocol failed to find the requested component type for the given node (e.g., discovery timeout). Invoking this will trigger any callbacks registered via NodeStore.awaitComponent(BabelNode, Class, Runnable, Consumer) with an empty sorted set.
      Specified by:
      resolutionFailed in interface NodeStore
      Parameters:
      node - the node for which resolution failed
      type - the type of component that failed to resolve
    • resolutionSuccessuful

      public void resolutionSuccessuful(BabelNode node, Class<? extends BabelNodeComponent> type)
      Description copied from interface: NodeStore
      Signals that the resolver protocol successfully resolved the requested component type for the given node. Invoking this will trigger any callbacks registered via NodeStore.awaitComponent(BabelNode, Class, Runnable, Consumer) with the resolved components.
      Specified by:
      resolutionSuccessuful in interface NodeStore
      Parameters:
      node - the node for which resolution succeeded
      type - the type of component that was successfully resolved
    • awaitComponent

      public <T extends BabelNodeComponent> void awaitComponent(BabelNode node, Class<T> type, Runnable missing, Consumer<SortedSet<T>> callback)
      Description copied from interface: NodeStore
      Registers a one-shot callback that executes the next time a component of the requested type is added for the given node, or when resolution explicitly fails.

      This allows channels to avoid synchronous blocking or silently dropping messages when an address is unknown.

      Specified by:
      awaitComponent in interface NodeStore
      Type Parameters:
      T - the type of the component
      Parameters:
      node - the node being resolved
      type - the type of component needed (e.g., IPBabelNodeComponent.class)
      missing - the callback to execute if the component is not currently present
      callback - the action to perform once the component is available, or when resolution fails