% Common shared database loaded by every deployment node. % Holds the family relations used in the tutorial's local and distributed % Prolog sections. ancestor_descendant(X, Y) :- parent_child(X, Y). ancestor_descendant(X, Z) :- parent_child(X, Y), ancestor_descendant(Y, Z). parent_child(X, Y) :- mother_child(X, Y). parent_child(X, Y) :- father_child(X, Y). mother_child(trude, sally). father_child(tom, sally). father_child(tom, erica). father_child(mike, tom). list_price(widget, 100). list_price(gadget, 250). list_price(gizmo, 400). price(Item, Price) :- list_price(Item, Price). % Shared database loaded by all ACTOR-profile deployment nodes (n3, n4). % Holds the actor predicates that the tutorial expects to find on either % public actor node, plus the public service directory. service(counter, meta(actor, protocol(count_v1))). service(pubsub_service, meta(actor, protocol(pubsub_v1))). service(linda, meta(actor, protocol(linda_v1))). echo_actor :- receive({ echo(From, Msg) -> From ! echo(Msg), echo_actor }). count_actor(Count0) :- receive({ count(From) -> Count is Count0 + 1, From ! count(Count), count_actor(Count) ; stop -> true }). % Native ping-pong benchmark. The worker predicates live in this shared % database, so the spawned actors can call them directly: no src_* source % transfer or private source installation is part of the measurement. ping_pong :- ping_pong(1000). ping_pong(RoundTrips) :- must_be(nonneg, RoundTrips), self(MasterPid), spawn(pong(MasterPid), PongPid), spawn(ping(RoundTrips, PongPid)), receive({finished -> true}). ping_pong_benchmark(RoundTrips, Microseconds) :- get_time(T0), ping_pong(RoundTrips), get_time(T1), Microseconds is round((T1-T0) * 1_000_000). ping(0, PongPid) :- PongPid ! finished. ping(N, PongPid) :- self(Self), PongPid ! ping(Self), receive({pong -> true}), N1 is N - 1, ping(N1, PongPid). pong(MasterPid) :- receive({ finished -> MasterPid ! finished ; ping(PingPid) -> PingPid ! pong, pong(MasterPid) }). authorized(alice). owns(alice, printer2). online(printer2). % Owner-installed local service address; callers use linda_out/1 etc. linda_local_address(linda@Node) :- self_node_url(Node). % Owner-installed application interface; loaded into the node shared database. % Clients call these five predicates without loading protocol implementation. linda_out(Tuple) :- linda_local_call(out(Tuple), ok). linda_in(Tuple) :- linda_local_call(in(Tuple), tuple(Tuple)). linda_rd(Tuple) :- linda_local_call(rd(Tuple), tuple(Tuple)). linda_inp(Tuple) :- linda_local_call(inp(Tuple), tuple(Tuple)). linda_rdp(Tuple) :- linda_local_call(rdp(Tuple), tuple(Tuple)). linda_local_call(Operation, Result) :- linda_local_address(Address), self(Me), make_ref(Ref), Address ! linda_connect(Me, Ref), receive({linda_connected(Ref, Space) -> true}, [timeout(5), on_timeout(throw(linda_down(unavailable)))]), linda_call(Space, Operation, Result). linda_call(Space, Operation, Result) :- self(Me), make_ref(Ref), setup_call_cleanup( monitor(Space, Monitor), ( Space ! linda(Me, Ref, Operation), receive({linda_reply(Ref, Reply) -> true; down(_, Monitor, Reason) -> throw(linda_down(Reason))}), linda_result(Reply, Result) ), ( catch(Space ! linda_cancel(Me, Ref), _, true), demonitor(Monitor, [flush]) )). linda_result(error(Reason), _) :- !, throw(linda_error(Reason)). linda_result(missing, _) :- !, fail. linda_result(Reply, Reply). % n3 is the public actor-demo node. % The shared actor predicates are in shared_db_actor_common.pl. This overlay % holds only n3-specific predicates: the deployment marker and the % mortal/human chain that the tutorial's distributed proof tree pulls % through to n4. :- dynamic mortal/1, human/1. mortal(X) :- human(X). human(socrates). human(X) :- rpc('https://n4.elfenbenstornet.se', human(X)). % Shared database used by example 13 shared-database.xml. shared_fact(n3_shared_db). % The statechart datamodel defines local_label/1 too. Its local definition % shadows this shared one while the chart is running. local_label(n3_shared_db). shared_transition_enabled. % Fixed, owner-installed inference capability. No network primitive is % exposed to public source; answers return in the caller's own execution. model_answer(Prompt, Result) :- model_service:model_answer(Prompt, Result). % Bounded multi-turn conversation; history remains owned by the caller. model_chat(Messages, Result) :- model_service:model_chat(Messages, Result). % Fixed, owner-installed Jev capability for examples 23, 24 and 20. It is % unavailable unless N3 starts with WP_JEV_SERVICE=yes and TYPESAFE_API_KEY. jev_deployment_observation(Text, Result) :- jev_service:jev_deployment_observation(Text, Result).