Hive.Registry

hive · API reference

Local type-safe name registry.

Local typed registry: name → capability, with no Obj.magic.

Keys carry a Type.Id witness, so a lookup returns the value only when made with the same key that registered it — type-safe by construction. Names are the unit of uniqueness. Backed by Kcas_data.Hashtbl: safe across domains, lock-free.

Values are typically addresses or server handles, but any capability can be registered. Create the key once, next to the worker module that owns the name, and share it.

type t

A local registry table.

type 'a key

A typed registry key. Values registered with this key have type 'a.

val create : unit -> t

Create an empty registry.

ocaml]
let registry = Hive.Registry.create ()
val key : string -> 'a key

key name makes a fresh key for name. Two keys made with the same name are distinct: each lookup must use the key that registered the value.

Define keys once and share the key value:

ocaml]
let counter_key : Counter.addr Hive.Registry.key =
  Hive.Registry.key "counter"
val name : _ key -> string

The textual name carried by a key.

val register : t -> 'a key -> 'a -> (unit, [ `Already_registered ]) result

Atomic: first registration for the name wins.

ocaml]
match Hive.Registry.register registry counter_key counter_addr with
| Ok () -> ()
| Error `Already_registered -> failwith "counter already started"
val whereis : t -> 'a key -> 'a option

whereis t key returns the value registered under key.

None means the name is free or was registered under a different key.

val unregister : t -> 'a key -> bool

true if this key's binding was removed; false when the name is free or owned by a different key.

val names : t -> string list

Snapshot of registered textual names.

Use this for diagnostics; it does not expose the typed values.