Lightning.Collaboration.Registry (Lightning v2.14.5-pre1)
View SourceRegistry for collaboration processes.
This Registry provides local process tracking for the collaboration system, complementing the cluster-wide :pg process groups. It supports the following key patterns:
Supported Key Patterns
{:shared_doc, document_name}
- SharedDoc processes for documents (e.g., "workflow:workflow_id"){:persistence_writer, document_name}
- PersistenceWriter processes (future use){:doc_supervisor, workflow_id}
- DocumentSupervisor processes (future use)
Session processes are not registered here as there may be multiple sessions for the same workflow and the same user.
Registry vs Process Groups
This Registry is used for local node process lookup and coordination, while
:pg
(process groups) remains for cluster-wide SharedDoc uniqueness. The
Registry provides faster local lookups and better integration with supervision
trees.
Usage
Processes can register themselves either in their init callback or using via tuples in their child_spec:
# Session registration in init callback
Lightning.Collaboration.Registry.register({:session, "workflow_123", "user_456"})
# SharedDoc registration via child_spec
{SharedDoc, [
doc_name: "workflow:workflow_123",
name: {:via, Registry, {Lightning.Collaboration.Registry.registry_name(), {:shared_doc, "workflow:workflow_123"}}}
]}
Summary
Functions
Child specification for starting the Registry.
Look up all processes registered with the given key.
Register the current process with the given key.
Select processes registered with the given key (prefix).
Find the pid registered with the given key.
Functions
Child specification for starting the Registry.
Look up all processes registered with the given key.
Returns a list of {pid, value} tuples. Since we use unique keys, this will typically return a single-item list or an empty list.
Examples
Lightning.Collaboration.Registry.lookup({:session, "workflow_123"})
# => [{#PID<0.123.0>, nil}]
Lightning.Collaboration.Registry.lookup({:session, "nonexistent"})
# => []
Register the current process with the given key.
Examples
Lightning.Collaboration.Registry.register({:session, "workflow_123"})
# => {:ok, #PID<0.123.0>}
Lightning.Collaboration.Registry.register({:shared_doc, "workflow:workflow_123"})
# => {:ok, #PID<0.123.0>}
Error Cases
Lightning.Collaboration.Registry.register({:session, "workflow_123"})
# => {:error, {:already_registered, #PID<0.456.0>}}
Select processes registered with the given key (prefix).
The key pattern expected is:
{:type, key}
{:type, key, any()}
.
We do a select with any key that starts with the given key.
Find the pid registered with the given key.
This is a convenience function that returns just the pid, or nil if no process is registered.
Examples
Lightning.Collaboration.Registry.whereis({:session, "workflow_123"})
# => #PID<0.123.0>
Lightning.Collaboration.Registry.whereis({:session, "nonexistent"})
# => nil