class

Earl::Registry(A, M)

Inherits Reference < Object

A concurrency-safe registry of agents.

  • Agents of type A may (un)register from the registry at any time.
  • Registered agents can be iterated with #each.
  • Sent messages of type M are broadcasted to all registered agents.
  • Failing to deliver a message to an agent will silently unregister it.

Concurrency

Relies on a copy-on-write array:

  • (un)registering an agent will duplicate the current array (in a lock);
  • iterations always iterate an immutable older reference to the array.

This assumes that agents will (un)register themselves infrequently and messages be sent much more often.

Constructors

new

Instance methods

closed?
each

Iterates registered agents. Always iterates agents registered at the moment the iteration is started. Newly registered agents won't be iterated, when newly unregistered agents will be.

register(agent : A) : Nil

Registers an agent. Raises if the registry is closed.

send(message : M) : Nil

Broadcasts a message to all registered agents at the time

stop

Closes the registry, preventing agents to register, then asks all registered agents to stop.

unregister(agent : A) : Nil

Unregisters an agent.