Skip to content

EntropyEngine::Core::Concurrency::NodeStateManager

EntropyEngine::Core::Concurrency::NodeStateManager

Section titled “EntropyEngine::Core::Concurrency::NodeStateManager”

Centralized state management for WorkGraph nodes. More…

#include <NodeStateManager.h>

Name
booltransitionState(const NodeHandle & node, NodeState from, NodeState to)
Attempt to transition a node to a new state.
voidresetStats()
Reset all statistics.
voidregisterNode(const NodeHandle & node, NodeState initialState =NodeState::Pending)
Register a node with initial state.
boolisTerminal(const NodeHandle & node) const
Check if a node is in a terminal state.
boolhasActiveNodes() const
Check if any nodes are in non-terminal states.
voidgetStats(WorkGraphStats & stats) const
Get statistics about current state distribution.
const char *getStateName(NodeState state)
Get human-readable name for a state.
NodeStategetState(const NodeHandle & node) const
Get current state of a node.
voidgetNodesInState(NodeState state, const std::vector< NodeHandle > & allNodes, std::vector< NodeHandle > & output) const
Get all nodes in a specific state.
size_tgetMemoryUsage() const
Get memory usage estimate.
voidforceState(const NodeHandle & node, NodeState to)
Force a state transition without validation.
boolcanTransition(NodeState from, NodeState to)
Check if a state transition is valid.
size_tbatchTransition(const std::vector< std::tuple< NodeHandle, NodeState, NodeState > > & updates)
Batch update for multiple nodes.
NodeStateManager(const WorkGraph * graph, Core::EventBus * eventBus =nullptr)
Construct state manager.
class EntropyEngine::Core::Concurrency::NodeStateManager;

Centralized state management for WorkGraph nodes.

This component is responsible for:

  • Validating state transitions
  • Publishing state change events
  • Tracking state statistics
  • Providing thread-safe state queries

Design goals:

  • Minimal memory footprint (suitable for thousands of instances)
  • Lock-free reads where possible
  • Optional event publishing (only if EventBus provided)
bool transitionState(
const NodeHandle & node,
NodeState from,
NodeState to
)

Attempt to transition a node to a new state.

Parameters:

  • node The node to transition
  • from Expected current state (for CAS operation)
  • to Target state

Return: true if transition succeeded, false if current state didn’t match ‘from’

This is the primary method for all state changes. It validates the transition, updates the state atomically, and publishes events if configured.

inline void resetStats()

Reset all statistics.

void registerNode(
const NodeHandle & node,
NodeState initialState =NodeState::Pending
)

Register a node with initial state.

Parameters:

  • node The node to register
  • initialState Initial state (default: Pending)
inline bool isTerminal(
const NodeHandle & node
) const

Check if a node is in a terminal state.

Parameters:

  • node The node to check

Return: true if node is in Completed, Failed, or Cancelled state

inline bool hasActiveNodes() const

Check if any nodes are in non-terminal states.

Return: true if there are pending, ready, scheduled, or executing nodes

inline void getStats(
WorkGraphStats & stats
) const

Get statistics about current state distribution.

Parameters:

  • stats Output parameter for statistics
static inline const char * getStateName(
NodeState state
)

Get human-readable name for a state.

Parameters:

  • state The state to convert

Return: String representation of the state

NodeState getState(
const NodeHandle & node
) const

Get current state of a node.

Parameters:

  • node The node to query

Return: Current state, or Pending if node is invalid

void getNodesInState(
NodeState state,
const std::vector< NodeHandle > & allNodes,
std::vector< NodeHandle > & output
) const

Get all nodes in a specific state.

Parameters:

  • state The state to query
  • allNodes List of all nodes to check
  • output Vector to fill with matching nodes
inline size_t getMemoryUsage() const

Get memory usage estimate.

Return: Approximate memory usage in bytes

void forceState(
const NodeHandle & node,
NodeState to
)

Force a state transition without validation.

Parameters:

  • node The node to transition
  • to Target state

Use sparingly - only for error recovery or initialization

static inline bool canTransition(
NodeState from,
NodeState to
)

Check if a state transition is valid.

Parameters:

  • from Source state
  • to Target state

Return: true if transition is allowed

size_t batchTransition(
const std::vector< std::tuple< NodeHandle, NodeState, NodeState > > & updates
)

Batch update for multiple nodes.

Parameters:

  • updates Vector of (node, from, to) tuples

Return: Number of successful transitions

inline explicit NodeStateManager(
const WorkGraph * graph,
Core::EventBus * eventBus =nullptr
)

Construct state manager.

Parameters:

  • graph The owning WorkGraph (for event context)
  • eventBus Optional event bus for publishing state changes

Updated on 2026-01-26 at 17:14:35 -0500