MCPcopy Create free account
hub / github.com/actor-framework/actor-framework / start

Method start

libcaf_io/caf/io/middleman.cpp:336–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336void middleman::start() {
337 auto lg = log::io::trace("");
338 // Consider using net::middleman for prometheus if caf-net is available.
339 if (auto prom = get_if<config_value::dictionary>(
340 &system().config(), "caf.middleman.prometheus-http")) {
341 auto ptr = std::make_unique<prometheus_scraping>(system());
342 if (auto port = ptr->start(*prom)) {
343 CAF_ASSERT(*port != 0);
344 prometheus_scraping_port_ = *port;
345 background_tasks_.emplace_back(std::move(ptr));
346 }
347 }
348 // Launch backend.
349 backend_supervisor_ = backend().make_supervisor();
350 CAF_ASSERT(backend_supervisor_ != nullptr);
351 detail::latch sync{1};
352 auto run_backend = [this, sync_ptr{&sync}] {
353 auto lg = log::io::trace("");
354 backend().thread_id(std::this_thread::get_id());
355 sync_ptr->count_down();
356 backend().run();
357 };
358 thread_ = system().launch_thread("caf.io.mpx", thread_owner::system,
359 run_backend);
360 sync.wait();
361 // Spawn utility actors.
362 auto basp = named_broker<basp_broker>("BASP");
363 manager_ = make_middleman_actor(system(), basp);
364}
365
366void middleman::stop() {
367 auto lg = log::io::trace("");
368 backend().dispatch([this] {
369 auto lg = log::io::trace("");
370 // managers_ will be modified while we are stopping each manager,
371 // because each manager will call remove(...)
372 for (auto& kvp : named_brokers_) {
373 auto& hdl = kvp.second;
374 auto ptr = actor_cast<broker*>(hdl);
375 if (!ptr->getf(abstract_actor::is_terminated_flag)) {
376 ptr->context(&backend());
377 ptr->quit();
378 ptr->finalize();
379 }
380 }
381 });
382 backend_supervisor_.reset();
383 if (thread_.joinable())
384 thread_.join();
385 named_brokers_.clear();
386 scoped_actor self{system(), true};
387 self->send_exit(manager_, exit_reason::kill);
388 if (!get_or(config(), "caf.middleman.attach-utility-actors", false))
389 self->wait_for(manager_);
390 destroy(manager_);
391 background_tasks_.clear();
392}
393

Callers 11

caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45
caf_mainFunction · 0.45

Calls 8

traceFunction · 0.85
make_supervisorMethod · 0.80
count_downMethod · 0.80
waitMethod · 0.80
make_middleman_actorFunction · 0.70
configMethod · 0.45
emplace_backMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected