Documentation
¶
Overview ¶
CRC: crc-Backend.md Spec: main.md (UI Server Architecture section) Package backend provides the Backend interface and implementations for the UI server's backend layer. Each session has one Backend instance.
CRC: crc-LuaBackend.md Spec: main.md (UI Server Architecture - Hosted Backend), protocol.md (Session-Based Communication) Sequence: seq-session-create-backend.md, seq-backend-watch.md, seq-backend-detect-changes.md
Index ¶
- type Backend
- type LuaBackend
- func (lb *LuaBackend) ClearDescendants(rootID int64)
- func (lb *LuaBackend) DestroyVariable(varID int64) []int64
- func (lb *LuaBackend) DetectChanges() []VariableUpdate
- func (lb *LuaBackend) GetSessionID() string
- func (lb *LuaBackend) GetTracker() *changetracker.Tracker
- func (lb *LuaBackend) GetWatcherCount(varID int64) int
- func (lb *LuaBackend) GetWatchers(varID int64) []string
- func (lb *LuaBackend) IsInactive(varID int64) bool
- func (lb *LuaBackend) Log(level int, format string, args ...interface{})
- func (lb *LuaBackend) OwnsVariable(varID int64) bool
- func (lb *LuaBackend) SetInactive(varID int64, inactive bool)
- func (lb *LuaBackend) Shutdown()
- func (lb *LuaBackend) TrackVariable(varID int64)
- func (lb *LuaBackend) UntrackVariable(varID int64)
- func (lb *LuaBackend) Unwatch(varID int64, connectionID string) UnwatchResult
- func (lb *LuaBackend) UnwatchAll(connectionID string) []int64
- func (lb *LuaBackend) Watch(varID int64, connectionID string) WatchResult
- type UnwatchResult
- type VariableUpdate
- type WatchResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Watch subscribes a connection to variable changes.
// For LuaBackend: manages tally, registers with tracker if new.
// For ProxiedBackend: relays to external backend.
Watch(varID int64, connectionID string) WatchResult
// Unwatch removes a connection's subscription to variable changes.
// For LuaBackend: decrements tally, unregisters from tracker if zero.
// For ProxiedBackend: relays to external backend.
Unwatch(varID int64, connectionID string) UnwatchResult
// UnwatchAll removes all watches for a connection (on disconnect).
// Returns list of variable IDs that were unwatched.
UnwatchAll(connectionID string) []int64
// GetWatchers returns all connection IDs watching a variable.
GetWatchers(varID int64) []string
// GetWatcherCount returns the current observer count for a variable.
GetWatcherCount(varID int64) int
// DetectChanges computes and returns changes for watched variables.
// Only meaningful for LuaBackend; ProxiedBackend returns nil.
DetectChanges() []VariableUpdate
// GetTracker returns the change-tracker instance for this session.
// Only meaningful for LuaBackend; ProxiedBackend returns nil.
GetTracker() *changetracker.Tracker
// DestroyVariable removes a variable and all its descendants.
// Returns the list of destroyed variable IDs (children before parents).
DestroyVariable(varID int64) []int64
// SetInactive marks a variable as inactive (updates not relayed).
SetInactive(varID int64, inactive bool)
// IsInactive checks if a variable or any ancestor is inactive.
IsInactive(varID int64) bool
// GetSessionID returns the session ID associated with this backend.
GetSessionID() string
// Shutdown cleans up backend resources.
Shutdown()
}
Backend is the interface for hosted (Lua) and proxied backends. Each session has exactly one Backend instance. CRC: crc-Backend.md
type LuaBackend ¶
type LuaBackend struct {
// contains filtered or unexported fields
}
LuaBackend implements Backend for hosted Lua sessions. It owns a per-session change-tracker and manages watch subscriptions. This replaces the global WatchManager with per-session watch management.
func NewLuaBackend ¶
func NewLuaBackend(cfg *config.Config, sessionID string, resolver changetracker.Resolver) *LuaBackend
NewLuaBackend creates a new LuaBackend for a session. The resolver is used for path navigation and wrapper creation. CRC: crc-LuaBackend.md Sequence: seq-session-create-backend.md
func (*LuaBackend) ClearDescendants ¶ added in v0.9.0
func (lb *LuaBackend) ClearDescendants(rootID int64)
ClearDescendants removes all descendant variables of the given root. Used when a page reconnects to clear stale child variables.
func (*LuaBackend) DestroyVariable ¶ added in v0.20.0
func (lb *LuaBackend) DestroyVariable(varID int64) []int64
DestroyVariable removes a variable and all its descendants. Returns the list of destroyed variable IDs (children before parents).
func (*LuaBackend) DetectChanges ¶
func (lb *LuaBackend) DetectChanges() []VariableUpdate
DetectChanges computes and returns changes for watched variables. CRC: crc-LuaBackend.md Sequence: seq-backend-detect-changes.md
func (*LuaBackend) GetSessionID ¶
func (lb *LuaBackend) GetSessionID() string
GetSessionID returns the session ID.
func (*LuaBackend) GetTracker ¶
func (lb *LuaBackend) GetTracker() *changetracker.Tracker
GetTracker returns the change-tracker instance for this session.
func (*LuaBackend) GetWatcherCount ¶
func (lb *LuaBackend) GetWatcherCount(varID int64) int
GetWatcherCount returns the current observer count for a variable.
func (*LuaBackend) GetWatchers ¶
func (lb *LuaBackend) GetWatchers(varID int64) []string
GetWatchers returns all connection IDs watching a variable.
func (*LuaBackend) IsInactive ¶
func (lb *LuaBackend) IsInactive(varID int64) bool
IsInactive checks if a variable or any ancestor has the inactive property set.
func (*LuaBackend) Log ¶
func (lb *LuaBackend) Log(level int, format string, args ...interface{})
Log logs a message via the config.
func (*LuaBackend) OwnsVariable ¶
func (lb *LuaBackend) OwnsVariable(varID int64) bool
OwnsVariable checks if this session owns the given variable.
func (*LuaBackend) SetInactive ¶
func (lb *LuaBackend) SetInactive(varID int64, inactive bool)
SetInactive marks a variable as inactive (updates not relayed).
func (*LuaBackend) Shutdown ¶
func (lb *LuaBackend) Shutdown()
Shutdown cleans up backend resources.
func (*LuaBackend) TrackVariable ¶
func (lb *LuaBackend) TrackVariable(varID int64)
TrackVariable records that this session owns a variable. Used for cleanup and session-scoped variable lookup.
func (*LuaBackend) UntrackVariable ¶
func (lb *LuaBackend) UntrackVariable(varID int64)
UntrackVariable removes a variable from session ownership.
func (*LuaBackend) Unwatch ¶
func (lb *LuaBackend) Unwatch(varID int64, connectionID string) UnwatchResult
Unwatch removes an observer from a variable. Returns UnwatchResult indicating if the unwatch should be forwarded (for bound variables).
func (*LuaBackend) UnwatchAll ¶
func (lb *LuaBackend) UnwatchAll(connectionID string) []int64
UnwatchAll removes all watches for a connection (on disconnect). Returns list of variable IDs that were unwatched.
func (*LuaBackend) Watch ¶
func (lb *LuaBackend) Watch(varID int64, connectionID string) WatchResult
Watch adds an observer for a variable. Returns WatchResult indicating if the watch should be forwarded (for bound variables). CRC: crc-LuaBackend.md Sequence: seq-backend-watch.md
type UnwatchResult ¶
type UnwatchResult struct {
ShouldForward bool // True if tally changed 1->0 for bound variables
Count int // New watch count
}
UnwatchResult indicates whether an unwatch should be forwarded to backend.
type VariableUpdate ¶
type VariableUpdate struct {
VarID int64
Value json.RawMessage
Properties map[string]string
}
VariableUpdate represents a detected change to be sent to the frontend.
type WatchResult ¶
type WatchResult struct {
ShouldForward bool // True if tally changed 0->1 for bound variables
Count int // New watch count
}
WatchResult indicates whether a watch should be forwarded to backend.