Next: , Previous: , Up: Programs   [Contents][Index]


3.9.4 Action Sequences

An Action Sequence can be entered as an interpreter command. It has the form

{} (the empty action sequence)

or 

ActOrQuery1 ; ActOrQuery12 ; ... ; ActOrQueryn, n>=1

with each ActOrQueryi one of:

A Simple Action Sequence is an Action Sequence which does not contain any forall, receive or wait actions.

3.9.4.1 Receive Action

When a blocking receive is executed by a QuLog thread the message buffer of the thread is searched from the oldest message to the most recent to see if there is a message term that is an instance of one of the message patterns MessPtni from a sender with handle that is an instance of HandlePtni. The receive patterns are tried in their given before/after order. If a message is found that satisfies the two constraints of the ith rule it is removed, the Acti simple action sequence is executed and the receive is exited. Should the end message buffer be reached with no acceptable message found the thread will suspend until a new message arrives. Each new message is tested for acceptability. If there is a timeout rule this will be fired when T seconds have elapsed since the thread started its search for an acceptable message. DefaultAct is executed and the receive is exited. If there is no timeout rule the receive action will block indefinitely waiting for an acceptable message.

3.9.4.2 Discarding messages

The action rules handle_messages defines a non-terminating message receive behaviour that will process request and ask messages of the allowd form from agents allowed to send such messages. It removes all messages not satisfying either test. There is no action when a messages is discarded.

act handle_messages()
handle_messages()
 receive {
   request(TaskCall) from Agent :: can_request(Agent,TaskCall) ~>
                           {fork TaskCall as TaskId; 
                            remember(taskfor(Agent,TaskId,Task)}
   ask(Id,Ans,Query) from Agent :: can_ask(Agent,Query) ~> 
                           {eval(Query); ans(Id,Ans) to Agent}
   _ from _ ~> {}
   };
   handle_messages()

An alternative is to send some reply when a message is discarded as in:

handle_messages()
receive {
   request(TaskCall) from Agent :: can_request(Agent,TaskCall) ~>
                  {fork TaskCall as TaskId; 
                   remember(taskfor(Agent,TaskId,Task)}
   request(TaskCall) from Agent ~> cannot_request(TaskCall) to Agent
   ask(Id,Ans,Query) from Agent :: can_ask(Agent,Query) ~> 
                  {eval(Query); ans(Id,Ans) to Agent}
   ask(Id,Ans,Query) from Agent ~> cannot_ask(Query) to Agent
   discard Mess from Agent ~> invalid_message(Mess) to Agent
   };
   handle_messages()

Here the second and fourth rules send suitable messages when the tests of the first and third rules have failed for request and ask messages, and the last messagesends and invalid_message response for all other messages.


Next: , Previous: , Up: Programs   [Contents][Index]