actor

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASF_NULL = iota
	ASF_RUN  = iota
	ASF_STOP = iota //已经关闭
)
View Source
const (
	DESDORY_EVENT = iota
)

Variables

This section is empty.

Functions

func AssignActorId

func AssignActorId() int64

func GetRpcMethodMap

func GetRpcMethodMap(rType reflect.Type, tagName string) map[string]string

Types

type ACTOR_TYPE

type ACTOR_TYPE uint32
const (
	ACTOR_TYPE_SINGLETON ACTOR_TYPE = iota //单列
	ACTOR_TYPE_VIRTUAL   ACTOR_TYPE = iota //玩家 必须初始一个全局的actor 作为类型判断
	ACTOR_TYPE_POOL      ACTOR_TYPE = iota //固定数量actor池
	ACTOR_TYPE_STUB      ACTOR_TYPE = iota //stub
)

type Actor

type Actor struct {
	ActorBase

	CallMap map[string]*CallFunc
	// contains filtered or unexported fields
}

******************************************************** actor 核心actor模式 ********************************************************

func (*Actor) Acotr

func (a *Actor) Acotr() *Actor

func (*Actor) FindCall

func (this *Actor) FindCall(funcName string) *CallFunc

func (*Actor) GetActorType

func (a *Actor) GetActorType() ACTOR_TYPE

func (*Actor) GetId

func (a *Actor) GetId() int64

func (*Actor) GetName

func (a *Actor) GetName() string

func (*Actor) GetRpcHead

func (a *Actor) GetRpcHead(ctx context.Context) rpc.RpcHead

func (*Actor) GetState

func (a *Actor) GetState() int32

func (*Actor) HasRpc

func (a *Actor) HasRpc(funcName string) bool

func (*Actor) Init

func (a *Actor) Init()

func (*Actor) PacketFunc2

func (this *Actor) PacketFunc2(packet rpc.Packet) bool

func (*Actor) RegisterCall

func (this *Actor) RegisterCall(funcName string, call interface{})

func (*Actor) RegisterTimer

func (a *Actor) RegisterTimer(duration time.Duration, fun func(), opts ...timer.OpOption)

func (*Actor) Send

func (a *Actor) Send(head rpc.RpcHead, packet rpc.Packet)

func (*Actor) Send2

func (this *Actor) Send2(head rpc.RpcHead, buff []byte)

func (*Actor) SendMsg

func (a *Actor) SendMsg(head rpc.RpcHead, funcName string, params ...interface{})

func (*Actor) SetId

func (a *Actor) SetId(id int64)

func (*Actor) Start

func (a *Actor) Start()

func (*Actor) Stop

func (a *Actor) Stop()

func (*Actor) Trace

func (a *Actor) Trace(funcName string)

func (*Actor) UpdateTimer

func (a *Actor) UpdateTimer(ctx context.Context, ptr uintptr)

type ActorBase

type ActorBase struct {
	Self IActor //when parent interface class call interface, it call parent not child  use for virtual
	// contains filtered or unexported fields
}

******************************************************** actor 核心actor模式 ********************************************************

func (*ActorBase) IsActorType

func (a *ActorBase) IsActorType(actorType ACTOR_TYPE) bool

type ActorMgr

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

一些全局的actor,不可删除的,不用锁考虑性能 不是全局的actor,请使用actor pool

var (
	MGR *ActorMgr
)

func (*ActorMgr) Init

func (a *ActorMgr) Init()

func (*ActorMgr) PacketFunc

func (a *ActorMgr) PacketFunc(packet rpc.Packet) bool

func (*ActorMgr) RegisterActor

func (a *ActorMgr) RegisterActor(ac IActor, params ...OpOption)

func (*ActorMgr) SendActor

func (a *ActorMgr) SendActor(funcName string, head rpc.RpcHead, packet rpc.Packet) bool

func (*ActorMgr) SendMsg

func (a *ActorMgr) SendMsg(head rpc.RpcHead, funcName string, params ...interface{})

func (*ActorMgr) Start

func (a *ActorMgr) Start()

type ActorPool

type ActorPool struct {
	MGR IActor
	// contains filtered or unexported fields
}

******************************************************** actorpool 管理,不能动态分配 ********************************************************

func (*ActorPool) GetPoolSize

func (a *ActorPool) GetPoolSize() int

func (*ActorPool) InitPool

func (a *ActorPool) InitPool(pPool IActorPool, rType reflect.Type, num int)

func (*ActorPool) SendAcotr

func (a *ActorPool) SendAcotr(head rpc.RpcHead, packet rpc.Packet) bool

type CallFunc

type CallFunc struct {
	Func       interface{}
	FuncType   reflect.Type
	FuncVal    reflect.Value
	FuncParams string
}

******************************************************** actor 核心actor模式 ********************************************************

type CallIO

type CallIO struct {
	rpc.RpcHead
	*rpc.RpcPacket
	Buff []byte
}

******************************************************** actor 核心actor模式 ********************************************************

type IActor

type IActor interface {
	Init()
	Stop()
	Start()
	SendMsg(head rpc.RpcHead, funcName string, params ...interface{})
	Send(head rpc.RpcHead, packet rpc.Packet)
	RegisterTimer(duration time.Duration, fun func(), opts ...timer.OpOption) //注册定时器,时间为纳秒 1000 * 1000 * 1000
	GetId() int64
	GetState() int32
	GetRpcHead(ctx context.Context) rpc.RpcHead //rpc is safe
	GetName() string
	GetActorType() ACTOR_TYPE
	HasRpc(string) bool
	Acotr() *Actor
	// contains filtered or unexported methods
}

******************************************************** actor 核心actor模式 ********************************************************

type IActorMgr

type IActorMgr interface {
	Init()
	RegisterActor(ac IActor, params ...OpOption) //注册回调
	PacketFunc(rpc.Packet) bool                  //回调函数
	SendMsg(rpc.RpcHead, string, ...interface{})
}

一些全局的actor,不可删除的,不用锁考虑性能 不是全局的actor,请使用actor pool

type IActorPool

type IActorPool interface {
	SendAcotr(head rpc.RpcHead, packet rpc.Packet) bool //ACTOR_TYPE_VIRTUAL,ACTOR_TYPE_POOL特殊判断
}

******************************************************** actor 核心actor模式 ********************************************************

type ICluster

type ICluster interface {
	BindPacketFunc(packetFunc network.PacketFunc)
}

一些全局的actor,不可删除的,不用锁考虑性能 不是全局的actor,请使用actor pool

type IVirtualActor

type IVirtualActor interface {
	GetActor(Id int64) IActor //获取actor
	AddActor(ac IActor)       //添加actor
	DelActor(Id int64)        //删除actor
	GetActorNum() int
	GetMgr() IActor
}

******************************************************** actorpool 管理,这里的actor可以动态添加 ********************************************************

type Op

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

一些全局的actor,不可删除的,不用锁考虑性能 不是全局的actor,请使用actor pool

func (*Op) IsActorType

func (op *Op) IsActorType(actorType ACTOR_TYPE) bool

type OpOption

type OpOption func(*Op)

一些全局的actor,不可删除的,不用锁考虑性能 不是全局的actor,请使用actor pool

func WithType

func WithType(actor_type ACTOR_TYPE) OpOption

type VirtualActor

type VirtualActor struct {
	MGR IActor
	// contains filtered or unexported fields
}

******************************************************** actorpool 管理,这里的actor可以动态添加 ********************************************************

func (*VirtualActor) AddActor

func (a *VirtualActor) AddActor(ac IActor)

func (*VirtualActor) DelActor

func (a *VirtualActor) DelActor(Id int64)

func (*VirtualActor) GeActorrNum

func (a *VirtualActor) GeActorrNum() int

func (*VirtualActor) GetActor

func (a *VirtualActor) GetActor(Id int64) IActor

func (*VirtualActor) GetMgr

func (a *VirtualActor) GetMgr() IActor

func (*VirtualActor) InitActor

func (a *VirtualActor) InitActor(pPool IActorPool, rType reflect.Type)

func (*VirtualActor) SendAcotr

func (a *VirtualActor) SendAcotr(head rpc.RpcHead, packet rpc.Packet) bool

Jump to

Keyboard shortcuts

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