Commit 37c3b185 authored by Dominik Charousset's avatar Dominik Charousset

Add caf::io::remote_group

parent 27f426c1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENCE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_IO_REMOTE_GROUP_HPP
#define CAF_IO_REMOTE_GROUP_HPP
#include "caf/group.hpp"
namespace caf {
namespace io {
/**
* <group-name>@<host>:<port>
*/
group remote_group(const std::string& group_uri);
group remote_group(const std::string& group_identifier,
const std::string& host,
uint16_t port);
} // namespace io
} // namespace caf
#endif // CAF_IO_REMOTE_GROUP_HPP
...@@ -30,11 +30,8 @@ namespace { ...@@ -30,11 +30,8 @@ namespace {
struct group_nameserver : event_based_actor { struct group_nameserver : event_based_actor {
behavior make_behavior() override { behavior make_behavior() override {
return { return {
on(atom("GET_GROUP"), arg_match) >> [](const std::string& name) { on(atom("GetGroup"), arg_match) >> [](const std::string& name) {
return make_message(atom("GROUP"), group::get("local", name)); return make_message(atom("Group"), group::get("local", name));
},
on(atom("SHUTDOWN")) >> [=] {
quit();
} }
}; };
} }
...@@ -48,8 +45,7 @@ void publish_local_groups(uint16_t port, const char* addr) { ...@@ -48,8 +45,7 @@ void publish_local_groups(uint16_t port, const char* addr) {
publish(gn, port, addr); publish(gn, port, addr);
} }
catch (std::exception&) { catch (std::exception&) {
gn->enqueue(invalid_actor_addr, message_id::invalid, anon_send_exit(gn, exit_reason::user_shutdown);
make_message(atom("SHUTDOWN")), nullptr);
throw; throw;
} }
} }
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENCE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/io/remote_group.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/io/remote_actor.hpp"
namespace caf {
namespace io {
group remote_group(const std::string& group_uri) {
// format of group_identifier is group@host:port
// a regex would be the natural choice here, but we want to support
// older compilers that don't have <regex> implemented (e.g. GCC < 4.9)
auto pos1 = group_uri.find('@');
auto pos2 = group_uri.find(':');
auto last = std::string::npos;
if (pos1 == last || pos2 == last || pos1 >= pos2) {
throw std::invalid_argument("group_uri has an invalid format");
}
auto name = group_uri.substr(0, pos1);
auto host = group_uri.substr(pos1 + 1, pos2 - pos1 - 1);
auto port = static_cast<uint16_t>(group_uri.substr(pos2 + 1));
return remote_group(name, host, port);
}
group remote_group(const std::string& group_identifier,
const std::string& host,
uint16_t port) {
auto group_server = remote_actor(host, port);
scoped_actor self;
self->send(group_server, atom("GetGroup"), group_identifier);
group result;
self->receive(
on(atom("Group"), arg_match) >> [&](group& grp) {
result = std::move(grp);
}
);
return result;
}
} // namespace io
} // namespace caf
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