Documentation
¶
Overview ¶
Package backend provides the capability runtime backend registry and lifecycle management. A runtime backend registers itself with the registry, and the registry dispatches Start calls to the backend named by the frozen capability runtime's runtime.kind.
Two backends are registered by this build: process, which hosts a capability runtime as a worker process, and wasm, which hosts one as a module. The container and remote kinds exist in the shared contract but have no backend here, so an assembly frozen against them is rejected at resolution rather than failing later at execution.
The registry deliberately does not track the instances it launches. It cannot own them, because sharing them is the backend's decision and each backend shares differently: the process backend keeps one worker pool per capability runtime and refcounts it by holder, the WASM backend keeps its compiled modules and its sandbox runtime on the backend itself, and the legacy JSON transport holds nothing at all between executions. A registry that tracked instances by type@version would only be able to record the last handle it handed out, which is exactly the kind of ownership claim it cannot honour. See Register and CloseBackends.
Index ¶
- type Registry
- func (r *Registry) CloseBackends(ctx context.Context) error
- func (r *Registry) Register(kind string, backend capabilityrt.Backend) error
- func (r *Registry) RegisteredKinds() []string
- func (r *Registry) Start(ctx context.Context, kind string, spec capabilityrt.BackendSpec) (capabilityrt.BackendInstance, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry routes capability runtime launches to the backend registered for a runtime kind. It owns the backends, not the instances they launch.
func New ¶
func New() *Registry
New returns a Registry with no backends registered. Call Register to add runtime backends before starting any instances.
func (*Registry) CloseBackends ¶
CloseBackends releases the process-global resources held by the registered backends and collects the failures.
It runs once at shutdown, after the instances have stopped. Instances are stopped first because that is where they give up their own references; this is then the backstop for anything an instance failed to release, and for the state a backend keeps with no per-instance handle at all.
func (*Registry) Register ¶
func (r *Registry) Register(kind string, backend capabilityrt.Backend) error
Register adds a runtime backend for the given kind. Registering an existing kind replaces the backend, which must not happen once anything has been started through it: the replacement would not own the instances already running, and they would be released by neither backend.
func (*Registry) RegisteredKinds ¶
RegisteredKinds returns the registered backend kinds, sorted. It is used to tell a caller which runtime kinds this build can host.
func (*Registry) Start ¶
func (r *Registry) Start(ctx context.Context, kind string, spec capabilityrt.BackendSpec) (capabilityrt.BackendInstance, error)
Start launches a capability runtime instance through the backend registered for the given kind.
The returned instance is owned by its backend, not by the caller and not by this registry. Callers that share one must each close their own instance when they are done: for the process backend that releases a single holder of a shared worker pool, so the runtime survives as long as anything is still using it.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package process implements a Backend that hosts capability runtimes as OS child processes.
|
Package process implements a Backend that hosts capability runtimes as OS child processes. |
|
Package wasm implements a Backend that hosts capability runtimes as WebAssembly modules using wazero, the pure-Go WASI runtime.
|
Package wasm implements a Backend that hosts capability runtimes as WebAssembly modules using wazero, the pure-Go WASI runtime. |