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

Detailed Description

The ActionEngine service class. Manages sessions, streams, and connections.

This class provides methods to establish and join connections, as well as to set the action registry.

The service can be instantiated with an optional action registry and connection handler. If the action registry is not provided, it will be initialized with an empty registry. If the connection handler is not provided, it will be initialized with RunSimpleSession. The chunk store factory is used to create chunk stores for new sessions. By default, LocalChunkStores are created.

This class is thread-safe. Whenever a connection is joined, it is moved out of the Service object under a lock, and the Service object is no longer responsible for managing it. Action registry is set under a lock, and getters use read locks.

The Service object can be destroyed at any time, and it will take care of joining all the connections and cleaning up all the fibers. However, the Service object itself will not be destroyed until all the connections have been joined.

#include <actionengine/service/service.h>

Public Member Functions

auto GetStream (std::string_view stream_id) const -> WireStream *absl_nullable
 
auto GetSession (std::string_view session_id) const -> Session *absl_nullable
 
auto EstablishConnection (std::shared_ptr< WireStream > &&stream, ConnectionHandler connection_handler=nullptr) -> absl::StatusOr< std::shared_ptr< StreamToSessionConnection > >
 
auto JoinConnection (StreamToSessionConnection *absl_nonnull connection) -> absl::Status
 
auto SetActionRegistry (const ActionRegistry &action_registry) const -> void
 

Member Function Documentation

◆ EstablishConnection()

absl::StatusOr< std::shared_ptr< StreamToSessionConnection > > act::Service::EstablishConnection ( std::shared_ptr< WireStream > && stream,
ConnectionHandler connection_handler = nullptr ) -> absl::StatusOr<std::shared_ptr<StreamToSessionConnection>>

Establishes a connection with the given stream and returns a StreamToSessionConnection object representing the connection.

The stream must be a valid WireStream instance that is already connected and ready to send and receive messages. The connection handler is used to handle the connection, and if it is not provided, the default handler RunSimpleSession is used.

The lifetime of the passed WireStream is guaranteed to be at least as long as the connection, so it is safe to use the stream anywhere in the connection handler.

Parameters
streamThe stream to establish the connection with.
connection_handlerThe connection handler to use for the connection. If not provided, RunSimpleSession is used.
Returns
A StreamToSessionConnection object representing the established connection, or an error status if the connection could not be established.

◆ GetSession()

Session *absl_nullable act::Service::GetSession ( std::string_view session_id) const -> Session* absl_nullable

Returns the session with the given ID managed by this service.

Parameters
session_idThe ID of the session to retrieve.
Returns
A pointer to the Session if it exists, or nullptr if it does not.

◆ GetStream()

WireStream *absl_nullable act::Service::GetStream ( std::string_view stream_id) const -> WireStream* absl_nullable

Returns the stream with the given ID managed by this service.

Parameters
stream_idThe ID of the stream to retrieve.
Returns
A pointer to the WireStream if it exists, or nullptr if it does not.

◆ JoinConnection()

absl::Status act::Service::JoinConnection ( StreamToSessionConnection *absl_nonnull connection) -> absl::Status

Joins an existing connection to the service.

This method is used to join a connection that has already been established and is being managed by the service. It will move the connection out of the service, so it is no longer responsible for managing it.

It is unsafe to pass a connection that has not been established by the same service, as it will not be able to join it properly and may return an error, as well as block indefinitely or even crash the application.

Parameters
connectionThe connection to join. The connection must be a valid StreamToSessionConnection object that has been established with the service.
Returns
An absl::Status indicating the success or failure of the operation.
Note
This method will, by intention, block. Therefore, you should call it only when you are sure that the connection is ready to be joined, i.e. will not proceed indefinitely.

◆ SetActionRegistry()

void act::Service::SetActionRegistry ( const ActionRegistry & action_registry) const -> void

Sets the action registry for the service.

This method allows you to set a custom action registry for the service. The action registry is used to resolve ActionMessages into Actions that can be executed in the context of a session.

This method does not introduce a race with connection handlers, and any ActionMessage received after this call succeeds will be resolved using the new action registry. This can be used to dynamically change the behavior of the service at runtime, for example, to add, remove or modify actions that can be executed in the context of a session.

No stream is interrupted by this call, so interesting applications are available, such as rapid prototyping of new actions in a Jupyter notebook.

Parameters
action_registryThe ActionRegistry to set for the service.

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