本文整理汇总了C++中message_id::valid方法的典型用法代码示例。如果您正苦于以下问题:C++ message_id::valid方法的具体用法?C++ message_id::valid怎么用?C++ message_id::valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message_id
的用法示例。
在下文中一共展示了message_id::valid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
optional<behavior&> behavior_stack::sync_handler(message_id expected_response) {
if (expected_response.valid()) {
auto e = m_elements.rend();
auto i = find_if(m_elements.rbegin(), e, [=](element_type& val) {
return val.second == expected_response;
});
if (i != e) return i->first;
}
return none;
}
示例2: filter
bool actor_pool::filter(upgrade_lock<detail::shared_spinlock>& guard,
const strong_actor_ptr& sender, message_id mid,
message_view& mv, execution_unit* eu) {
auto& content = mv.content();
CAF_LOG_TRACE(CAF_ARG(mid) << CAF_ARG(content));
if (content.match_elements<exit_msg>()) {
// acquire second mutex as well
std::vector<actor> workers;
auto em = content.get_as<exit_msg>(0).reason;
if (cleanup(std::move(em), eu)) {
auto tmp = mv.move_content_to_message();
// send exit messages *always* to all workers and clear vector afterwards
// but first swap workers_ out of the critical section
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
workers_.swap(workers);
unique_guard.unlock();
for (auto& w : workers)
anon_send(w, tmp);
unregister_from_system();
}
return true;
}
if (content.match_elements<down_msg>()) {
// remove failed worker from pool
auto& dm = content.get_as<down_msg>(0);
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
auto last = workers_.end();
auto i = std::find(workers_.begin(), workers_.end(), dm.source);
CAF_LOG_DEBUG_IF(i == last, "received down message for an unknown worker");
if (i != last)
workers_.erase(i);
if (workers_.empty()) {
planned_reason_ = exit_reason::out_of_workers;
unique_guard.unlock();
quit(eu);
}
return true;
}
if (content.match_elements<sys_atom, put_atom, actor>()) {
auto& worker = content.get_as<actor>(2);
worker->attach(default_attachable::make_monitor(worker.address(),
address()));
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
workers_.push_back(worker);
return true;
}
if (content.match_elements<sys_atom, delete_atom, actor>()) {
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
auto& what = content.get_as<actor>(2);
auto last = workers_.end();
auto i = std::find(workers_.begin(), last, what);
if (i != last) {
workers_.erase(i);
}
return true;
}
if (content.match_elements<sys_atom, get_atom>()) {
auto cpy = workers_;
guard.unlock();
sender->enqueue(nullptr, mid.response_id(),
make_message(std::move(cpy)), eu);
return true;
}
if (workers_.empty()) {
guard.unlock();
if (sender && mid.valid()) {
// tell client we have ignored this sync message by sending
// and empty message back
sender->enqueue(nullptr, mid.response_id(), message{}, eu);
}
return true;
}
return false;
}
示例3: filter
bool actor_pool::filter(upgrade_lock<detail::shared_spinlock>& guard,
const actor_addr& sender, message_id mid,
const message& msg, execution_unit* eu) {
auto rsn = planned_reason_;
if (rsn != caf::exit_reason::not_exited) {
guard.unlock();
if (mid.valid()) {
detail::sync_request_bouncer srq{rsn};
srq(sender, mid);
}
return true;
}
if (msg.match_elements<exit_msg>()) {
std::vector<actor> workers;
// send exit messages *always* to all workers and clear vector afterwards
// but first swap workers_ out of the critical section
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
workers_.swap(workers);
planned_reason_ = msg.get_as<exit_msg>(0).reason;
unique_guard.unlock();
for (auto& w : workers) {
anon_send(w, msg);
}
quit();
return true;
}
if (msg.match_elements<down_msg>()) {
// remove failed worker from pool
auto& dm = msg.get_as<down_msg>(0);
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
auto last = workers_.end();
auto i = std::find(workers_.begin(), workers_.end(), dm.source);
if (i != last) {
workers_.erase(i);
}
if (workers_.empty()) {
planned_reason_ = exit_reason::out_of_workers;
unique_guard.unlock();
quit();
}
return true;
}
if (msg.match_elements<sys_atom, put_atom, actor>()) {
auto& worker = msg.get_as<actor>(2);
if (worker == invalid_actor) {
return true;
}
worker->attach(default_attachable::make_monitor(address()));
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
workers_.push_back(worker);
return true;
}
if (msg.match_elements<sys_atom, delete_atom, actor>()) {
upgrade_to_unique_lock<detail::shared_spinlock> unique_guard{guard};
auto& what = msg.get_as<actor>(2);
auto last = workers_.end();
auto i = std::find(workers_.begin(), last, what);
if (i != last) {
workers_.erase(i);
}
return true;
}
if (msg.match_elements<sys_atom, get_atom>()) {
auto cpy = workers_;
guard.unlock();
actor_cast<abstract_actor*>(sender)->enqueue(invalid_actor_addr,
mid.response_id(),
make_message(std::move(cpy)),
eu);
return true;
}
if (workers_.empty()) {
guard.unlock();
if (sender != invalid_actor_addr && mid.valid()) {
// tell client we have ignored this sync message by sending
// and empty message back
auto ptr = actor_cast<abstract_actor_ptr>(sender);
ptr->enqueue(invalid_actor_addr, mid.response_id(), message{}, eu);
}
return true;
}
return false;
}
示例4:
response_promise::response_promise(const actor_addr& from,
const actor_addr& to,
const message_id& id)
: m_from(from), m_to(to), m_id(id) {
CPPA_REQUIRE(id.is_response() || !id.valid());
}
示例5: handle_message
handle_message_result handle_message(Actor* self, mailbox_element* node,
Fun& fun, message_id awaited_response) {
bool handle_sync_failure_on_mismatch = true;
if (dptr()->hm_should_skip(node)) {
return hm_skip_msg;
}
switch (this->filter_msg(self, node)) {
case msg_type::normal_exit:
CAF_LOG_DEBUG("dropped normal exit signal");
return hm_drop_msg;
case msg_type::expired_sync_response:
CAF_LOG_DEBUG("dropped expired sync response");
return hm_drop_msg;
case msg_type::expired_timeout:
CAF_LOG_DEBUG("dropped expired timeout message");
return hm_drop_msg;
case msg_type::inactive_timeout:
CAF_LOG_DEBUG("skipped inactive timeout message");
return hm_skip_msg;
case msg_type::non_normal_exit:
CAF_LOG_DEBUG("handled non-normal exit signal");
// this message was handled
// by calling self->quit(...)
return hm_msg_handled;
case msg_type::timeout: {
CAF_LOG_DEBUG("handle timeout message");
auto& tm = node->msg.get_as<timeout_msg>(0);
self->handle_timeout(fun, tm.timeout_id);
if (awaited_response.valid()) {
self->mark_arrived(awaited_response);
self->remove_handler(awaited_response);
}
return hm_msg_handled;
}
case msg_type::timeout_response:
handle_sync_failure_on_mismatch = false;
CAF_ANNOTATE_FALLTHROUGH;
case msg_type::sync_response:
CAF_LOG_DEBUG("handle as synchronous response: "
<< CAF_TARG(node->msg, to_string) << ", "
<< CAF_MARG(node->mid, integer_value) << ", "
<< CAF_MARG(awaited_response, integer_value));
if (awaited_response.valid() && node->mid == awaited_response) {
auto previous_node = dptr()->hm_begin(self, node);
auto res = invoke_fun(self, node->msg, node->mid, fun);
if (!res && handle_sync_failure_on_mismatch) {
CAF_LOG_WARNING("sync failure occured in actor "
<< "with ID " << self->id());
self->handle_sync_failure();
}
self->mark_arrived(awaited_response);
self->remove_handler(awaited_response);
dptr()->hm_cleanup(self, previous_node);
return hm_msg_handled;
}
return hm_cache_msg;
case msg_type::ordinary:
if (!awaited_response.valid()) {
auto previous_node = dptr()->hm_begin(self, node);
auto res = invoke_fun(self, node->msg, node->mid, fun);
if (res) {
dptr()->hm_cleanup(self, previous_node);
return hm_msg_handled;
}
// no match (restore self members)
dptr()->hm_revert(self, previous_node);
}
CAF_LOG_DEBUG_IF(awaited_response.valid(),
"ignored message; await response: "
<< awaited_response.integer_value());
return hm_cache_msg;
}
// should be unreachable
CAF_CRITICAL("invalid message type");
}