actor

package
v0.0.0-...-b2a5a1f Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Call      = 1
	AsyncCall = 2
)
View Source
const (
	BucketNum = 64
)

Variables

View Source
var (
	ErrCallTimeout = errors.New("err_call_timeout")
)
View Source
var File_core_actor_actor_proto protoreflect.FileDescriptor

Functions

func AcquireTimer

func AcquireTimer(d time.Duration) *time.Timer

func ReleaseTimer

func ReleaseTimer(t *time.Timer)

Types

type ActorProcess

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

func (*ActorProcess) Call

func (ap *ActorProcess) Call(ctx context.Context, _ *PID, msg any) (any, error)

func (*ActorProcess) Cast

func (ap *ActorProcess) Cast(_ *PID, msg any)

func (*ActorProcess) CastSystem

func (ap *ActorProcess) CastSystem(_ *PID, msg any)

func (*ActorProcess) GracefulStop

func (ap *ActorProcess) GracefulStop()

GracefulStop 模式, actor在消耗掉收到sign之前的所有消息之后在安全的Terminate

func (*ActorProcess) Stop

func (ap *ActorProcess) Stop()

Stop 模式会抛弃掉当前信箱内的所有消息并安全的Terminate

type Config

type Config struct {
}

type Context

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

func (*Context) GracefulStop

func (ac *Context) GracefulStop(pid *PID)

GracefulStop 模式, actor在消耗掉收到sign之前的所有消息之后在安全的Terminate

func (*Context) InvokeMsg

func (ac *Context) InvokeMsg(msg any)

func (*Context) InvokeSysMsg

func (ac *Context) InvokeSysMsg(msg any)

func (*Context) Stop

func (ac *Context) Stop(pid *PID)

Stop 模式会抛弃掉当前信箱内的所有消息并安全的Terminate

type Engine

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

func GEngine

func GEngine() *Engine

func NewEngine

func NewEngine(conf *Config) *Engine

func (*Engine) GetNodeId

func (e *Engine) GetNodeId() string

func (*Engine) LocalAddress

func (e *Engine) LocalAddress() string

func (*Engine) RegRemoteHandler

func (e *Engine) RegRemoteHandler(h func(*PID) (IProcess, bool))

func (*Engine) Register

func (e *Engine) Register() *Register

type IActorBehavior

type IActorBehavior interface {
	HandleCall(ctx any) (any, error)
}

type IProcess

type IProcess interface {
	Cast(pid *PID, msg any)
	CastSystem(pid *PID, msg any)
	Call(ctx context.Context, pid *PID, msg any) (any, error)
	Stop()
	GracefulStop()
}

IProcess 每个 Actor 都有一个与之关联的 IProcess 实例, IProcess 负责将消息投递给 Actor 以及 Actor 生命周期管理 IProcess 提供了一个透明的机制来发送消息,使得Local和Remote通信对于 Actor 来说是透明的 业务可以自定义 IProcess 来实现不同的业务场景

func FindProcess

func FindProcess(pid *PID) (IProcess, bool)

type PID

type PID struct {
	Address   string `protobuf:"bytes,1,opt,name=Address,proto3" json:"Address,omitempty"`
	NodeId    string `protobuf:"bytes,2,opt,name=NodeId,proto3" json:"NodeId,omitempty"`
	Id        string `protobuf:"bytes,3,opt,name=Id,proto3" json:"Id,omitempty"`
	RequestId uint32 `protobuf:"varint,4,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`
	// contains filtered or unexported fields
}

func NewPID

func NewPID(address, id string) *PID

NewPID returns a new instance of the PID struct. Pid ( Process Id ) 消息投递的入口, 一个可序列化的标识符,作为消息投递的入口,将消息发送到参与者的邮箱; Pid 可以低消耗的序列化供远程传输

func (*PID) Descriptor deprecated

func (*PID) Descriptor() ([]byte, []int)

Deprecated: Use PID.ProtoReflect.Descriptor instead.

func (*PID) Equal

func (pid *PID) Equal(other *PID) bool

func (*PID) GetAddress

func (x *PID) GetAddress() string

func (*PID) GetId

func (x *PID) GetId() string

func (*PID) GetNodeId

func (x *PID) GetNodeId() string

func (*PID) GetRequestId

func (x *PID) GetRequestId() uint32

func (*PID) IsLocal

func (pid *PID) IsLocal() bool

func (*PID) ProtoMessage

func (*PID) ProtoMessage()

func (*PID) ProtoReflect

func (x *PID) ProtoReflect() protoreflect.Message

func (*PID) Reset

func (x *PID) Reset()

func (*PID) SendMessage

func (pid *PID) SendMessage(message interface{})

func (*PID) String

func (x *PID) String() string

type Register

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

func NewRegister

func NewRegister(bucketNum int) *Register

func (*Register) Del

func (r *Register) Del(pid *PID)

func (*Register) Get

func (r *Register) Get(pid *PID) (IProcess, bool)

func (*Register) Id

func (r *Register) Id() string

func (*Register) Set

func (r *Register) Set(uuid string, p IProcess) (*PID, bool)

type Request

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

func GetRequest

func GetRequest() *Request

func (*Request) Done

func (req *Request) Done() <-chan *Response

func (*Request) Response

func (req *Request) Response(msg any, err error)

func (*Request) Return

func (req *Request) Return()

type Response

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

type Stop

type Stop struct{}

User auto receive messages

type Stopped

type Stopped struct{}

User auto receive messages

type Stopping

type Stopping struct{}

User auto receive messages

type SystemGracefulStop

type SystemGracefulStop struct{}

System messages

type SystemRestart

type SystemRestart struct{}

System messages

type SystemStarted

type SystemStarted struct{}

System messages

type SystemStop

type SystemStop struct{}

System messages

Jump to

Keyboard shortcuts

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