AMDCallbackCollection< OnCloseExceptionT > Class Template Reference

This helper-class can be used when you have an ice AMD method. More...

#include <ArmarXCore/core/util/distributed/AMDCallbackCollection.h>

Public Types

using ExceptFunction = std::function<void(const std::exception&)>
 
using RespondFunction = std::function<void()>
 

Public Member Functions

template<class IceCallbackT>
void addCallback (IceUtil::Handle< IceCallbackT > cb)
 Adds an callback and processes it depending on the current mode.
 
void addCallback (RespondFunction onRespond, ExceptFunction onExcept)
 Adds an callback and processes it depending on the current mode.
 
 AMDCallbackCollection ()=default
 
void respondeAll ()
 All currently stored callbacks will receive a response.
 
void respondeN (std::size_t n)
 The n oldest callbacks will receive a response.
 
void setAutoResponse (bool doAutoResponse=true)
 setAutoResponse
 
void setAutoThrow (std::unique_ptr< std::exception > except)
 If except is null, the mode will be set to Store if it was Except.
 
void storeFurtherCallbacks ()
 All future callbacks will be stored.
 
void throwAll (const std::exception &except)
 All currently stored callbacks will receive the exception.
 
 ~AMDCallbackCollection ()
 

Detailed Description

template<class OnCloseExceptionT = ServerShuttingDown>
class armarx::AMDCallbackCollection< OnCloseExceptionT >

This helper-class can be used when you have an ice AMD method.

It holds the ice function callbacks or custom fuctions to respond or pass an exception.. Furthermore an excpetion will be passed if this class destroys and some clients are still waiting.

A usecase for this class would be the following scenario: A server S does a long calculation and some clients wait for the result. The server may want to offer a wait function to the clients. Since the server does not want to block threads for waiting the function should be tagged ["amd"] in the slice definition. If a client calls the function, S receives a function callback to send a response or an exception. The server now can use an AMDCallbackCollection to store all callbacks and send an exception or responde to all or some of the stored callbacks.

See also
https://doc.zeroc.com/pages/viewpage.action?pageId=14031073

Member Typedef Documentation

◆ ExceptFunction

template<class OnCloseExceptionT = ServerShuttingDown>
using ExceptFunction = std::function<void(const std::exception&)>

◆ RespondFunction

template<class OnCloseExceptionT = ServerShuttingDown>
using RespondFunction = std::function<void()>

Constructor & Destructor Documentation

◆ AMDCallbackCollection()

template<class OnCloseExceptionT = ServerShuttingDown>
AMDCallbackCollection ( )
default

◆ ~AMDCallbackCollection()

template<class OnCloseExceptionT>
~AMDCallbackCollection ( )
inline

Member Function Documentation

◆ addCallback() [1/2]

template<class OnCloseExceptionT>
template<class IceCallbackT>
void addCallback ( IceUtil::Handle< IceCallbackT > cb)
inline

Adds an callback and processes it depending on the current mode.

The callback is created using the ice_response and ice_exception functions of the callback object.

Parameters
cbThe function callback from ice.

◆ addCallback() [2/2]

template<class OnCloseExceptionT>
void addCallback ( AMDCallbackCollection< OnCloseExceptionT >::RespondFunction onRespond,
AMDCallbackCollection< OnCloseExceptionT >::ExceptFunction onExcept )
inline

Adds an callback and processes it depending on the current mode.

Parameters
onRespondThe function called to responde.
onExceptThe function called on exception.

◆ respondeAll()

template<class OnCloseExceptionT>
void respondeAll ( )
inline

All currently stored callbacks will receive a response.

◆ respondeN()

template<class OnCloseExceptionT>
void respondeN ( std::size_t n)
inline

The n oldest callbacks will receive a response.

Parameters
n

This may be used in an producer/consumer scenario where the producer creates multiple objects.

◆ setAutoResponse()

template<class OnCloseExceptionT>
void setAutoResponse ( bool doAutoResponse = true)
inline

setAutoResponse

Parameters
doAutoResponseIf set the mode will change to Respond. If false the mode will change from Respond to Store

◆ setAutoThrow()

template<class OnCloseExceptionT>
void setAutoThrow ( std::unique_ptr< std::exception > except)
inline

If except is null, the mode will be set to Store if it was Except.

If except is not null, all currently stored and future callbacks will receive the exception.

Parameters
except

◆ storeFurtherCallbacks()

template<class OnCloseExceptionT>
void storeFurtherCallbacks ( )
inline

All future callbacks will be stored.

◆ throwAll()

template<class OnCloseExceptionT>
void throwAll ( const std::exception & except)
inline

All currently stored callbacks will receive the exception.

Parameters
exceptThe exception.

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