Commit f4711b9a authored by Dominik Charousset's avatar Dominik Charousset

Re-implement remote lookup

parent ebc7bef1
...@@ -334,7 +334,7 @@ local_actor::msg_type local_actor::filter_msg(mailbox_element& x) { ...@@ -334,7 +334,7 @@ local_actor::msg_type local_actor::filter_msg(mailbox_element& x) {
x.sender->enqueue( x.sender->enqueue(
mailbox_element::make(ctrl(), x.mid.response_id(), mailbox_element::make(ctrl(), x.mid.response_id(),
{}, ok_atom::value, std::move(what), {}, ok_atom::value, std::move(what),
address(), name()), strong_actor_ptr{ctrl()}, name()),
context()); context());
} else { } else {
x.sender->enqueue( x.sender->enqueue(
......
...@@ -261,7 +261,7 @@ bool monitorable_actor::handle_system_message(mailbox_element& x, ...@@ -261,7 +261,7 @@ bool monitorable_actor::handle_system_message(mailbox_element& x,
} }
res = mailbox_element::make(ctrl(), x.mid.response_id(), {}, res = mailbox_element::make(ctrl(), x.mid.response_id(), {},
ok_atom::value, std::move(what), ok_atom::value, std::move(what),
address(), name()); strong_actor_ptr{ctrl()}, name());
} }
}); });
if (! res && ! err) if (! res && ! err)
......
...@@ -180,13 +180,11 @@ public: ...@@ -180,13 +180,11 @@ public:
add_hook<impl>(std::move(fun)); add_hook<impl>(std::move(fun));
} }
/*
/// Returns the actor associated with `name` at `nid` or /// Returns the actor associated with `name` at `nid` or
/// `invalid_actor` if `nid` is not connected or has no actor /// `invalid_actor` if `nid` is not connected or has no actor
/// associated to this `name`. /// associated to this `name`.
/// @warning Blocks the caller until `nid` responded to the lookup. /// @warning Blocks the caller until `nid` responded to the lookup.
actor remote_lookup(atom_value name, const node_id& nid); strong_actor_ptr remote_lookup(atom_value name, const node_id& nid);
*/
/// Smart pointer for `network::multiplexer`. /// Smart pointer for `network::multiplexer`.
using backend_pointer = std::unique_ptr<network::multiplexer>; using backend_pointer = std::unique_ptr<network::multiplexer>;
......
...@@ -257,30 +257,29 @@ void basp_broker_state::learned_new_node(const node_id& nid) { ...@@ -257,30 +257,29 @@ void basp_broker_state::learned_new_node(const node_id& nid) {
CAF_LOG_ERROR("learned_new_node called for known node " << CAF_ARG(nid)); CAF_LOG_ERROR("learned_new_node called for known node " << CAF_ARG(nid));
return; return;
} }
auto tmp = system().spawn<hidden>([=](event_based_actor* this_actor) -> behavior { auto tmp = system().spawn<hidden>([=](event_based_actor* tself) -> behavior {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
// terminate when receiving a down message // terminate when receiving a down message
this_actor->set_down_handler([=](down_msg& dm) { tself->set_down_handler([=](down_msg& dm) {
CAF_LOG_TRACE(CAF_ARG(dm)); CAF_LOG_TRACE(CAF_ARG(dm));
this_actor->quit(std::move(dm.reason)); tself->quit(std::move(dm.reason));
}); });
// skip messages until we receive the initial ok_atom // skip messages until we receive the initial ok_atom
this_actor->set_default_handler(skip); tself->set_default_handler(skip);
return { return {
[=](ok_atom, const std::string& /* key == "info" */, [=](ok_atom, const std::string& /* key == "info" */,
const actor_addr& config_serv_addr, const std::string& /* name */) { const strong_actor_ptr& config_serv, const std::string& /* name */) {
CAF_LOG_TRACE(CAF_ARG(config_serv_addr)); CAF_LOG_TRACE(CAF_ARG(config_serv));
// drop unexpected messages from this point on // drop unexpected messages from this point on
this_actor->set_default_handler(print_and_drop); tself->set_default_handler(print_and_drop);
auto config_serv = actor_cast<strong_actor_ptr>(config_serv_addr);
if (! config_serv) if (! config_serv)
return; return;
this_actor->monitor(config_serv); tself->monitor(config_serv);
this_actor->become( tself->become(
[=](spawn_atom, std::string& type, message& args) [=](spawn_atom, std::string& type, message& args)
-> delegated<ok_atom, strong_actor_ptr, std::set<std::string>> { -> delegated<ok_atom, strong_actor_ptr, std::set<std::string>> {
CAF_LOG_TRACE(CAF_ARG(type) << CAF_ARG(args)); CAF_LOG_TRACE(CAF_ARG(type) << CAF_ARG(args));
this_actor->delegate(actor_cast<actor>(std::move(config_serv)), tself->delegate(actor_cast<actor>(std::move(config_serv)),
get_atom::value, std::move(type), get_atom::value, std::move(type),
std::move(args)); std::move(args));
return {}; return {};
...@@ -289,7 +288,7 @@ void basp_broker_state::learned_new_node(const node_id& nid) { ...@@ -289,7 +288,7 @@ void basp_broker_state::learned_new_node(const node_id& nid) {
}, },
after(std::chrono::minutes(5)) >> [=] { after(std::chrono::minutes(5)) >> [=] {
CAF_LOG_INFO("no spawn server found:" << CAF_ARG(nid)); CAF_LOG_INFO("no spawn server found:" << CAF_ARG(nid));
this_actor->quit(); tself->quit();
} }
}; };
}); });
......
...@@ -244,19 +244,17 @@ group middleman::remote_group(const std::string& group_identifier, ...@@ -244,19 +244,17 @@ group middleman::remote_group(const std::string& group_identifier,
return result; return result;
} }
/* strong_actor_ptr middleman::remote_lookup(atom_value name, const node_id& nid) {
actor middleman::remote_lookup(atom_value name, const node_id& nid) {
CAF_LOG_TRACE(CAF_ARG(name) << CAF_ARG(nid)); CAF_LOG_TRACE(CAF_ARG(name) << CAF_ARG(nid));
auto basp = named_broker<basp_broker>(atom("BASP")); auto basp = named_broker<basp_broker>(atom("BASP"));
actor result; strong_actor_ptr result;
scoped_actor self{system(), true}; scoped_actor self{system(), true};
try { try {
self->send(basp, forward_atom::value, self.address(), nid, name, self->send(basp, forward_atom::value, self.address(), nid, name,
make_message(sys_atom::value, get_atom::value, "info")); make_message(sys_atom::value, get_atom::value, "info"));
self->receive( self->receive(
[&](ok_atom, const std::string&, [&](ok_atom, std::string&, strong_actor_ptr& addr, std::string&) {
const actor_addr& addr, const std::string&) { result = std::move(addr);
result = actor_cast<actor>(addr);
}, },
after(std::chrono::minutes(5)) >> [] { after(std::chrono::minutes(5)) >> [] {
// nop // nop
...@@ -267,7 +265,6 @@ actor middleman::remote_lookup(atom_value name, const node_id& nid) { ...@@ -267,7 +265,6 @@ actor middleman::remote_lookup(atom_value name, const node_id& nid) {
} }
return result; return result;
} }
*/
void middleman::start() { void middleman::start() {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
......
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