Comments (3)
I would like to drop here just a reference to a real use case we have discussed already that would benefit from this feature:
#30 (comment)
from sobjectizer.
The idea I have at the moment is:
A new interface has to be introduced. Something like that:
class message_sink_t
{
public:
static void
call_push_event(
message_sink_t & sink,
const message_limit::control_block_t * limit,
mbox_id_t mbox_id,
std::type_index msg_type,
const message_ref_t & message )
{
sink.push_event(limit, mbox_id, msg_type, message);
}
protected:
~message_sink_t() noexcept; // Will be empty.
virtual void
push_event(
const message_limit::control_block_t * limit,
mbox_id_t mbox_id,
std::type_index msg_type,
const message_ref_t & message ) = 0;
};
The class agent_t
will implement this interface.
A new helper class mbox_binder_t
will be introduced. It will manage subscriptions between mboxes. And will destroy all remaining subscriptions in the destructor (or in a special method clear()
). So a user has to create an instance of mbox_builder_t
, make all subscriptions and then ensure that this mbox_builder_t
lives as long as required.
Something like:
const so_5::mbox_t source_mbox = ...;
const so_5::mbox_t dest_one = ...;
const so_5::mbox_t dest_two = ...;
const so_5::mbox_t dest_three = ...;
auto binder{ std::make_unique< so_5::mbox_binder_t<> >() };
binder->from(source_mbox)
.subscribe<MSG1>(dest_one)
.subscribe<MSG1>(dest_two)
.subscribe<MSG1>(dest_three);
binder->from(source_mbox)
.subscribe<MSG2>(dest_one)
.subscribe<MSG2>(dest_three);
binder->from(source_mbox)
.subscribe<MSG3>(dest_one)
.unsubscribe<MSG1>(dest_two)
.unsubscribe_all(dest_three);
... // binder should be stored somewhere.
Where mbox_binder_t
can be something like (just a sketch):
template< typename Lock_Type = std::mutex >
class mbox_binder_t {
... // Some internals.
public:
class performer_t {
mbox_binder_t & m_binder;
mbox_t m_source;
performer_t(mbox_binder_t & binder, mbox_t source) : m_binder{binder}, m_source{std::move(source)} {}
public:
template<typename Msg_Type>
performer_t &
subscribe(const mbox_t & dest) {
m_binder.make_subscription<Msg_Type>(m_source, dest);
return *this;
}
template<typename Msg_Type>
performer_t &
unsubscribe(const mbox_t & dest) {
m_binder.drop_subscription<Msg_Type>(m_source, dest);
return *this;
}
performer_t &
unsubscribe_all(const mbox_t & dest) {
m_binder.drop_all_subscriptions(m_source, dest);
return *this;
}
};
[[nodiscard]] performer_t
from(const mbox_t & source) { return { *this, source }; }
private:
... // Implementation of make_subscription, drop_subscription, drop_all_subscriptions.
};
The implementation of mbox_binder_t
will hide an actual implementation of message_sink_t
interface from a user. But it seems that this implementation of message_sink_t
will be very simple. The mbox_binder_t
itself it expected to be more complex.
This will cover all cases when we want to subscribe a destination mbox to a source mbox (and have to possibility to use something from so5extra as the source mbox).
If a user wants to cover other use cases where a custom message sink is necessary he/she has to deal will all that stuff (like handling of subscriptions) to him/herself.
from sobjectizer.
Implemented in v.5.8.0
from sobjectizer.
Related Issues (20)
- Asynchrony of register_coop HOT 4
- Documentation for message_holder_t has to be extended HOT 1
- 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
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.