Comments (4)
Hi!
There are two different cases:
- 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.
- 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.
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.
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.
Ok, thanks for your suggestions!
from sobjectizer.
Related Issues (20)
- A usage example for agent_t::limit_then_redirect method in API Reference HOT 1
- [Design] Your opinion on expressing agent intent HOT 2
- Deprecation of coop_t::deregister and coop_t::deregister_normally methods HOT 1
- [idea] An emergency stop of SOEnv on an exception in noexcept context HOT 1
- `so_evt_finish` not called until `so_evt_start` is running? HOT 2
- Should agent_t::so_drop_subscription* methods be marked as noexcept? HOT 1
- Should delivery filters be checked for noexcept-ness?
- bind_and_transform HOT 10
- so_5::details::make_message_instance_impl metafunction doesn't set message mutability flag properly HOT 1
- limit_then_transform for mutable messages HOT 1
- Allow `const auto &` as an argument for delivery filter in single/multi_sink_binding HOT 1
- Should there be agent_t::so_disp_binder() and agent_t::so_coop_default_disp_binder() methods? HOT 2
- [idea] Make so5extra's revocable timers the default implementation for timers in SObjectizer
- Another constructor for wrapped_env_t that waits completion of init-function HOT 1
- Use of message limits and state_t::time_limit
- Optional name for an agent? HOT 2
- New method `as_string_view` for so_5::stats::prefix_t and so_5::stats::suffix_t HOT 1
- SO_5_TYPE shouldn't be used for so_5::stats::messages::quantity
- Integrating with GUI applications HOT 1
- Add lock_shared/unlock_shared to so_5::null_mutex_t
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sobjectizer.