Commit bbf07840 authored by Dominik Charousset's avatar Dominik Charousset

Add `before_shutdown` callback to `io::hook`

parent 73718b1c
......@@ -99,8 +99,10 @@ public:
virtual void invalid_message_received_cb(const node_id& source,
const actor_addr& sender,
actor_id invalid_dest,
message_id mid,
const message& msg);
message_id mid, const message& msg);
/// Called before middleman shuts down.
virtual void before_shutdown_cb();
/// All possible events for IO hooks.
enum event_type {
......@@ -113,7 +115,8 @@ public:
new_remote_actor,
new_connection_established,
new_route_added,
invalid_message_received
invalid_message_received,
before_shutdown
};
/// Handles an event by invoking the associated callback.
......@@ -148,6 +151,7 @@ private:
CAF_IO_HOOK_DISPATCH(new_connection_established)
CAF_IO_HOOK_DISPATCH(new_route_added)
CAF_IO_HOOK_DISPATCH(invalid_message_received)
CAF_IO_HOOK_DISPATCH(before_shutdown)
};
} // namespace io
......
......@@ -100,6 +100,23 @@ public:
});
}
template <class F>
void add_shutdown_cb(F fun) {
struct impl : hook {
impl(F&& f) : fun_(std::move(f)) {
// nop
}
void before_shutdown_cb() override {
fun_();
call_next<hook::before_shutdown>();
}
F fun_;
};
add_hook<impl>(std::move(fun));
}
/// @cond PRIVATE
// stops the singleton
......
......@@ -81,5 +81,9 @@ void hook::invalid_message_received_cb(const node_id& source,
call_next<invalid_message_received>(source, sender, invalid_dest, mid, msg);
}
void hook::before_shutdown_cb() {
call_next<before_shutdown>();
}
} // namespace io
} // namespace caf
......@@ -369,6 +369,7 @@ void middleman::stop() {
CAF_LOG_TRACE("");
backend_->dispatch([=] {
CAF_LOG_TRACE("");
notify<hook::before_shutdown>();
// managers_ will be modified while we are stopping each manager,
// because each manager will call remove(...)
for (auto& kvp : named_brokers_) {
......@@ -379,6 +380,7 @@ void middleman::stop() {
});
backend_supervisor_.reset();
thread_.join();
hooks_.reset();
named_brokers_.clear();
scoped_actor self(true);
self->monitor(manager_);
......
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