hmbdc
simplify-high-performance-messaging-programming
|
synchronous request reply interface for the Network Sender More...
#include <RequestReply.hpp>
Public Member Functions | |
template<RequestC RequestT, typename ReplyContext , typename ReplyHandler > | |
bool | requestReply (RequestT &&request, ReplyContext &ctx, ReplyHandler &replyHandler, time::Duration timeout=time::Duration::seconds(0xffffffff)) |
The caller is blocked until the replies to this request are heard and processed. Just like regular Messages REQUEST is sent out to Clients through the CcSender. More... | |
template<MessageC M> | |
void | sendReply (REPLY< M > &&reply) |
part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior. More... | |
template<MessageC M> | |
void | sendReply (REPLY< M > const &reply) |
part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior. More... | |
synchronous request reply interface for the Network Sender
CcSender | concrete Sender |
|
inline |
The caller is blocked until the replies to this request are heard and processed. Just like regular Messages REQUEST is sent out to Clients through the CcSender.
MessageC | Message the type wrapped in REQUEST<> template |
ReplyContext | the Context Type that ReplyT messages need to be able to reach, it needs to have a pool template <typename Ctx> struct Auctioner : Client<Auctioner<Ctx>, REPLY<Bid>> { Auctioner(Ctx& ctx, char const ** items, size_t count) : ctx_(ctx) , sender_(NetCtx::instance().getSender(AUCTION_TOPIC)) , items_(items) , count_(count) { } void invokedCb(uint16_t) { if (current_ == count_) throw 0; //all done REQUEST<AuctionItem> ra; strcpy(ra.request.description, items_[current_++]); //blocking for a second to collect all bids in this period //for this item sender_->requestReply(ra , ctx_ , *this , time::Duration::seconds(1)); if (highestBidder_.size()) { std::cout << ra.request.description << " sold at " << (int)highestPrice_ << " to " << highestBidder_ << std::endl; } else { std::cout << ra.request.description << " bought-in " << std::endl; } highestPrice_ = 0; highestBidder_ = std::string(); } //when replies come back - handle it here since //the Client regular callbacks is blocked on requestReply() // - it is safe to use any data here //this Bid is garanteed by hmbdc to be for the current Item, //request-reply ensures the above void handleReplyCb(Bid const& bid) { if (bid.price > highestPrice_) { highestPrice_ = bid.price; highestBidder_ = std::string(bid.bidder); } } private: Ctx& ctx_; Sender* sender_; char const** items_; size_t count_; size_t current_ = 0; uint8_t highestPrice_ = 0; std::string highestBidder_; }; |
ReplyHandler | type for how to handle the replies. example of a handler expect two steps replies for requestReply call: struct ClientAlsoHandlesReplies : Client<ClientAlsoHandlesReplies, REPLY<Reply0>, REPLY<Reply1>, OtherMsg> { void handleReplyCb(Reply0 const&){ // got step 1 reply } void handleReplyCb(Reply1 const&){ // got step 2 reply // throw to unblock the requestReply call } |
|
inline |
part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior.
MessageC | Message the type wrapped in REPLY<> template example usage: REPLY<Response> resp(req, req.request); //see REPLY<> ctor myCtx.sendReply(resp); |
|
inline |
part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior.
MessageC | Message the type wrapped in REPLY<> template example usage: REPLY<Response> resp(req, req.request); //see REPLY<> ctor myCtx.sendReply(resp); |