A microservice for a Xentara system.
More...
#include <process/Microservice.hpp>
|
virtual auto | loadConfig (const ConfigIntializer &initializer, utils::json::decoder::Object &jsonObject, config::Resolver &resolver, const FallbackConfigHandler &fallbackHandler) -> void=0 |
| Called by the framework to load the microservice's configuration from a JSON object.
|
|
virtual auto | realize () -> void |
| Called by the framework once all references have been resolved.
|
|
virtual auto | postRealize () -> void |
| Called by the framework after all subservices have been realized.
|
|
virtual auto | prepare () -> void |
| Called by the framework to prepare the microservice for operation.
|
|
virtual auto | postPrepare () -> void |
| Called by the framework after all subservices have been prepared.
|
|
virtual auto | preCleanup () -> void |
| Called by the framework before the subservices are cleaned up.
|
|
virtual auto | cleanup () -> void |
| Called by the framework to clean up the microservice after operation.
|
|
auto | configBlock () const noexcept -> const memory::ArrayBlock & |
| Gets the memory block that the configuration is stored in.
|
|
A microservice for a Xentara system.
A microservice is an object that provides some sort of functionality can can be hooked into process pipelines.
- See also
- Microservices
-
Microservices in the Xentara user manual
◆ ConfigIntializer
Type alias for an initializer for the configuration.
◆ ~Microservice()
xentara::process::Microservice::~Microservice |
( |
| ) |
|
|
pure virtualdefault |
◆ cleanup()
virtual auto xentara::process::Microservice::cleanup |
( |
| ) |
-> void |
|
protectedvirtual |
Called by the framework to clean up the microservice after operation.
This method is called by the framework after Xentara has completely shut down.
This method is called after the cleanup() method of any subservices. You can override preCleanup() if you need to perform actions before the subservices are cleaned up.
- Default Implementation
- The default implementation does nothing.
◆ configBlock()
Gets the memory block that the configuration is stored in.
◆ createSubservice()
Called by the framework to create a new subservice of this microservice.
The implementation for this method must use the given factory to create a new microservice of the given microservice class:
return factory.makeShared<MySubservice>();
If your driver requires access to the subservice later, you must store an std::weak_ptr to it somewhere.
The framework will call loadConfig() on the newly created microservice.
- Default Implementation
- The default implementation returns nullptr, denoting that the microservice does not support subservices.
- Parameters
-
microserviceClass | The class for the new microservice |
factory | The factory that must be used to create the microservice |
- Returns
- The newly created microservice, or nullptr if the microservice does not support subservices of the given class
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- See also
- Creating Plugin Element Objects
◆ loadConfig()
Called by the framework to load the microservice's configuration from a JSON object.
- Parameters
-
initializer | An initializer object for the memory block that contains the configuration. Use this object to access the storage for any configuration attributes you added to the config() array in the microservice class. |
jsonObject | The JSON object |
resolver | An object that allows you to resolve cross references |
fallbackHandler | An object that handles config parameters unknown to the sub class. You should call the function call operator of this object for any config parameters you do not recognize. |
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- See also
- Loading Element Configs
- Examples
- LoadingElementConfig.cpp
◆ name()
auto xentara::process::Microservice::name |
( |
| ) |
const -> std::string |
Gets the name of the microservice.
- Note
- The name is only known once the configuration of the microservice has been loaded.
- Returns
- The name of the microservice, in UTF-8 encoding.
◆ postPrepare()
virtual auto xentara::process::Microservice::postPrepare |
( |
| ) |
-> void |
|
protectedvirtual |
Called by the framework after all subservices have been prepared.
This method is similar to the prepare() method, but it is called after the prepare() method of subservices.
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- Default Implementation
- The default implementation does nothing.
◆ postRealize()
virtual auto xentara::process::Microservice::postRealize |
( |
| ) |
-> void |
|
protectedvirtual |
Called by the framework after all subservices have been realized.
This method is similar to the realize() method, but it is called after the realize() method of subservices.
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- Default Implementation
- The default implementation does nothing.
◆ preCleanup()
virtual auto xentara::process::Microservice::preCleanup |
( |
| ) |
-> void |
|
protectedvirtual |
Called by the framework before the subservices are cleaned up.
This method is similar to the cleanup() method, but it is called before the cleanup() method of subservices.
- Default Implementation
- The default implementation does nothing.
◆ prepare()
virtual auto xentara::process::Microservice::prepare |
( |
| ) |
-> void |
|
protectedvirtual |
Called by the framework to prepare the microservice for operation.
This method is called by the framework after all objects have been realized, but before any processing is done. It allows you to prepare the object for operation. This is the place where read and write handles for attributes should be fetched, for example.
This method is called before the prepare() method of any subservices. You can override postPrepare() if you need to perform actions after all subservices have been prepared.
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- Default Implementation
- The default implementation does nothing.
- See also
- Loading Element Configs
◆ primaryKey()
auto xentara::process::Microservice::primaryKey |
( |
| ) |
const -> std::string |
Gets the primary key of the microservice.
- Note
- The primary key is only fully known once the entire configuration has been loaded.
- Returns
- The primary key of the microservice, in UTF-8 encoding.
◆ readHandle()
Called by the framework to get a read handle for a specific attribute.
The implementation for this method must return a read handle for the given attribute's value.
- Default Implementation
- The default implementation returns an error handle with error data::ReadHandle::Error::Unknown.
- Parameters
-
attribute | The desired attribute. This will never be one of the standard configuration attributes, as these are handled automatically by the framework. |
- Returns
- A read handle for the attribute, or an error handle with an appropriate error code on error
- See also
- Publishing Attributes
- Examples
- PublishingConfigAttributes.cpp
◆ realize()
virtual auto xentara::process::Microservice::realize |
( |
| ) |
-> void |
|
protectedvirtual |
Called by the framework once all references have been resolved.
This method is called by the framework after the configuration has been completely loaded and all references have been resolved, but before the objects are prepared for processing. Use this function to perform initialization that requires access to the objects you submitted to the resolver in loadConfig().
This method is called before the realize() method of any subservices. You can override postRealize() if you need to perform actions after all subservices have been realized.
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- Default Implementation
- The default implementation does nothing.
- See also
- Loading Element Configs
◆ resolveAttribute()
Called by the framework to resolve an attribute with a specific name.
The implementation for this method must return a reference to the attribute with the given name, if the microservice supports it.
Attributes are always resolved after Xentara model elements. This means that when this function is called, all references to Xentara model elements you submitted in loadConfig() have already been resolved.
- Default Implementation
- The default implementation returns nullptr, denoting that the microservice does not provide an attribute with the given name.
- Parameters
-
name | The name of the desired attribute, in UTF-8 encoding. This will never be one of the standard configuration attributes, as these are resolved automatically by the framework. |
- Returns
- A pointer to the attribute description, or nullptr if the microservice does not provide an attribute with the given name
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- See also
- Publishing Attributes
- Examples
- PublishingConfigAttributes.cpp
◆ resolveEvent()
Called by the framework to resolve an event with a specific name.
The implementation for this method must return a pointer to the event with the given name. You can either create the event on demand from within this function, or return a pointer to an existing event.
If the event you which to return is not a shared object itself, but a regular member of the microservice, you can derive your microservice class from xentara::plugin::EnableSharedFromThis and use the aliasing constructor (8) of std::shared_ptr together with sharedFromThis():
Events are always resolved after Xentara model elements. This means that when this function is called, all references to Xentara model elements you submitted in loadConfig() have already been resolved.
- Default Implementation
- The default implementation returns nullptr, denoting that the microservice does not provide an event with the given name.
- Parameters
-
name | The name of the desired event, in UTF-8 encoding |
- Returns
- A pointer to the event, or nullptr if the microservice does not provide an event with the given name
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- See also
- Publishing Events
◆ resolveTask()
Called by the framework to resolve a task with a specific name.
The implementation for this method must return a pointer to the task with the given name. You can either create the task on demand from within this function, or return a pointer to an existing task.
If the task you which to return is not a shared object itself, but a regular member of the microservice, you can derive your microservice class from xentara::plugin::EnableSharedFromThis and use the aliasing constructor (8) of std::shared_ptr together with sharedFromThis():
Tasks are always resolved after Xentara model elements. This means that when this function is called, all references to Xentara model elements you submitted in loadConfig() have already been resolved.
- Default Implementation
- The default implementation returns nullptr, denoting that the microservice does not provide a task with the given name.
- Parameters
-
name | The name of the desired task, in UTF-8 encoding |
- Returns
- A pointer to the task, or nullptr if the microservice does not provide a task with the given name
- Exceptions
-
std::runtime_error | The function must throw this exception (or a suitable subclass) if an error occurs |
- See also
- Publishing Tasks
◆ uuid()
Gets the UUID of the microservice.
- Note
- The UUID is only known once the configuration of the microservice has been loaded.
◆ writeHandle()
Called by the framework to get a write handle for a specific attribute.
The implementation for this method must return a write handle for the given attribute's value.
- Default Implementation
- The default implementation returns an error handle with error data::WriteHandle::Error::Unknown.
- Parameters
-
attribute | The desired attribute. This will never be one of the standard configuration attributes, as these are handled automatically by the framework. |
- Returns
- A write handle for the attribute, or an error handle with an appropriate error code on error
- See also
- Publishing Attributes