actor

package
v0.16.6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

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

Actor represents a single server actor with its own goroutine and state machine. Each actor manages the lifecycle of one upstream server connection independently.

func New

func New(cfg ActorConfig, client *managed.Client, logger *zap.Logger) *Actor

New creates a new actor for a server.

func (*Actor) Events

func (a *Actor) Events() <-chan Event

Events returns the event channel for this actor.

func (*Actor) GetClient

func (a *Actor) GetClient() *managed.Client

GetClient returns the current managed client (for compatibility).

func (*Actor) GetState

func (a *Actor) GetState() State

GetState returns the current state (thread-safe).

func (*Actor) SendCommand

func (a *Actor) SendCommand(cmd Command)

SendCommand sends a command to the actor.

func (*Actor) Start

func (a *Actor) Start()

Start begins the actor's event loop in a dedicated goroutine.

func (*Actor) Stop

func (a *Actor) Stop()

Stop gracefully stops the actor.

func (*Actor) UpdateClient

func (a *Actor) UpdateClient(client *managed.Client)

UpdateClient updates the underlying managed client (used during reconfiguration).

type ActorConfig

type ActorConfig struct {
	Name           string
	ServerConfig   *config.ServerConfig
	MaxRetries     int
	RetryInterval  time.Duration
	ConnectTimeout time.Duration
}

ActorConfig holds the configuration for an actor

type Command

type Command struct {
	Type CommandType
	Data map[string]interface{}
}

Command represents a command sent to the actor

type CommandType

type CommandType string

CommandType describes the kind of command

const (
	// CommandConnect tells the actor to connect
	CommandConnect CommandType = "connect"

	// CommandDisconnect tells the actor to disconnect
	CommandDisconnect CommandType = "disconnect"

	// CommandStop tells the actor to stop
	CommandStop CommandType = "stop"

	// CommandUpdateConfig tells the actor to update its configuration
	CommandUpdateConfig CommandType = "update_config"
)

type Event

type Event struct {
	Type      EventType
	State     State
	Timestamp time.Time
	Error     error
	Data      map[string]interface{}
}

Event represents an actor lifecycle event

type EventType

type EventType string

EventType describes the kind of actor event

const (
	// EventStateChanged means the actor changed state
	EventStateChanged EventType = "state_changed"

	// EventConnected means the actor successfully connected
	EventConnected EventType = "connected"

	// EventDisconnected means the actor disconnected
	EventDisconnected EventType = "disconnected"

	// EventError means the actor encountered an error
	EventError EventType = "error"

	// EventRetrying means the actor is retrying connection
	EventRetrying EventType = "retrying"
)

type State

type State string

State represents the actor's connection state

const (
	// StateIdle means the actor is waiting for commands
	StateIdle State = "idle"

	// StateConnecting means the actor is attempting to connect
	StateConnecting State = "connecting"

	// StateConnected means the actor is connected and ready
	StateConnected State = "connected"

	// StateDisconnecting means the actor is disconnecting
	StateDisconnecting State = "disconnecting"

	// StateError means the actor encountered an error
	StateError State = "error"

	// StateStopped means the actor has been stopped
	StateStopped State = "stopped"
)

Jump to

Keyboard shortcuts

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