Action Engine
Loading...
Searching...
No Matches
act::AsyncNode Class Reference

Detailed Description

An asynchronous node in the ActionEngine framework.

This class represents a node that can read and write data asynchronously. It provides methods for consuming data as specific types. The node is backed by a ChunkStore for storing data chunks.

#include <actionengine/nodes/async_node.h>

Public Member Functions

 AsyncNode (std::string_view id="", NodeMap *absl_nullable node_map=nullptr, std::unique_ptr< ChunkStore > chunk_store=nullptr)
 
auto Put (Chunk value, int seq=-1, bool final=false) -> absl::Status
 
auto Put (NodeFragment value) -> absl::Status
 
template<typename T>
auto Put (T value, int seq=-1, bool final=false) -> absl::Status
 
ChunkStoreWriterGetWriter ()
 
auto GetWriterStatus () const -> absl::Status
 
absl::StatusOr< std::optional< Chunk > > Next (std::optional< absl::Duration > timeout=std::nullopt)
 

Constructor & Destructor Documentation

◆ AsyncNode()

act::AsyncNode::AsyncNode ( std::string_view id = "",
NodeMap *absl_nullable node_map = nullptr,
std::unique_ptr< ChunkStore > chunk_store = nullptr )
explicit

Constructs an AsyncNode with the given ID, node map, and chunk store.

Parameters
idThe unique identifier for the node.
node_mapAn optional pointer to a NodeMap for managing multiple nodes.
chunk_storeAn optional unique pointer to a ChunkStore for storing data chunks. If not provided, a default chunk store will be created.

Member Function Documentation

◆ GetWriter()

ChunkStoreWriter & act::AsyncNode::GetWriter ( )
nodiscard

Returns the writer for this AsyncNode.

This method ensures that a writer is created if it does not already exist, so never fails.

Returns
A reference to the ChunkStoreWriter associated with this AsyncNode.

◆ GetWriterStatus()

absl::Status act::AsyncNode::GetWriterStatus ( ) const -> absl::Status
nodiscard

Returns the status of the writer for this AsyncNode.

This method checks if the writer is in a valid state and returns an absl::Status indicating the status of the writer.

Returns
An absl::Status indicating the status of the writer. If the writer is in a valid state, it returns absl::OkStatus(). If there is an error, it returns an appropriate error status.

◆ Next()

absl::StatusOr< std::optional< Chunk > > act::AsyncNode::Next ( std::optional< absl::Duration > timeout = std::nullopt)

Reads the next chunk from the underlying chunk store.

This method reads the next chunk from the store, blocking until a chunk is available or the timeout expires. If no chunk is available within the timeout, it returns an empty optional.

The default associated reader is used, but multiple readers in principle can be created for the same AsyncNode, each with its own options.

Parameters
timeoutAn optional duration to wait for a chunk to become available. If not provided, it defaults to the reader's timeout.
Returns
An absl::StatusOr containing an optional Chunk. If a chunk is available, it will be returned; otherwise, an empty optional is returned.

◆ Put() [1/3]

auto act::AsyncNode::Put ( Chunk value,
int seq = -1,
bool final = false ) -> absl::Status

Enqueues a chunk to be written to underlying chunk store.

Parameters
valueThe chunk to write to the store.
seqThe sequence number of the chunk. If -1, the chunk will be written without a specific sequence number.
finalA flag indicating whether this is the final chunk in a sequence. If true, the chunk will be marked as final, and no more chunks are expected after this one.
Returns
An absl::Status indicating the success or failure of the operation. Writers are asynchronous, so an OK status does not guarantee that the chunk has been written to the store immediately. It only indicates that the chunk has been successfully enqueued for writing.

◆ Put() [2/3]

auto act::AsyncNode::Put ( NodeFragment value) -> absl::Status

Enqueues a NodeFragment to be written to the underlying chunk store.

See Put(Chunk, int, bool) for details on the parameters, which in this case are part of the NodeFragment structure.

Parameters
valueThe NodeFragment to write to the store.
Returns
An absl::Status indicating the success or failure of the operation.

◆ Put() [3/3]

template<typename T>
auto act::AsyncNode::Put ( T value,
int seq = -1,
bool final = false ) -> absl::Status

Enqueues a value to be written to the underlying chunk store.

This method converts the value to a Chunk using ToChunk and then calls Put(Chunk, int, bool) with the converted chunk.

Parameters
valueThe value to write to the store.
seqThe sequence number of the chunk. If -1, the chunk will be written without a specific sequence number.
finalA flag indicating whether this is the final chunk in a sequence.
Returns
An absl::Status indicating the success or failure of the operation. In addition to the failure cases of Put(Chunk, int, bool), this method can also fail if the conversion from T to Chunk fails.

The documentation for this class was generated from the following files: