-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Sometimes an agent handles a number of messages of the same type. For example, a message msg_incoming_data with a portion of fresh data to process. The problem arises when the agent handles messages slower than the messages are generated. Sometimes a very simple form of overload control is suitable for such a case: just discard all msg_incoming_data messages that are currently in flight, and process only the last one.
Such a case can be easily handled by a special mbox that actually delivers just the last instance of the sent messages. Something like:
class demo final : public so_5::agent_t
{
struct msg_incoming_data final : public so_5::message_t {
const std::string m_data;
msg_incoming_data(std::string data) : m_data{std::move(data)} {}
};
const so_5::mbox_t m_dest;
public:
demo(context_t ctx)
: so_5::agent_t{std::move(ctx)}
, m_dest{so_5::extra::mboxes::last_msg_only::make<msg_incoming_data>(so_direct_mbox())}
{}
...
void so_evt_start() override {
so_5::send<msg_incoming_data>(m_dest, "One");
so_5::send<msg_incoming_data>(m_dest, "Two");
so_5::send<msg_incoming_data>(m_dest, "Three");
}
};In this case only msg_incoming_data with value "Three" has to be delivered, two previous messages will be discarded.
Metadata
Metadata
Assignees
Labels
No labels