More updates to messaging in the "new" Prova.
1. Added the spawn predicate that runs Java calls as tasks on the task thread pool. The result is shipped back as a message.
2. Added rcvMult reactions that are kept after a matching message arrives. This is comparable with the "every" construct in the Esper event processing language.
3. Any conversations with conversation XID are now always pinned to the same thread so that message ordering is preserved in any given conversation at all times.
4. Started adding control messages mechanism. This allows a sender of a control message to affect a reaction matching the supplied template. The most common use might be to terminate a rcvMult reaction.
The test msg006.prova shows how reaction termination works. Note that that the "Received" is printed from a conversation thread selected based on conversation-id so its order with respect to "Sent"'s is random. However, the termination signal is guaranteed to arrive before the third send is receved by the target conversation thread, so the third reaction never happens.
% This example introduces a new control mechanism for reactions--in this example, termination.
% It works by an agent instructing the receiving reaction matching a template to terminate (eof).
% Message ordering within the same conversation is ensured by conversation-id XID always mapped to the same thread
% from the thread pool based on partitions.
:- eval(msg006()).
msg006() :-
println(["==========Messaging test 006=========="]),
% This reaction will stay active after receiving the first message so that both messages will be received
rcvMult(XID,Protocol,From,inform,a(I)),
println(["Received: ",rcvMult(XID,async,From,inform,a(I))],"").
msg006() :-
% Use the 'async' verb to force the reactions to run on the thread pool ('self' can be used to run on the main agent thread)
sendMsg(XID,async,0,inform,a(1)),
println(["Sent: ",sendMsg(XID,async,0,inform,a(1))],""),
% Send termination signal
sendMsg(XID,async,0,eof,[ReactionXID,Protocol,From,inform,a(_)]),
println(["Sent: ",sendMsg(XID,async,0,eof,[ReactionXID,Protocol,From,inform,a(_)])],""),
% The next message will be ignored as rcvMult will have terminated
sendMsg(XID,async,0,inform,a(2)),
println(["Sent: ",sendMsg(XID,async,0,inform,a(2))],"").
% This prints:
% Sent: [sendMsg,prova:1,async,0,inform,[a,1]]
% Received: [rcvMult,prova:1,async,0,inform,[a,1]]
% Sent: [sendMsg,prova:1,async,0,eof,[,,inform,[a,]]]
% Sent: [sendMsg,prova:1,async,0,inform,[a,2]]