Skip to content

A possibility to subscribe a event-handler to a base type of a message #25

@eao197

Description

@eao197

NOTE. This issue is just a reminder that SObjectizer needs a solution for use-cases like described in #24
I don't know how and when this will be implemented (and can it be implemented at all), but the reminder will help to form scope for a new SObjectizer's release when appropriate resources will be available.

The task is to allow writing something like that:

class image_base : public so_5::message_t {...};
class image_vendor_A : public image_base {...};
class image_vendor_B : public image_base {...};
class image_vendor_C : public image_base {...};

// The first handler.
void first_handler::so_define_agent() {
  so_subscribe_self()
    // Handles only one type of images.
    .event([this](mhood_t<image_vendor_A> cmd) {...})
    // All other messages are just logged.
    .event([this](mhood_t<image_base> cmd) { log_image(*cmd); });
}
...
// Another handler.
void second_handler::so_define_agent() {
  so_subscribe_self()
    // Handles two types.
    .event([this](mhood_t<image_vendor_B> cmd) {...})
    .event([this](mhood_t<image_vendor_C> cmd) {...})
    // All other messages are just redirected as is.
    .event([this](mhood_t<image_base> cmd) {
      so_5::send(new_dest, cmd);
    });
}

// Yet another handler.
void third_handler::so_define_agent() {
  // Redirects all messages to another destination.
  so_subscribe_self().event([this](mhood_t<image_base> cmd) {
    so_5::send(new_dest, cmd);
  }
}

Additional requirement. It'll be great to have that functionality for handling messages from mchains too:

so_5::receive(from(mchain).handle_all(),
  [](so_5::mhood_t<image_vendor_A> cmd) {...},
  [](so_5::mhood_t<image_vendor_C> cmd) {...},
  [new_dest](so_5::mhood_t<image_base> cmd) { so_5::send(new_dest, cmd); });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions