actor

package
v1.0.1 Latest Latest
Warning

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

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

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 added in v1.0.1

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

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

func ParseRequestId

func ParseRequestId(requestId string) (source string, target string, addr string, ok bool)

Types

type ActorHanlerBase

type ActorHanlerBase struct {
	IActor
}

func (*ActorHanlerBase) BResponse

func (s *ActorHanlerBase) BResponse(requestId string, msg interface{})

func (*ActorHanlerBase) HandleEvent

func (s *ActorHanlerBase) HandleEvent(event interface{})

func (*ActorHanlerBase) HandleMessage

func (s *ActorHanlerBase) HandleMessage(sourceId, targetId string, msg interface{})

func (*ActorHanlerBase) HandleRequest

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

func (*ActorHanlerBase) Init

func (s *ActorHanlerBase) Init()

func (*ActorHanlerBase) Stop

func (s *ActorHanlerBase) Stop() bool

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 ActorSystem

type ActorSystem struct {
	*EventDispatcher
	// contains filtered or unexported fields
}

func System added in v1.0.1

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

func (*ActorSystem) Address

func (s *ActorSystem) Address() string

func (*ActorSystem) ClusterId

func (s *ActorSystem) ClusterId() string

func (*ActorSystem) Regist

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

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

func (*ActorSystem) RegistCmd

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

func (*ActorSystem) Send

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

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

func (*ActorSystem) SetCluster added in v1.0.1

func (s *ActorSystem) SetCluster(id string)

func (*ActorSystem) Stop

func (s *ActorSystem) Stop()

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_delSession

type Ev_delSession struct {
	Host string
}

type Ev_newActor

type Ev_newActor struct {
	ActorId     string
	Publish     bool
	FromCluster bool
}

type Ev_newSession

type Ev_newSession struct {
	Host string
}

type EventDispatcher added in v1.0.1

type EventDispatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewActorEvent added in v1.0.1

func NewActorEvent(s *ActorSystem) *EventDispatcher

func (*EventDispatcher) CancelAll added in v1.0.1

func (ed *EventDispatcher) CancelAll(actorId string)

取消actor事件

func (*EventDispatcher) CancelEvent added in v1.0.1

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

取消actor事件

func (*EventDispatcher) DispatchEvent added in v1.0.1

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

事件触发

func (*EventDispatcher) RegistEvent added in v1.0.1

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

注册actor事件

type IActor

type IActor interface {
	//core
	GetID() string
	ActorSystem() *ActorSystem
	LogicStop()

	//timer
	AddTimer(interval time.Duration, trigger_times int32, callback jtimer.FuncCallback) int64
	CancelTimer(timerId int64)

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

	// Send 不保证消息发送可靠性,如果需要超时处理用 Request
	Send(targetId string, msg interface{})
	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 IActorHandler

type IActorHandler interface {
	Init()
	Stop() (immediatelyStop bool) // true 立刻停止,false 延迟停止

	HandleEvent(event interface{})                                                       //事件消息
	HandleMessage(sourceId, targetId string, msg interface{})                            //普通消息(只管发送)
	HandleRequest(sourceId, targetId, requestId string, msg interface{}) (respErr error) //请求消息(需要应答)
	// contains filtered or unexported methods
}

actor 处理接口

type ICmd

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

type SystemOption

type SystemOption func(*ActorSystem) 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