Stiffstream / sobjectizer

An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.

Home Page:https://stiffstream.com/en/products/sobjectizer.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A possibility to drop all subscriptions with total deactivation of an agent?

eao197 opened this issue · comments

NOTE: it just an idea inspired by #28 . It may not get any implementation. I fix it in issues to return to it when there will be a possibility.

Sometimes it's necessary to deactivate some agent and keep it in that deactivated state until the coop of the agent will be deregistered.

A developer can do that by using an additional state without any subscriptions:

class demo : public so_5::agent_t
{
  state_t st_deactivated{this};
  ...
  void on_some_event() {
    if(has_to_be_deactivated())
      this >>= st_deactivated; // Agent won't react to new messages anymore.
    ...
  }
};

But this approach has a drawback: anyone can still send messages to that agent and some resources will be consumed. It's because all subscriptions of the agent remain valid and messages sent to the deactivated agent will be stored to the agent's event-queue, extracted, checked for the presence of an event-handler in the current state, and only then those messages will be ignored.

It seems that SObjectizer can do better. There is already a special invisible state awaiting_deregistration_state that is used when an agent throws an exception, but the exception reaction is set to deregister_coop_on_exception. So we can provide a new agent_t's method so_deactivate_agent that does the following actions:

  • drops all the subscriptions to avoid resources consumptions if someone tries to send a message to the deactivated agent;
  • switches the agent to awaiting_deregistration_state. In that state, the agent will wait for the deregistration of its coop.

Or we can just add a new method so_drop_all_subscriptions to remove all subscriptions regardless of the states. Including deadletter_handlers.

Will be a part of upcoming v.5.7.3.