|
libbmq b6028b29b733bc7541593d2905a5f79a9f0192fc
|
Provide a value-semantic type usable as an efficient identifier. More...
#include <bdlb_variant.h>#include <bsl_cstdint.h>#include <bsl_iosfwd.h>#include <bsl_memory.h>#include <bslh_hash.h>#include <bsls_assert.h>#include <bsls_types.h>Go to the source code of this file.
Classes | |
| class | BloombergLP::bmqt::CorrelationId |
| struct | BloombergLP::bmqt::CorrelationIdLess |
Namespaces | |
| namespace | BloombergLP |
| namespace | BloombergLP::bmqt |
Functions | |
| bsl::ostream & | BloombergLP::bmqt::operator<< (bsl::ostream &stream, const CorrelationId &rhs) |
| bool | BloombergLP::bmqt::operator== (const CorrelationId &lhs, const CorrelationId &rhs) |
| bool | BloombergLP::bmqt::operator!= (const CorrelationId &lhs, const CorrelationId &rhs) |
| bool | BloombergLP::bmqt::operator< (const CorrelationId &lhs, const CorrelationId &rhs) |
| template<class HASH_ALGORITHM > | |
| void | BloombergLP::bmqt::hashAppend (HASH_ALGORITHM &hashAlgo, const CorrelationId &value) |
This component implements a value-semantic class, bmqt::CorrelationId, which can be used to identify any async operations. The correlationId contains a value (64-bit integer, raw pointer or sharedPtr) supplied by the application or uses an auto-assigned value. The type and the value of the correlationId can be set at construction time and changed later via the setNumeric(), setPointer() and setSharedPointer() methods. Alternatively, an AutoValue can be used to generate a unique correlationId from within the process. The bmqt::CorrelationIdLess comparison functor can be used for storing bmqt::CorrelationId in a map as the key element; and a hash functor specialization is provided in the bsl::hash namespace.
If the application doesn't care about the actual value of the correlation, AutoValue type can be used to create a unique correlationId. An AutoValue correlationId behaves exactly the same as any other type of correlation, with the exception that it's value can not be retrieved (but two correlationId can be still compared equal).
This section illustrates intended use of this component.
Suppose that we have the following asynchronous messaging interface that we want to use to implement a basic request/response class.
First we declare a requester class.
Then, we implement the constructor, setting the message handler on the provided 'Messenger' to our class method.
Now, we implement sendRequest, copying the given callback into a correlationId that is provided to the messenger.
Finally, we implement our message handler, extracting the response callback from the correlationId, and invoking it with the received response message.