Commit 975a8c1d authored by Dominik Charousset's avatar Dominik Charousset

Make remote_lookup more efficient

parent e0e7e4da
......@@ -73,6 +73,7 @@ behavior config_serv_impl(stateful_actor<kvstate>* self) {
unsubscribe_all(actor_cast<actor>(std::move(ptr)));
});
return {
// set a key/value pair
[=](put_atom, const std::string& key, message& msg) {
CAF_LOG_TRACE(CAF_ARG(key) << CAF_ARG(msg));
if (key == "*")
......@@ -91,6 +92,7 @@ behavior config_serv_impl(stateful_actor<kvstate>* self) {
self->send(actor_cast<actor>(subscriber), update_atom::value,
key, vp.second);
},
// get a key/value pair
[=](get_atom, std::string& key) -> message {
CAF_LOG_TRACE(CAF_ARG(key));
if (key == wildcard) {
......@@ -105,6 +107,7 @@ behavior config_serv_impl(stateful_actor<kvstate>* self) {
i != self->state.data.end() ? i->second.first
: make_message());
},
// subscribe to a key
[=](subscribe_atom, const std::string& key) {
auto subscriber = actor_cast<strong_actor_ptr>(self->current_sender());
CAF_LOG_TRACE(CAF_ARG(key) << CAF_ARG(subscriber));
......@@ -120,6 +123,7 @@ behavior config_serv_impl(stateful_actor<kvstate>* self) {
subscribers.emplace(subscriber, kvstate::topic_set{key});
}
},
// unsubscribe from a key
[=](unsubscribe_atom, const std::string& key) {
auto subscriber = actor_cast<strong_actor_ptr>(self->current_sender());
if (! subscriber)
......@@ -131,6 +135,10 @@ behavior config_serv_impl(stateful_actor<kvstate>* self) {
}
self->state.subscribers[subscriber].erase(key);
self->state.data[key].second.erase(subscriber);
},
// get a 'named' actor from local registry
[=](get_atom, atom_value name) {
return self->home_system().registry().get(name);
}
};
}
......
......@@ -29,7 +29,7 @@ const uint8_t header::named_receiver_flag;
std::string to_bin(uint8_t x) {
std::string res;
for (auto offset = 7; offset > 0; --offset)
for (auto offset = 7; offset > -1; --offset)
res += std::to_string((x >> offset) & 0x01);
return res;
}
......
......@@ -251,12 +251,13 @@ strong_actor_ptr middleman::remote_lookup(atom_value name, const node_id& nid) {
auto basp = named_broker<basp_broker>(atom("BASP"));
strong_actor_ptr result;
scoped_actor self{system(), true};
self->set_default_handler(print_and_drop);
try {
self->send(basp, forward_atom::value, actor_cast<strong_actor_ptr>(self),
nid, name,
make_message(sys_atom::value, get_atom::value, "info"));
nid, atom("ConfigServ"),
make_message(get_atom::value, name));
self->receive(
[&](ok_atom, std::string&, strong_actor_ptr& addr, std::string&) {
[&](strong_actor_ptr& addr) {
result = std::move(addr);
},
after(std::chrono::minutes(5)) >> [] {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment