void remote_actor_proxy::forward_msg(const actor_addr& sender, message_id mid, message msg) { CAF_LOG_TRACE(CAF_ARG(id()) << ", " << CAF_TSARG(sender) << ", " << CAF_MARG(mid, integer_value) << ", " << CAF_TSARG(msg)); m_parent->enqueue( invalid_actor_addr, invalid_message_id, make_message(atom("_Dispatch"), sender, address(), mid, std::move(msg)), nullptr); }
void send_to_acquaintances(const message& what) { // send to all remote subscribers auto sender = current_sender(); CAF_LOG_DEBUG("forward message to " << m_acquaintances.size() << " acquaintances; " << CAF_TSARG(sender) << ", " << CAF_TSARG(what)); for (auto& acquaintance : m_acquaintances) { acquaintance->enqueue(sender, invalid_message_id, what, host()); } }
void forwarding_actor_proxy::forward_msg(const actor_addr& sender, message_id mid, message msg) { CAF_LOG_TRACE(CAF_ARG(id()) << ", " << CAF_TSARG(sender) << ", " << CAF_MARG(mid, integer_value) << ", " << CAF_TSARG(msg)); shared_lock<detail::shared_spinlock> m_guard(m_manager_mtx); m_manager->enqueue(invalid_actor_addr, invalid_message_id, make_message(atom("_Dispatch"), sender, address(), mid, std::move(msg)), nullptr); }
bool abstract_actor::remove_backlink_impl(const actor_addr& other) { CAF_LOG_TRACE(CAF_TSARG(other)); default_attachable::observe_token tk{other, default_attachable::link}; if (other && other != this) { guard_type guard{mtx_}; return detach_impl(tk, attachables_head_, true) > 0; } return false; }
void local_actor::leave(const group& what) { CAF_LOG_TRACE(CAF_TSARG(what)); if (what == invalid_group) { return; } if (detach(abstract_group::subscription_token{what.ptr()}) > 0) { what->unsubscribe(address()); } }
bool abstract_actor::link_impl(linking_operation op, const actor_addr& other) { CAF_LOG_TRACE(CAF_ARG(op) << ", " << CAF_TSARG(other)); switch (op) { case establish_link_op: return establish_link_impl(other); case establish_backlink_op: return establish_backlink_impl(other); case remove_link_op: return remove_link_impl(other); default: CAF_ASSERT(op == remove_backlink_op); return remove_backlink_impl(other); } }
void local_actor::join(const group& what) { CAF_LOG_TRACE(CAF_TSARG(what)); if (what == invalid_group) { return; } abstract_group::subscription_token tk{what.ptr()}; std::unique_lock<std::mutex> guard{m_mtx}; if (detach_impl(tk, m_attachables_head, true, true) == 0) { auto ptr = what->subscribe(address()); if (ptr) { attach_impl(ptr); } } }
bool abstract_actor::remove_link_impl(const actor_addr& other) { CAF_LOG_TRACE(CAF_TSARG(other)); if (other == invalid_actor_addr || other == this) { return false; } default_attachable::observe_token tk{other, default_attachable::link}; guard_type guard{mtx_}; // remove_backlink returns true if this actor is linked to other auto ptr = actor_cast<abstract_actor_ptr>(other); if (detach_impl(tk, attachables_head_, true) > 0) { // tell remote side to remove link as well ptr->remove_backlink(address()); return true; } return false; }
void unpublish_impl(const actor_addr& whom, uint16_t port, bool blocking) { CAF_LOGF_TRACE(CAF_TSARG(whom) << ", " << CAF_ARG(port) << CAF_ARG(blocking)); auto mm = get_middleman_actor(); if (blocking) { scoped_actor self; self->sync_send(mm, unpublish_atom::value, whom, port).await( [](ok_atom) { // ok, basp_broker is done }, [](error_atom, const std::string&) { // ok, basp_broker is done } ); } else { anon_send(mm, unpublish_atom::value, whom, port); } }
bool abstract_actor::establish_link_impl(const actor_addr& other) { CAF_LOG_TRACE(CAF_TSARG(other)); if (other && other != this) { guard_type guard{mtx_}; auto ptr = actor_cast<abstract_actor_ptr>(other); // send exit message if already exited if (exited()) { ptr->enqueue(address(), invalid_message_id, make_message(exit_msg{address(), exit_reason()}), host_); } else if (ptr->establish_backlink(address())) { // add link if not already linked to other // (checked by establish_backlink) auto tmp = default_attachable::make_link(other); attach_impl(tmp); return true; } } return false; }
bool abstract_actor::establish_backlink_impl(const actor_addr& other) { CAF_LOG_TRACE(CAF_TSARG(other)); uint32_t reason = exit_reason::not_exited; default_attachable::observe_token tk{other, default_attachable::link}; if (other && other != this) { guard_type guard{mtx_}; reason = exit_reason_; if (reason == exit_reason::not_exited) { if (detach_impl(tk, attachables_head_, true, true) == 0) { auto tmp = default_attachable::make_link(other); attach_impl(tmp); return true; } } } // send exit message without lock if (reason != exit_reason::not_exited) { auto ptr = actor_cast<abstract_actor_ptr>(other); ptr->enqueue(address(), invalid_message_id, make_message(exit_msg{address(), exit_reason()}), host_); } return false; }