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

Function client

robot/middleman/driver.cpp:234–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234int client(actor_system& sys, std::string_view mode, const std::string& host,
235 uint16_t port) {
236 auto& mm = sys.middleman();
237 if (mode == "remote_actor") {
238 auto cell = with_retry([&] { return mm.remote_actor(host, port); });
239 auto cell2 = mm.remote_actor(host, port);
240 if (!cell2 || *cell != *cell2) {
241 std::cout << "calling remote_actor twice must return the same handle\n";
242 return EXIT_FAILURE;
243 }
244 return cell_tests(sys, *cell);
245 }
246 if (mode == "remote_spawn") {
247 auto nid = with_retry([&] { return mm.connect(host, port); });
248 auto nid2 = mm.connect(host, port); // with cache
249 if (!nid2 || *nid != *nid2) {
250 std::cout << "calling connect twice must return the same node ID\n";
251 return EXIT_FAILURE;
252 }
253 purge_cache(sys, host, port);
254 auto nid3 = mm.connect(host, port); // without cache
255 if (!nid3 || *nid != *nid3) {
256 std::cout << "calling connect twice must return the same node ID\n";
257 return EXIT_FAILURE;
258 }
259 auto cell = mm.remote_spawn<actor>(*nid, "cell", make_message(int32_t{7}),
260 5s);
261 if (!cell) {
262 std::cout << "remote spawn failed: " << to_string(cell.error()) << "\n";
263 return EXIT_FAILURE;
264 }
265 return cell_tests(sys, *cell);
266 }
267 if (mode == "remote_lookup") {
268 auto nid = with_retry([&] { return mm.connect(host, port); });
269 auto cell = mm.remote_lookup("cell", *nid);
270 if (!cell) {
271 std::cout << "remote_lookup failed\n";
272 return EXIT_FAILURE;
273 }
274 return cell_tests(sys, actor_cast<actor>(cell));
275 }
276 if (mode == "unpublish") {
277 auto ctrl = with_retry([&] { return mm.remote_actor(host, port); });
278 bool unpublished = false;
279 scoped_actor self{sys};
280 self->mail(ok_atom_v).request(*ctrl, 5s).receive(
281 [&unpublished] { unpublished = true; },
282 [](const error& reason) {
283 std::cout << "failed to unpublish: " << to_string(reason) << "\n";
284 });
285 if (!unpublished) {
286 return EXIT_FAILURE;
287 }
288 with_retry([&] {
289 purge_cache(sys, host, port);
290 return !mm.remote_actor(host, port);
291 });

Callers 1

caf_mainFunction · 0.70

Calls 15

with_retryFunction · 0.85
cell_testsFunction · 0.85
purge_cacheFunction · 0.85
make_messageFunction · 0.85
afterFunction · 0.85
remote_actorMethod · 0.80
remote_lookupMethod · 0.80
to_stringFunction · 0.50
middlemanMethod · 0.45
connectMethod · 0.45
errorMethod · 0.45
receiveMethod · 0.45

Tested by

no test coverage detected