Commit ad406f57 authored by Dominik Charousset's avatar Dominik Charousset

implemented serialization of local groups with a broker-based forwarding strategy

parent c65f4cd3
...@@ -183,15 +183,6 @@ class group : public channel { ...@@ -183,15 +183,6 @@ class group : public channel {
virtual void unsubscribe(const channel_ptr& who) = 0; virtual void unsubscribe(const channel_ptr& who) = 0;
/**
* @brief Called whenever a message was received via network. If @p this
* is a proxy, it should not send the message
* back to the original group but forward the message to its local
* subscribers. This member function should call @p enqueue for
* all non-proxy instances.
*/
virtual void remote_enqueue(actor* sender, any_tuple msg);
module_ptr m_module; module_ptr m_module;
std::string m_identifier; std::string m_identifier;
......
...@@ -93,8 +93,4 @@ const std::string& group::module_name() const { ...@@ -93,8 +93,4 @@ const std::string& group::module_name() const {
return get_module()->name(); return get_module()->name();
} }
void group::remote_enqueue(actor* sender, any_tuple msg) {
enqueue(sender, std::move(msg));
}
} // namespace cppa } // namespace cppa
This diff is collapsed.
...@@ -35,6 +35,17 @@ std::vector<string_pair> get_kv_pairs(int argc, char** argv, int begin = 1) { ...@@ -35,6 +35,17 @@ std::vector<string_pair> get_kv_pairs(int argc, char** argv, int begin = 1) {
return result; return result;
} }
struct reflector : public event_based_actor {
void init() {
become (
others() >> [=] {
reply_tuple(last_dequeued());
quit();
}
);
}
};
int client_part(const std::vector<string_pair>& args) { int client_part(const std::vector<string_pair>& args) {
CPPA_TEST(test__remote_actor_client_part); CPPA_TEST(test__remote_actor_client_part);
auto i = std::find_if(args.begin(), args.end(), auto i = std::find_if(args.begin(), args.end(),
...@@ -93,13 +104,38 @@ int client_part(const std::vector<string_pair>& args) { ...@@ -93,13 +104,38 @@ int client_part(const std::vector<string_pair>& args) {
} }
); );
} }
// test group communication
auto grp = group::anonymous();
spawn_in_group<reflector>(grp);
spawn_in_group<reflector>(grp);
receive_response (sync_send(server, atom("Spawn5"), grp)) (
on(atom("ok")) >> [&] {
send(grp, "Hello reflectors!", 5.0);
},
after(std::chrono::seconds(10)) >> [&] {
CPPA_ERROR("unexpected timeout!");
}
);
// receive seven reply messages (2 local, 5 remote)
int x = 0;
receive_for(x, 7) (
on("Hello reflectors!", 5.0) >> [] { },
others() >> [&] {
CPPA_ERROR("unexpected message; "
<< __FILE__ << " line " << __LINE__ << ": "
<< to_string(self->last_dequeued()));
}
);
// wait for locally spawned reflectors
await_all_others_done();
send(server, atom("farewell"));
shutdown();
return CPPA_TEST_RESULT; return CPPA_TEST_RESULT;
} }
} // namespace <anonymous> } // namespace <anonymous>
int main(int argc, char** argv) { int main(int argc, char** argv) {
cout << "argv[0] = " << argv[0] << endl;
std::string app_path = argv[0]; std::string app_path = argv[0];
bool run_remote_actor = true; bool run_remote_actor = true;
if (argc > 1) { if (argc > 1) {
...@@ -169,13 +205,30 @@ cout << "argv[0] = " << argv[0] << endl; ...@@ -169,13 +205,30 @@ cout << "argv[0] = " << argv[0] << endl;
} }
); );
// test 100 sync messages // test 100 sync messages
cout << "test 100 synchronous messages" << endl;
int i = 0; int i = 0;
receive_for(i, 100) ( receive_for(i, 100) (
others() >> [] { others() >> [] {
reply_tuple(self->last_dequeued()); reply_tuple(self->last_dequeued());
} }
); );
cout << "test group communication via network" << endl;
// group test
receive (
on(atom("Spawn5"), arg_match) >> [](const group_ptr& grp) {
for (int i = 0; i < 5; ++i) {
spawn_in_group<reflector>(grp);
}
reply(atom("ok"));
}
);
await_all_others_done();
cout << "wait for a last goodbye" << endl;
receive (
on(atom("farewell")) >> [] { }
);
// wait until separate process (in sep. thread) finished execution // wait until separate process (in sep. thread) finished execution
if (run_remote_actor) child.join(); if (run_remote_actor) child.join();
shutdown();
return CPPA_TEST_RESULT; return CPPA_TEST_RESULT;
} }
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