Giter Club home page Giter Club logo

Comments (4)

eao197 avatar eao197 commented on September 28, 2024

Hi!

There are two different cases:

  1. You have to sequentially handle N incoming messages and only then do something. There is no out-of-the-box solution to that task. You have to count handled messages by yourself.
  2. You have to collect N incoming messages and only then do something with them. In that case, you can take a look at so_5::extra::mboxes::collecting_mbox.

from sobjectizer.

ilpropheta avatar ilpropheta commented on September 28, 2024

Thanks! The second scenario is what I need and I will have a look at collecting_mbox.

I have another related question and I would like to share a bit of the context.

I have an application that grabs images from a camera and sends them to one mailbox. Some agents can subscribe to this mailbox and process the stream of images independently. A classical SPMC scenario. For instance, one agent can save the stream to the disk, another one can perform some statistics on the pixels, etc. This works nicely:

Grabber -> mbox
              <-- agent 1
              <-- agent 2
              <-- agent 3
              <-- ...

Now, suppose I want to add an agent that sends the frames to VLC. VLC works via callbacks, in "pull" mode. Roughly speaking, it calls some of my functions when it wants to read the next image. I cannot simply send them across*.

A simple approach is to use a message chain and call handle_n(1) from the read callback. However, to get the stream of images, I need an agent in the middle that subscribes to the image mailbox and just copies the traffic to the chain (a sort of "parrot" agent):

Grabber -> mbox
              <-- agent 1
              <-- agent 2
              <-- agent 3
              <-- parrot agent --> mchain <-- VLC agent <-- VLC

Although writing that parrot agent requires just a few lines of code, I am wondering if SObjectizer (or SObjectizer extra) can do something already. In other words, I am wondering if a message box (or message chain) can subscribe to another message box (!).

This would save not only extra code to maintain, but also hosting that parrot on some cooperation (that could take some resources, especially if the number of parrots increases in the future). Also, the parrot now handles just one message type but it might need to redirect more and this would result in adding more code to maintain.

As a side note, so5extra's fixed_mbox could work by changing the design of the application:

Grabber -> fixed_mbox
                    so_direct_mbox <-- agent1
                    so_direct_mbox <-- agent2
                    so_direct_mbox <-- agent3
                    mchain <-- VLC agent <-- VLC

However, it forces me to know in advance the agents that want to subscribe and it also does not allow me to use the great "named mailbox" feature.

Please let me know your thoughts.

Many thanks.

  • just for completeness, VLC can work with pipes (or stdin), in push mode. However, I cannot exploit that feature in my scenario.

from sobjectizer.

eao197 avatar eao197 commented on September 28, 2024

I am wondering if SObjectizer (or SObjectizer extra) can do something already. In other words, I am wondering if a message box (or message chain) can subscribe to another message box (!).

No, there is no such feature for now. I thought about such a possibility several times but it never got implemented :(

As a workaround you can make your own mbox by implementing so_5::abstract_message_box_t interface (by using proxy_mbox as the basis). That mbox can hold an actual MPMC mbox under the hood + mchain or something else. In the do_deliver_message of your custom mbox you just call do_deliver_message methods of the underlying MPMC mbox and your mchain.

from sobjectizer.

ilpropheta avatar ilpropheta commented on September 28, 2024

Ok, thanks for your suggestions!

from sobjectizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.