Apache Celix  latest
Apache Celix is a framework for C, C++14 and C++17 to develop dynamic modular software applications using component and in-process service-oriented programming.
Public Member Functions | Friends | List of all members
celix::ServiceRegistrationBuilder< I > Class Template Reference

Fluent builder API to build a new service registration for a service. More...

#include <ServiceRegistrationBuilder.h>

Public Member Functions

 ServiceRegistrationBuilder (std::shared_ptr< celix_bundle_context_t > _cCtx, std::shared_ptr< I > _svc, std::string _name, bool _registerAsync=true, bool _unregisterAsync=true)
 
ServiceRegistrationBuilderoperator= (ServiceRegistrationBuilder &&)=delete
 
 ServiceRegistrationBuilder (const ServiceRegistrationBuilder &)=delete
 
ServiceRegistrationBuilder operator= (const ServiceRegistrationBuilder &)=delete
 
ServiceRegistrationBuildersetVersion (std::string v)
 Set the service version. More...
 
template<typename T >
ServiceRegistrationBuilderaddProperty (const std::string &key, T &&value)
 Add a property to the service properties. More...
 
ServiceRegistrationBuildersetProperties (celix::Properties p)
 Set the service properties. More...
 
ServiceRegistrationBuilderaddProperties (const celix::Properties &props)
 Add the properties to the service properties. More...
 
ServiceRegistrationBuilderaddOnRegistered (std::function< void(ServiceRegistration &)> callback)
 Adds an on registered callback for the service registration. More...
 
ServiceRegistrationBuilderaddOnUnregistered (std::function< void(ServiceRegistration &)> callback)
 Adds an on unregistered callback for the service registration. More...
 
ServiceRegistrationBuildersetRegisterAsync (bool async)
 Configure if the service registration will be done synchronized or asynchronized. More...
 
ServiceRegistrationBuildersetUnregisterAsync (bool async)
 Configure if the service un-registration will be done synchronized or asynchronized. More...
 
std::shared_ptr< ServiceRegistrationbuild ()
 "Builds" the service registration and return a ServiceRegistration. More...
 

Friends

class BundleContext
 

Detailed Description

template<typename I>
class celix::ServiceRegistrationBuilder< I >

Fluent builder API to build a new service registration for a service.

See also
celix::BundleContext::registerService for more info.
Template Parameters
IThe service type (Note should be the abstract interface, not the interface implementer)
Note
Not thread safe.

Constructor & Destructor Documentation

◆ ServiceRegistrationBuilder() [1/2]

template<typename I >
celix::ServiceRegistrationBuilder< I >::ServiceRegistrationBuilder ( std::shared_ptr< celix_bundle_context_t >  _cCtx,
std::shared_ptr< I >  _svc,
std::string  _name,
bool  _registerAsync = true,
bool  _unregisterAsync = true 
)
inline

◆ ServiceRegistrationBuilder() [2/2]

template<typename I >
celix::ServiceRegistrationBuilder< I >::ServiceRegistrationBuilder ( const ServiceRegistrationBuilder< I > &  )
delete

Member Function Documentation

◆ addOnRegistered()

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::addOnRegistered ( std::function< void(ServiceRegistration &)>  callback)
inline

Adds an on registered callback for the service registration.

This callback will be called on the Celix event thread when the service is registered (REGISTERED state)

◆ addOnUnregistered()

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::addOnUnregistered ( std::function< void(ServiceRegistration &)>  callback)
inline

Adds an on unregistered callback for the service registration.

This callback will be called on the Celix event thread when the service is unregistered (UNREGISTERED state)

◆ addProperties()

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::addProperties ( const celix::Properties &  props)
inline

Add the properties to the service properties.

Note this call will add these properties to the already set properties. If a key is already present the value will be overridden.

◆ addProperty()

template<typename I >
template<typename T >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::addProperty ( const std::string &  key,
T &&  value 
)
inline

Add a property to the service properties.

If a key is already present the value will be overridden.

◆ build()

template<typename I >
std::shared_ptr<ServiceRegistration> celix::ServiceRegistrationBuilder< I >::build ( )
inline

"Builds" the service registration and return a ServiceRegistration.

The ServiceRegistration will register the service to the Celix framework and unregister the service if the shared ptr for the ServiceRegistration goes out of scope.

◆ operator=() [1/2]

template<typename I >
ServiceRegistrationBuilder celix::ServiceRegistrationBuilder< I >::operator= ( const ServiceRegistrationBuilder< I > &  )
delete

◆ operator=() [2/2]

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::operator= ( ServiceRegistrationBuilder< I > &&  )
delete

◆ setProperties()

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::setProperties ( celix::Properties  p)
inline

Set the service properties.

Note this call will clear already set properties.

◆ setRegisterAsync()

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::setRegisterAsync ( bool  async)
inline

Configure if the service registration will be done synchronized or asynchronized.

When a service registration is done synchronized the underlining service will be registered in the Celix framework (and all service trackers will have been informed) when the build() returns. For asynchronized the build() will not wait until this is done.

The benefit of synchronized is the user is ensured a service registration is completely done, but extra care has te be taking into account to prevent deadlocks: lock object -> register service -> trigger service tracker -> trying to update a locked object.

The benefit of asynchronized is that service registration can safely be done inside a lock.

Default behavior is asynchronized.

◆ setUnregisterAsync()

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::setUnregisterAsync ( bool  async)
inline

Configure if the service un-registration will be done synchronized or asynchronized.

When a service un-registration is done synchronized the underlining service will be unregistered in the Celix framework (and all service trackers will have been informed) when the ServiceRegistration::unregister is called of when the ServiceRegistration goes out of scope (with a still REGISTERED service). For asynchronized this will be done asynchronously and the actual ServiceRegistration object will only be deleted if the un-registration is completed async.

The benefit of synchronized is the user is ensured a service un-registration is completely done when calling unregister() / letting ServiceRegistration out of scope, but extra care has te be taking into account to prevent deadlocks: lock object -> unregister service -> trigger service tracker -> trying to update a locked object.

The benefit of asynchronized is that service un-registration can safely be called inside a lock.

Default behavior is asynchronized.

◆ setVersion()

template<typename I >
ServiceRegistrationBuilder& celix::ServiceRegistrationBuilder< I >::setVersion ( std::string  v)
inline

Set the service version.

This will lead to a 'service.version' service property.

Friends And Related Function Documentation

◆ BundleContext

template<typename I >
friend class BundleContext
friend

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