| Action Engine
             | 
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 | 
| 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.
| stream | The stream to establish the connection with. | 
| connection_handler | The connection handler to use for the connection. If not provided, RunSimpleSession is used. | 
| 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.
| session_id | The ID of the session to retrieve. | 
| 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.
| stream_id | The ID of the stream to retrieve. | 
| 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.
| connection | The connection to join. The connection must be a valid StreamToSessionConnection object that has been established with the service. | 
| 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.
| action_registry | The ActionRegistry to set for the service. |