control

package
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package control owns per-device control-session lifecycles and serialization. It deliberately knows nothing about MCP, CLI, or the JetKVM wire protocol.

Index

Constants

View Source
const (
	DefaultIdleTimeout      = 5 * time.Minute
	DefaultAbsoluteLifetime = 30 * time.Minute
	DefaultSweepInterval    = time.Second
	DefaultCleanupTimeout   = 5 * time.Second
)

Variables

View Source
var (
	ErrInvalidConfig      = errors.New("invalid control configuration")
	ErrControlNotFound    = errors.New("control handle was not found")
	ErrControlExpired     = errors.New("control handle expired")
	ErrGenerationMismatch = errors.New("control generation mismatch")
	ErrControlBusy        = errors.New("control is draining")
	ErrRegistryClosed     = errors.New("control registry is closed")
	ErrCapabilityMissing  = errors.New("control capability is unavailable")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Factory          SessionFactory
	Locker           Locker
	IdleTimeout      time.Duration
	AbsoluteLifetime time.Duration
	SweepInterval    time.Duration
	CleanupTimeout   time.Duration
	Now              func() time.Time
	NewHandleID      func() HandleID
}

type ExecuteFunc

type ExecuteFunc func(context.Context, Session) error

ExecuteFunc runs inside the per-device write queue. The Session value is valid only for the duration of the callback and must not be retained.

type Handle

type Handle struct {
	ID                HandleID
	DeviceID          domain.DeviceID
	Generation        uint64
	Ownership         Ownership
	Capabilities      []string
	State             HandleState
	CreatedAt         time.Time
	LastUsedAt        time.Time
	IdleExpiresAt     time.Time
	AbsoluteExpiresAt time.Time
}

Handle identifies one generation of one device control session.

type HandleID

type HandleID string

HandleID is an opaque control lease identifier.

type HandleState

type HandleState string
const (
	HandleReady    HandleState = "ready"
	HandleDraining HandleState = "draining"
	HandleExpired  HandleState = "expired"
	HandleClosed   HandleState = "closed"
	HandleFenced   HandleState = "fenced"
)

type Lock

type Lock interface {
	Release() error
}

Lock is held for the complete lifetime of a device session.

type Locker

type Locker interface {
	Acquire(context.Context, domain.DeviceID) (Lock, error)
}

Locker prevents independent local processes from controlling one device at the same time.

type OpenRequest

type OpenRequest struct {
	DeviceID         domain.DeviceID
	Capabilities     []string
	Ownership        Ownership
	IdleTimeout      time.Duration
	AbsoluteLifetime time.Duration
}

type Ownership

type Ownership string
const (
	OwnershipOwned    Ownership = "owned"
	OwnershipAttached Ownership = "attached"
)

type Ref

type Ref struct {
	ID                 HandleID
	ExpectedGeneration uint64
}

Ref fences an operation to the exact handle generation observed by its caller.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry owns one actor per stable device identity.

func NewRegistry

func NewRegistry(config Config) (*Registry, error)

func (*Registry) Close

func (r *Registry) Close(ctx context.Context, deviceID domain.DeviceID, ref Ref) (Handle, error)

func (*Registry) Drain

func (r *Registry) Drain(ctx context.Context) error

Drain stops accepting new work, drains every per-device queue, closes owned sessions, and releases all cross-process locks.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, deviceID domain.DeviceID, ref Ref, capability string, execute ExecuteFunc) error

Execute serializes state-changing work for one device while allowing other device actors to progress independently.

func (*Registry) Get

func (r *Registry) Get(ctx context.Context, deviceID domain.DeviceID, ref Ref) (Snapshot, error)

func (*Registry) Open

func (r *Registry) Open(ctx context.Context, request OpenRequest) (Handle, error)

func (*Registry) Quiescent added in v1.0.6

func (r *Registry) Quiescent(ctx context.Context) (bool, error)

Quiescent queries actor-owned state. The caller must exclude new operations until its reconfiguration is complete; this is not a substitute for that gate.

func (*Registry) Reconnect

func (r *Registry) Reconnect(ctx context.Context, deviceID domain.DeviceID, ref Ref) (Handle, error)

Reconnect replaces the protocol session, fences the old handle, and returns a new handle with a strictly greater generation.

func (*Registry) State

func (r *Registry) State() TransportState

type Session

type Session interface {
	Close(context.Context) error
	Disconnect(context.Context) error
}

Session is the protocol adapter resource owned by a DeviceActor. Concrete implementations may expose richer APIs to Execute callbacks.

type SessionFactory

type SessionFactory interface {
	Open(context.Context, domain.DeviceID, uint64, []string) (Session, error)
}

SessionFactory creates a fresh protocol session for one fenced generation.

type SessionState

type SessionState string
const (
	SessionAbsent    SessionState = "absent"
	SessionOpening   SessionState = "opening"
	SessionReady     SessionState = "ready"
	SessionDraining  SessionState = "draining"
	SessionClosing   SessionState = "closing"
	SessionClosed    SessionState = "closed"
	SessionUncertain SessionState = "uncertain"
)

type Snapshot

type Snapshot struct {
	Transport TransportState
	Session   SessionState
	Handle    *Handle
}

Snapshot reports the three independent lifecycle state machines.

type TransportState

type TransportState string
const (
	TransportRunning  TransportState = "running"
	TransportDraining TransportState = "draining"
	TransportClosed   TransportState = "closed"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL