Class DefaultNodeStore
java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.DefaultNodeStore
- All Implemented Interfaces:
NodeStore
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault initial capacity for awaiting callbacks.static final intDefault initial capacity for components per node.static final intDefault initial capacity for the node mappings. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a DefaultNodeStore with default expected capacities and default ordering.DefaultNodeStore(int numberOfNodes) Creates a DefaultNodeStore with the specified expected number of nodes and default ordering.DefaultNodeStore(int numberOfNodes, int numberOfAwaits) Creates a DefaultNodeStore with the specified expected number of nodes and awaits, using default ordering.DefaultNodeStore(int numberOfNodes, int numberOfAwaits, @Nullable Comparator<BabelNodeComponent> comparator) Creates a DefaultNodeStore with the specified expected number of nodes, awaits, and component comparator.DefaultNodeStore(int numberOfNodes, @Nullable Comparator<BabelNodeComponent> comparator) Creates a DefaultNodeStore with the specified expected number of nodes and component comparator.DefaultNodeStore(@Nullable Comparator<BabelNodeComponent> comparator) Creates a DefaultNodeStore with default expected capacities and the specified component comparator. -
Method Summary
Modifier and TypeMethodDescriptionaddComponent(BabelNode node, BabelNodeComponent component) Adds a newly discovered component to the store.<T extends BabelNodeComponent>
voidRegisters 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.<T extends BabelNodeComponent>
SortedSet<T> getComponentsOfType(BabelNode node, Class<T> type) Gets all components of a specific type (e.g., IPBabelNodeComponent.class) attached to a node.booleanremoveComponent(BabelNode node, BabelNodeComponent component) Removes a stale or dead component from the store.voidresolutionFailed(BabelNode node, Class<? extends BabelNodeComponent> type) Signals that the resolver protocol failed to find the requested component type for the given node (e.g., discovery timeout).voidresolutionSuccessuful(BabelNode node, Class<? extends BabelNodeComponent> type) Signals that the resolver protocol successfully resolved the requested component type for the given node.
-
Field Details
-
DEFAULT_NUMBER_OF_NODES
public static final int DEFAULT_NUMBER_OF_NODESDefault initial capacity for the node mappings.- See Also:
-
DEFAULT_NUMBER_OF_COMPONENTS
public static final int DEFAULT_NUMBER_OF_COMPONENTSDefault initial capacity for components per node.- See Also:
-
DEFAULT_NUMBER_OF_AWAITS
public static final int DEFAULT_NUMBER_OF_AWAITSDefault 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 nodesnumberOfAwaits- the expected number of awaits
-
DefaultNodeStore
Creates a DefaultNodeStore with default expected capacities and the specified component comparator.- Parameters:
comparator- the comparator to order components with, ornullto use default ordering
-
DefaultNodeStore
Creates a DefaultNodeStore with the specified expected number of nodes and component comparator.- Parameters:
numberOfNodes- the expected number of nodescomparator- the comparator to order components with, ornullto 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 nodesnumberOfAwaits- the expected number of awaitscomparator- the comparator to order components with, ornullto use default ordering
-
-
Method Details
-
getComponentsOfType
public <T extends BabelNodeComponent> SortedSet<T> getComponentsOfType(BabelNode node, Class<T> type) Description copied from interface:NodeStoreGets 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:
getComponentsOfTypein interfaceNodeStore- Type Parameters:
T- the type of the component- Parameters:
node- the node to querytype- the class representing the component type- Returns:
- a sorted set of components of the requested type attached to the node
-
addComponent
Description copied from interface:NodeStoreAdds a newly discovered component to the store. Invoking this will trigger any callbacks registered viaNodeStore.awaitComponent(BabelNode, Class, Runnable, Consumer).- Specified by:
addComponentin interfaceNodeStore- Parameters:
node- the node to which the component is addedcomponent- the component to add- Returns:
- a sorted set of components attached to the node after the addition
-
removeComponent
Description copied from interface:NodeStoreRemoves a stale or dead component from the store. Essential for evicting IPs that no longer respond to heartbeats.- Specified by:
removeComponentin interfaceNodeStore- Parameters:
node- the node from which the component is removedcomponent- the component to remove- Returns:
- true if the component was present and removed, false otherwise
-
resolutionFailed
Description copied from interface:NodeStoreSignals 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 viaNodeStore.awaitComponent(BabelNode, Class, Runnable, Consumer)with an empty sorted set.- Specified by:
resolutionFailedin interfaceNodeStore- Parameters:
node- the node for which resolution failedtype- the type of component that failed to resolve
-
resolutionSuccessuful
Description copied from interface:NodeStoreSignals that the resolver protocol successfully resolved the requested component type for the given node. Invoking this will trigger any callbacks registered viaNodeStore.awaitComponent(BabelNode, Class, Runnable, Consumer)with the resolved components.- Specified by:
resolutionSuccessufulin interfaceNodeStore- Parameters:
node- the node for which resolution succeededtype- 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:NodeStoreRegisters 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:
awaitComponentin interfaceNodeStore- Type Parameters:
T- the type of the component- Parameters:
node- the node being resolvedtype- the type of component needed (e.g., IPBabelNodeComponent.class)missing- the callback to execute if the component is not currently presentcallback- the action to perform once the component is available, or when resolution fails
-