GtBridge.ObjectRegistry (gt_bridge v0.17.3)

Copy Markdown View Source

I am a Registry for objects that are referenced from GT.

This allows GT to keep references to Elixir objects via IDs, and handles cleanup when GT's proxy objects are garbage collected.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get an object by ID.

Get the value of a specific attribute from an object by ID.

List all attributes (field names) of an object by ID. For structs, returns the field names. For maps, returns the keys.

Register an object and return its ID.

Remove an object by ID (called when GT garbage collects the proxy).

I batch-remove multiple objects by ID. Called by GtBridge.Eval.terminate/2 to clean up all objects registered during a session's lifetime.

Resolve an object by ID, returning the object directly (or nil if not found). This is the function GT should call when retrieving lazy objects.

Start the object registry.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(server \\ __MODULE__, id)

@spec get(GenServer.server(), non_neg_integer()) :: {:ok, any()} | :error

Get an object by ID.

get_attribute(id, attribute_name)

@spec get_attribute(non_neg_integer(), atom() | String.t()) :: any() | nil

Get the value of a specific attribute from an object by ID.

list_attributes(id)

@spec list_attributes(non_neg_integer()) :: [atom() | String.t()] | nil

List all attributes (field names) of an object by ID. For structs, returns the field names. For maps, returns the keys.

register(server \\ __MODULE__, object)

@spec register(GenServer.server(), any()) :: non_neg_integer() | nil

Register an object and return its ID.

remove(server \\ __MODULE__, id)

@spec remove(GenServer.server(), non_neg_integer()) :: :ok

Remove an object by ID (called when GT garbage collects the proxy).

remove_all(server \\ __MODULE__, ids)

@spec remove_all(GenServer.server(), [non_neg_integer()]) :: :ok

I batch-remove multiple objects by ID. Called by GtBridge.Eval.terminate/2 to clean up all objects registered during a session's lifetime.

resolve(id)

@spec resolve(non_neg_integer()) :: any() | nil

Resolve an object by ID, returning the object directly (or nil if not found). This is the function GT should call when retrieving lazy objects.

start_link(opts \\ [])

Start the object registry.