xentara-plugin v1.2.1
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::process::Microservice Class Referenceabstract

A microservice for a Xentara system. More...

#include <process/Microservice.hpp>

+ Inheritance diagram for xentara::process::Microservice:

Classes

class  FallbackConfigHandler
 A helper object used to handle config parameters unknown to the sub class. More...
 

Public Member Functions

virtual internal ~Microservice ()=0
 Virtual destructor.
 
auto name () const -> std::string
 Gets the name of the microservice.
 
auto primaryKey () const -> std::string
 Gets the primary key of the microservice.
 
auto uuid () const -> utils::core::Uuid
 Gets the UUID of the microservice.
 
virtual auto createSubservice (const MicroserviceClass &microserviceClass, plugin::SharedFactory< Microservice > &factory) -> std::shared_ptr< Microservice >
 Called by the framework to create a new subservice of this microservice.
 
virtual auto resolveAttribute (std::string_view name) -> const model::Attribute *
 Called by the framework to resolve an attribute with a specific name.
 
virtual auto resolveTask (std::string_view name) -> std::shared_ptr< process::Task >
 Called by the framework to resolve a task with a specific name.
 
virtual auto resolveEvent (std::string_view name) -> std::shared_ptr< process::Event >
 Called by the framework to resolve an event with a specific name.
 
virtual auto readHandle (const model::Attribute &attribute) const noexcept -> data::ReadHandle
 Called by the framework to get a read handle for a specific attribute.
 
virtual auto writeHandle (const model::Attribute &attribute) noexcept -> data::WriteHandle
 Called by the framework to get a write handle for a specific attribute.
 
- Public Member Functions inherited from xentara::utils::tools::DisableCopy
constexpr DisableCopy () noexcept=default
 
 DisableCopy (const DisableCopy &)=delete
 
DisableCopyoperator= (const DisableCopy &)=delete
 

Protected Types

using ConfigIntializer = memory::Initializer< memory::Array >
 Type alias for an initializer for the configuration.
 

Protected Member Functions

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.
 

Detailed Description

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

Member Typedef Documentation

◆ ConfigIntializer

Type alias for an initializer for the configuration.

Constructor & Destructor Documentation

◆ ~Microservice()

xentara::process::Microservice::~Microservice ( )
pure virtualdefault

Virtual destructor.

Member Function Documentation

◆ 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()

auto xentara::process::Microservice::configBlock ( ) const -> const memory::ArrayBlock &
protectednoexcept

Gets the memory block that the configuration is stored in.

◆ createSubservice()

virtual auto xentara::process::Microservice::createSubservice ( const MicroserviceClass microserviceClass,
plugin::SharedFactory< Microservice > &  factory 
) -> std::shared_ptr< Microservice >
virtual

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
microserviceClassThe class for the new microservice
factoryThe 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_errorThe function must throw this exception (or a suitable subclass) if an error occurs
See also
Creating Plugin Element Objects

◆ loadConfig()

virtual auto xentara::process::Microservice::loadConfig ( const ConfigIntializer initializer,
utils::json::decoder::Object jsonObject,
config::Resolver resolver,
const FallbackConfigHandler fallbackHandler 
) -> void
protectedpure virtual

Called by the framework to load the microservice's configuration from a JSON object.

Parameters
initializerAn 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.
jsonObjectThe JSON object
resolverAn object that allows you to resolve cross references
fallbackHandlerAn 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_errorThe 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_errorThe 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_errorThe 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_errorThe 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()

virtual auto xentara::process::Microservice::readHandle ( const model::Attribute attribute) const -> data::ReadHandle
virtualnoexcept

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
attributeThe 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_errorThe 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()

virtual auto xentara::process::Microservice::resolveAttribute ( std::string_view  name) -> const model::Attribute *
virtual

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
nameThe 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_errorThe function must throw this exception (or a suitable subclass) if an error occurs
See also
Publishing Attributes
Examples
PublishingConfigAttributes.cpp

◆ resolveEvent()

virtual auto xentara::process::Microservice::resolveEvent ( std::string_view  name) -> std::shared_ptr< process::Event >
virtual

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():

return std::shared_ptr(sharedFromThis(), &_myEvent);

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
nameThe 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_errorThe function must throw this exception (or a suitable subclass) if an error occurs
See also
Publishing Events

◆ resolveTask()

virtual auto xentara::process::Microservice::resolveTask ( std::string_view  name) -> std::shared_ptr< process::Task >
virtual

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():

return std::shared_ptr(sharedFromThis(), &_myTask);

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
nameThe 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_errorThe function must throw this exception (or a suitable subclass) if an error occurs
See also
Publishing Tasks

◆ uuid()

auto xentara::process::Microservice::uuid ( ) const -> utils::core::Uuid

Gets the UUID of the microservice.

Note
The UUID is only known once the configuration of the microservice has been loaded.

◆ writeHandle()

virtual auto xentara::process::Microservice::writeHandle ( const model::Attribute attribute) -> data::WriteHandle
virtualnoexcept

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
attributeThe 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