class

Arcana::Actor

Inherits Reference < Object

OTP-inspired actor base class.

Subclass and implement handle to process incoming envelopes. Actors register in the Directory, listen on the Bus, and follow the Protocol handshake automatically.

class MyAgent < Arcana::Actor def init # setup state end

def handle(envelope : Arcana::Envelope)
  data = extract_data(envelope.payload)
  reply(envelope, Protocol.result(JSON::Any.new("done")))
end

end

agent = MyAgent.new(bus, dir, "my-agent", "My Agent", "Does things") agent.start

Constructors

new(bus : Bus, directory : Directory, address : String, name : String, description : String, schema : JSON::Any | Nil = nil, guide : String | Nil = nil, tags : Array(String) = [] of String)
Source

Instance methods

address
Source
handle(envelope : Envelope)

Handle an incoming envelope. Override this.

Source
init

Called when the actor starts, before processing messages.

Source
on_error(envelope : Envelope, error : Exception)

Called when handle raises. Default: re-raise (let it crash). Override to swallow errors and keep processing.

Source
register

Register in directory and bus. Called before run.

Source
run

Run the message loop. Blocks until stopped or crashed.

Source
running?
Source
start

Start in a new fiber (standalone, unsupervised).

Source
stop

Signal the actor to stop after processing the current message.

Source
terminate

Called when the actor stops.

Source