Actor Module (Actor-model for parallel XQuery processing)

http://xqerl.org/modules/actor

This module is statically bound to the prefix "actor".

Description

Module for spawning processes mid-query and asynchronous message-passing between these processes.

(: Save the address of the current actor :)
let $replyTo := actor:self()
(: Spawn 10,000 child actors and save their addresses in $children :)
let $children := (
for $a in 1 to 10000
(: Build a 0-arity function to spawn :)
let $fun :=
function()
{
(: Build a nice message and send it to the actor addressed by $replyTo :)
let $cmt := ``[From `{ $a }`: Hi, my name is `{ actor:self() }`.]``
return
actor:send($replyTo, $cmt)
}
return
(: Spawn the actor :)
actor:spawn($fun)
)
return
(: Collect the responses sent to this actor by their 'from' address
These will be in the order sent :)
$children ! actor:receive(.)
(: $children ! actor:receive() would return in a possibly different order
as the messages would be taken in the order received and not by address :)
Functions

actor:spawn


Signature
actor:spawn($fun as function() as item()*) as xs:base64Binary
Description
Spawns a child actor that begins executing the 0-arity function passed to it. Returns the address of the child actor.
back to top

actor:self


Signature
actor:self() as xs:base64Binary
Description
Returns the address of the actor executing the function.
back to top

actor:parent


Signature
actor:parent() as xs:base64Binary?
Description
Returns the address of the actor which spawned the current actor, or the empty-sequence if this is the root actor.
back to top

actor:send


Signature
actor:send($address as xs:base64Binary, $payload as item()*) as empty-sequence()
Description
Sends an asynchronous message containing $payload to $address.
back to top

actor:receive


Signature
actor:receive() as item()*
actor:receive($from as xs:base64Binary) as item()*

actor:receive($from as xs:base64Binary, $timeout as xs:integer) as item()*
Description
Receives a message. When no parameters are given, receives the next message in the queue. When $from is given, will block until a message from that actor is received (optionally with a timeout in milliseconds). Upon timeout, an error will be raised.
back to top