Comments (3)
No, named dispatchers were a part of SObjectizer up to v.5.5 but were deprecated and removed in v.5.6.
It is because in practice they were not as useful as expected.
The main problem is that every dispatcher can have its own unique interface and the binding of an agent to a dispatcher can require different parameters. You can compare an interface of disp_handle of one_thread, active_group, or so5extra's asio_thread_pool dispatchers.
This situation is completely different from the case of mboxes where each mbox implements the same interface.
Anyway, if you have a case where you want to have a dictionary of similar dispatchers (or wrap different dispatchers under the same unified interface) you can implement such a dictionary by yourself and attach that dispatcher to SObjectizer's Environment as a layer. Unfortunately, there is no example of custom layers in the standard SObjectizer's examples, but there are some unit-tests for layres.
The basic idea is:
class disp_binder_dictionary_layer_t : public so_5::layer_t
{
using map_t = std::map<std::string, so_5::disp_binder_shptr_t, std::less<>>;
std::mutex m_lock;
map_t m_dict;
public:
// There is no need to override start()/shutdown()/wait() methods
// because the basic implementation does nothing.
void add(std::string name, so_5::disp_binder_shptr_t binder)
{
std::lock_guard l{m_lock};
auto [it, inserted] = m_dict.emplace(std::move(name), std::move(binder));
if(!inserted)
throw std::runtime_error(name + ": is not unique name");
}
std::optional<so_5::disp_binder_shptr_t>
try_get(std::string_view name) noexcept
{
std::lock_guard l{m_lock};
if(const auto it = m_dict.find(name); it != m_dict.end())
return { it->second };
else
return std::nullopt;
}
so_5::disp_binder_shptr_t
get(std::string_view name)
{
auto r = try_get(name);
if(!r) throw std::runtime_error("binder is not found");
return std::move(*r);
}
};
...
so_5::launch([](so_5::environment_t & env) {...},
[](so_5::environment_params_t & params) {
params.add_layer(std::make_unique<disp_binder_dictionary_layer_t>());
...
});
...
// Somewhere inside your application code:
so_environment().query_layer<disp_binder_dictionary_layer_t>()->add("my_disp", ...);
...
so_environment().introduce_coop(
so_environment().query_layer<disp_binder_dictionary_layer_t>()->get("my_disp"),
...);
from sobjectizer.
Got it. Thank you a lot. Will be fine, if you add an example with SObjectizer layers to the official examples. But for me your answer is enough.
I think I can close it.
from sobjectizer.
By the way, if anyone else will use in the future the example above, you should fix one thing - use-after-move in add
method: variable name
is moved into distionary and then used during exaception message building. Be careful with that (catched with Clang-Tidy btw).
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.