Documentation
¶
Overview ¶
Package session manages live sessions and their channels.
Package session is the in-memory session and channel registry.
Index ¶
- Variables
- type ConnectFunc
- type Handle
- func (h *Handle) Close() error
- func (h *Handle) HealthCheck(ctx context.Context) error
- func (h *Handle) OpenChannel(ctx context.Context, req plugin.ChannelRequest) (plugin.Channel, error)
- func (h *Handle) Session() plugin.Session
- func (h *Handle) Snapshot() Snapshot
- func (h *Handle) TrackStream() func()
- type Key
- type Manager
- func (m *Manager) Acquire(ctx context.Context, key Key, userID string, connect ConnectFunc) (*Handle, error)
- func (m *Manager) Close(key Key)
- func (m *Manager) CloseConnection(connectionID string)
- func (m *Manager) IdleTimeout() time.Duration
- func (m *Manager) Shutdown()
- func (m *Manager) Stats() Stats
- func (m *Manager) Status(key Key) (Snapshot, bool)
- type Options
- type Snapshot
- type State
- type Stats
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSessionClosed is returned when using a session that has been closed. ErrSessionClosed = errors.New("session: closed") // ErrSessionLimit is returned when a user is at their max session count. ErrSessionLimit = errors.New("session: per-user limit reached") // ErrChannelLimit is returned when a session is at its max channel count. ErrChannelLimit = errors.New("session: per-session channel limit reached") )
Functions ¶
This section is empty.
Types ¶
type ConnectFunc ¶
ConnectFunc lazily opens the upstream session on first use.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is a borrowed reference to a live session. It opens tracked channels and keeps the session marked as recently used.
func (*Handle) OpenChannel ¶
func (h *Handle) OpenChannel(ctx context.Context, req plugin.ChannelRequest) (plugin.Channel, error)
OpenChannel opens a tracked upstream stream, enforcing the per-session channel cap. The returned channel decrements the counter exactly once on Close.
func (*Handle) TrackStream ¶
func (h *Handle) TrackStream() func()
TrackStream pins the session while a browser stream is active. Not every plugin stream maps to an upstream Channel, but an open WS still means the session is in use and must not be reclaimed as idle.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the session registry and lifecycle.
func (*Manager) Acquire ¶
func (m *Manager) Acquire(ctx context.Context, key Key, userID string, connect ConnectFunc) (*Handle, error)
Acquire returns the live session for key, lazily connecting on first use.
func (*Manager) CloseConnection ¶
CloseConnection closes and removes every live session for a connection across all owner scopes. Callers use this after connection config changes so cached plugin options cannot outlive the saved connection state.
func (*Manager) IdleTimeout ¶
IdleTimeout returns the configured idle session timeout.
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown()
Shutdown stops the janitor and closes every live session.
type Options ¶
type Options struct {
IdleTimeout time.Duration
MaxSessionsPerUser int
MaxChannelsPerSession int
HealthInterval time.Duration
FailureRetention time.Duration
}
Options bound the registry. Zero values fall back to sensible defaults.
type Snapshot ¶
type Snapshot struct {
Key Key
UserID string
State State
Reason string
Channels int
Streams int
LastUsed time.Time
CreatedAt time.Time
LastHealthCheck time.Time
}
Snapshot is a point-in-time view of one live registry entry.