Repository navigation
Replies: 1 comment 1 reply
|
Hi!
struct msg_i_am_ready : public so_5::message_t
{
msg_i_am_ready(bool discardable) : m_discardable(discardable) {}
bool so_is_discardable() const noexcept override { return m_discardable; }
...
private:
bool m_discardable;
};This is also possible with a new type doing this boilerplate underneath. However, adding a flag might add 1 byte to the message. This is useful only if the discard status can change dynamically. Otherwise, I would prefer to inherit from a new type to express the intent more explicitly.
|
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
One of the distinctive features of SObjectizer is the lack of guarantees of message delivery to the recipient. The message may be lost for various reasons:
sendcall;Those cases are rare and developers don't usually think about them. But if we want to build a robust software we have to detect such cases and implement some recovery actions or, if recovery is impossible, we have to switch the application in a special state or even terminate it because the application can't work normally.
For example, suppose that we have an agent that collects some tasks (like requests from users) and several worker agents that can do task processing. Every worker sends a
msg_i_am_readymessage to the collector agent. If the collector has a task to execute the collector sends this task to the free worker as amsg_take_taskmessage. The worker receives themsg_take_taskmessage, processes the task and sends a newmsg_i_am_readyback to the collector.Let's suppose that an instance of
msg_i_am_readyis lost for some reason.In such a case the collector will lose a particular worker. If several
msg_i_am_readyare lost then the collector may not dispatch tasks anymore and will become dysfunctional.The good part of the story is that it's not easy to lose the
msg_i_am_readymessage. If we design our collector/worker agents carefully they will be in the same coop and be subscribed at the appropriate moments, so there won't be a case when a worker sendsmsg_i_am_readyand there is no subscriber for it. Nor is there a case when the collector has a state without a handler formsg_i_am_readymessage.If we protect the collector from overloading then SObjectizer will oblige us to determine the limit for msg_i_am_ready and the reaction to exceeding this limit. So we will have an opportunity to use
limit_then_abortto prevent the collector from dysfunctional state.So the most probable case for losing
msg_i_am_readyis the bad_alloc exception from thesendfunction. It's not easy to ignore such an exception.But we make mistakes. We can use the
ignore_exceptionpolicy and std::bad_alloc will break an event-handler in a worker agent but doesn't kill the application. Or we can uselimit_then_dropinstead oflimit_then_abortas overflow action. Or someone refactored the collector agent by introducing a new state and forgets to define an event-handler formsg_i_am_readyin that state. In other words, let's suppose that we have made a mistake that leads to losing ofmsg_i_am_ready.SObjectizer can't help us here. A message can be lost. The application may become dysfunctional as a consequence.
But what if we introduce a new flag for a message/signal? Somewhat like nondiscardable?
If a message is marked as nondiscardable it should be delivered to an event-handler (or message handler in case of
selectfunction for mchains). If there won't be a handler found and the message will be lost without processing then the whole application will be terminated.It may sound a bit harsh, but termination is much better than silent ignorance of the fact that an important message is lost.
How can a message/signal be marked as nondiscardable?
A new virtual method
so_is_discardablecan be added toso_5::message_tclass. It will returnfalseby default. And it can be overridden in an inherited class:A couple of helper classes like
so_5::nondiscarable_message_tandso_5::nondiscardable_signal_tcould be added too:An open question: should the flag nondiscardable be applied to mutable messages only?
All reactions