actor

package
v1.4.26 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: GPL-3.0 Imports: 21 Imported by: 5

Documentation

Index

Constants

View Source
const DefaultTimeout = time.Second * 10

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor added in v1.0.4

type Actor interface {
	ID() string
	System() *System
	Exit()
}

type Base

type Base struct {
	Actor
	Timer
	Messenger
	Drainer
}

func (*Base) Exit added in v1.4.1

func (s *Base) Exit()

func (*Base) OnHandle added in v1.3.0

func (s *Base) OnHandle(Message)

func (*Base) OnInit

func (s *Base) OnInit()

func (*Base) OnStop

func (s *Base) OnStop() bool

type BaseFunc added in v1.4.1

type BaseFunc struct {
	Base
	Init   func()
	Stop   func() bool
	Handle func(msg Message)
}

func (*BaseFunc) OnHandle added in v1.4.1

func (s *BaseFunc) OnHandle(msg Message)

func (*BaseFunc) OnInit added in v1.4.1

func (s *BaseFunc) OnInit()

func (*BaseFunc) OnStop added in v1.4.1

func (s *BaseFunc) OnStop() bool

type Drainer added in v1.4.1

type Drainer interface {
	Drain(afterDrained func(), timeout ...time.Duration)
	// contains filtered or unexported methods
}

type Handler added in v1.2.21

type Handler interface{}

type Id added in v1.2.21

type Id = string

type Message added in v1.3.0

type Message interface {
	GetSourceId() Id
	GetTargetId() Id
	GetRequestId() string
	GetMsgName() string
	Payload() interface{}
	String() string
	Free()
}

type Messenger added in v1.4.1

type Messenger interface {
	Send(targetId Id, msg any) error
	Request(targetId Id, msg any, timeout ...time.Duration) (req *request)
	RequestWait(targetId Id, msg any, timeout ...time.Duration) (result interface{}, err error)
	Response(requestId string, msg any) error
}

type Option added in v1.1.10

type Option func(*actor)

Option the extra options of the new actor

func SetLocalized

func SetLocalized() Option

SetLocalized indicates that it can't be discovered by other System, meaning, this actor is localized.

func SetMailBoxSize

func SetMailBoxSize(boxSize int) Option

type RequestId added in v1.3.0

type RequestId string

func (RequestId) Parse added in v1.3.0

func (r RequestId) Parse() (sourceId string, targetId string, sourceAddr string, ok bool)

func (RequestId) String added in v1.3.0

func (r RequestId) String() string

func (RequestId) Valid added in v1.3.0

func (r RequestId) Valid() bool

type System

type System struct {
	Stopped chan struct{}

	// bind the inter-service communication port
	// to system-assigned random port
	Addr string
	// contains filtered or unexported fields
}

func NewSystem

func NewSystem(op ...SystemOption) (*System, error)

func (*System) CancelAll

func (ed *System) CancelAll(actorId Id)

func (*System) CancelEvent

func (ed *System) CancelEvent(actorId Id, events ...interface{})

func (*System) Cluster added in v1.2.18

func (s *System) Cluster() Id

func (*System) DispatchEvent

func (ed *System) DispatchEvent(sourceId Id, event interface{})

func (*System) HasActor added in v1.4.0

func (s *System) HasActor(actorId string) bool

func (*System) NewActor added in v1.4.0

func (s *System) NewActor(id Id, handler spawnActor, opt ...Option) error

NewActor new an actor for system id is invalid if contain '@' or '$'

func (*System) OnEvent added in v1.2.21

func (ed *System) OnEvent(actorId Id, callback Handler)

func (*System) ProtoIndex added in v1.2.2

func (s *System) ProtoIndex() *tools.ProtoIndex

func (*System) Send

func (s *System) Send(sourceId, targetId Id, requestId RequestId, msg any) (err error)

Send try to send the message to target

func (*System) SetCluster

func (s *System) SetCluster(id Id)

func (*System) Stop

func (s *System) Stop()

func (*System) WaiterId added in v1.2.21

func (s *System) WaiterId() string

type SystemOption

type SystemOption func(*System) error

func LogFileName added in v1.4.12

func LogFileName(path, fileName string) SystemOption

func LogLevel added in v1.3.6

func LogLevel(level logger.Level) SystemOption

func Name added in v1.3.9

func Name(name string) SystemOption

func Output added in v1.3.6

func Output(out io.Writer) SystemOption

func ProtoIndex added in v1.2.0

func ProtoIndex(pi *tools.ProtoIndex) SystemOption

ProtoIndex index proto struct

type Timer added in v1.1.1

type Timer interface {
	AddTimer(timeId string, endAt time.Time, callback func(dt time.Duration), times ...int) string
	CancelTimer(timerId string)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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