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

Definition at line 52 of file AMDCallbackCollection.h.

Member Typedef Documentation

◆ ExceptFunction

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

Definition at line 55 of file AMDCallbackCollection.h.

◆ RespondFunction

using RespondFunction = std::function<void()>

Definition at line 56 of file AMDCallbackCollection.h.

Constructor & Destructor Documentation

◆ AMDCallbackCollection()

AMDCallbackCollection ( )
default

◆ ~AMDCallbackCollection()

Definition at line 145 of file AMDCallbackCollection.h.

Member Function Documentation

◆ addCallback() [1/2]

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.

Definition at line 248 of file AMDCallbackCollection.h.

◆ addCallback() [2/2]

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.

Definition at line 151 of file AMDCallbackCollection.h.

+ Here is the caller graph for this function:

◆ respondeAll()

void respondeAll
inline

All currently stored callbacks will receive a response.

Definition at line 198 of file AMDCallbackCollection.h.

◆ respondeN()

void respondeN ( std::size_t  n)
inline

The n oldest callbacks will receive a response.

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

Definition at line 187 of file AMDCallbackCollection.h.

◆ setAutoResponse()

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

Definition at line 169 of file AMDCallbackCollection.h.

+ Here is the caller graph for this function:

◆ setAutoThrow()

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

Definition at line 209 of file AMDCallbackCollection.h.

◆ storeFurtherCallbacks()

void storeFurtherCallbacks
inline

All future callbacks will be stored.

Definition at line 239 of file AMDCallbackCollection.h.

◆ throwAll()

void throwAll ( const std::exception &  except)
inline

All currently stored callbacks will receive the exception.

Parameters
exceptThe exception.

Definition at line 228 of file AMDCallbackCollection.h.


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