A formalization of the actor model family in Julia.
The goal of this project is to provide a standard and usable API for actor programming. Applications written using this API will be independent from any specific actor library, and will run under all implementations of ActorInterfaces.jl.
There is no such thing as The Actor Model, there are interpretations and extensions of it. ActorInterfaces tries to handle this diversity by defining a minimalistic base called the Classic Model, and extensions to it.
The Classic model is the one described by Gul Agha in the book "ACTORS: A Model of Concurrent Computation in Distributed Systems":
Actors are computational agents which map each incoming communication to a 3-tuple consisting of:
- a finite set of communications sent to other actors;
- a new behavior (which will govern the response to the next communication processed); and,
- a finite set of new actors created.
ActorInterfaces.Classic
maps these to the primitives send()
, become()
and spawn()
. The incoming communication will be dispatched to onmessage()
.
Agha's stack example illustrates the API:
using ActorInterfaces.Classic
struct Pop
customer::Addr
end
struct Push
content
end
struct StackNode
content
link::Union{Addr, Nothing} # The next node
end
struct Forwarder
target::Addr
end
@ctx function Classic.onmessage(me::Forwarder, msg)
send(me.target, msg)
end
@ctx function Classic.onmessage(me::StackNode, msg::Push)
p = spawn(StackNode(me.content, me.link))
become(StackNode(msg.content, p))
end
@ctx function Classic.onmessage(me::StackNode, msg::Pop)
if !isnothing(me.link)
become(Forwarder(me.link))
end
send(msg.customer, me.content)
end
Please note that this runs inefficiently on implementations that lack forward-chain optimization.
Actor libraries currently provide their own API for exchanging messages with actors from the outside of the actor system. It is not yet covered by ActorInterfaces.
- QuickActors.jl, the reference implementation.
The Classic interface settled recently, major semantical changes are unlikely. Extensions will be added continously. If you have an extension idea, please open an issue or a topic on Discourse.