actor

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: GPL-3.0 Imports: 18 Imported by: 5

Documentation

Index

Constants

View Source
const DefaultTimeout = time.Second * 30

Variables

This section is empty.

Functions

func LDebug

func LDebug(l *lua.LState) int

func LError

func LError(l *lua.LState) int

func LGoVersion

func LGoVersion(l *lua.LState) int

func LWarn

func LWarn(l *lua.LState) int

func New

func New(id string, handler spawnActor, op ...ActorOption) *actor

New 创建actor id actorId外部定义 @和$为内部符号,其他id尽量不占用 handler 消息处理模块 op 修改默认属性

func ParseRequestId

func ParseRequestId(requestId string) (sourceId string, targetId string, sourceAddr string, ok bool)

Types

type Actor added in v1.0.4

type Actor interface {
	//core
	GetID() string
	System() *System
	Exit()

	//timer
	AddTimer(timeId string, interval time.Duration, callback func(dt int64), trigger_times ...int32) string
	CancelTimer(timerId string)

	//lua
	CallLua(name string, ret int, args ...lua.LValue) []lua.LValue

	// Send 不保证消息发送可靠性
	Send(targetId string, msg interface{}) error
	Request(targetId string, msg interface{}, timeout ...time.Duration) (req *request)
	RequestWait(targetId string, msg interface{}, timeout ...time.Duration) (result interface{}, err error)
	Response(requestId string, msg interface{}) error

	//cmd
	RegistCmd(cmd string, fn func(...string))
}

type ActorOption

type ActorOption func(*actor)

func SetLocalized

func SetLocalized() ActorOption

func SetLua

func SetLua(path string) ActorOption

func SetMailBoxSize

func SetMailBoxSize(boxSize int) ActorOption

=========================

func SetTimerAccuracy

func SetTimerAccuracy(acc int64) ActorOption

type Base

type Base struct {
	Actor
}

Base 创建Actor统一通过Base继承

func (*Base) OnHandleEvent

func (s *Base) OnHandleEvent(event interface{})

func (*Base) OnHandleMessage

func (s *Base) OnHandleMessage(sourceId, targetId string, msg interface{})

func (*Base) OnHandleRequest

func (s *Base) OnHandleRequest(sourceId, targetId, requestId string, msg interface{}) (respErr error)

func (*Base) OnInit

func (s *Base) OnInit()

默认方法,需要的子类重写

func (*Base) OnStop

func (s *Base) OnStop() bool

type Ev_clusterUpdate

type Ev_clusterUpdate struct {
	ActorId string
	Host    string
	Add     bool
}

type Ev_delActor

type Ev_delActor struct {
	ActorId     string
	Publish     bool
	FromCluster bool
}

type Ev_newActor

type Ev_newActor struct {
	ActorId     string
	Publish     bool
	FromCluster bool
}

type Ev_sessionClosed added in v1.0.4

type Ev_sessionClosed struct {
	PeerHost string
}

type Ev_sessionOpened added in v1.0.4

type Ev_sessionOpened struct {
	PeerHost string
}

type ICmd

type ICmd interface {
	Start(actorSystem *System)
	RegistCmd(actorId, cmd string, f func(...string))
}

type System

type System struct {
	CStop chan struct{}
	// contains filtered or unexported fields
}

func NewSystem

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

func (*System) Address

func (s *System) Address() string

func (System) CancelAll

func (ed System) CancelAll(actorId string)

取消actor事件

func (System) CancelEvent

func (ed System) CancelEvent(actorId string, events ...interface{}) error

取消actor事件

func (System) DispatchEvent

func (ed System) DispatchEvent(sourceId string, event interface{}) error

事件触发

func (*System) Regist

func (s *System) Regist(actor *actor) error

注册actor,外部创建对象,保证ActorId唯一性

func (*System) RegistCmd

func (as *System) RegistCmd(actorId, cmd string, fn func(...string))

func (System) RegistEvent

func (ed System) RegistEvent(actorId string, events ...interface{}) error

注册actor事件

func (*System) Send

func (s *System) Send(sourceId, targetId, requestId string, msg interface{}) error

actor之间发送消息, sourceid 发送源actor targetid 目标actor message 消息内容

func (*System) SetCluster

func (s *System) SetCluster(id string)

func (*System) Stop

func (s *System) Stop()

type SystemOption

type SystemOption func(*System) error

所有actor的驱动器和调度器

func Addr

func Addr(addr string) SystemOption

设置Actor监听的端口

func WithCMD

func WithCMD(cmd ICmd) SystemOption

设置Actor监听的端口

Jump to

Keyboard shortcuts

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