int main(int argc, char *argv[]) { auto system = actor_system::create_system("actor_system", 4444); auto props_local = bumbler::typed_props<local_actor, out_actor>(); auto la1 = system->actor_of(props_local, "test_actor1"); auto ra1 = actor_ref("test_actor1$actor_system@localhost:4444"); std::future<std::string> f = la1.ask<std::string>(5); if(f.wait_for(std::chrono::seconds(1)) == std::future_status::ready) { INFO << "future result = " << f.get(); } f = ra1.ask<std::string>(6); if(f.wait_for(std::chrono::seconds(1)) == std::future_status::ready) { INFO << "future result = " << f.get(); } std::this_thread::sleep_for(std::chrono::seconds(1)); system->stop(true); INFO << "EXIT"; return 0; }
void local_actor_channel::ask_impl(std::unique_ptr<message> msg, const ResponseFun& response_fun) { auto target_system = actor_system_storage::instance().get_system(msg->get_target().system_name); if (target_system != nullptr) { auto response_promise_actor = typed_props<promise_actor, typed_promise_actor>(response_fun); actor_ref p_actor = target_system->actor_of(response_promise_actor, target_system->get_next_temporary_actor_name()); msg->set_sender(p_actor); actor_ptr_.lock()->tell(std::move(msg)); } }
void remote_actor_channel::ask_impl(std::unique_ptr<message> msg, const ResponseFun& response_fun) { auto target_system = get_actor_system(msg->get_sender()); if (!target_system) { throw new server_doesnt_exist("can't send messages to remote actors without an active actor system"); } auto response_promise_actor = typed_props<promise_actor, typed_promise_actor>(response_fun); actor_ref p_actor = target_system->actor_of(response_promise_actor, target_system->get_next_temporary_actor_name()); msg->set_sender(p_actor); packet msg_packet(std::move(msg)); std::string serialized_packet = msg_packet.get_serialized(); target_system->send_data(serialized_packet, network_actor_endpoint_); }