Documentation ¶
Index ¶
- Constants
- Variables
- func FutureAsk[M Message](ctx mixinDeliver, target ActorRef, message Message, timeout ...time.Duration) future.Future[M]
- func GetDefaultPersistenceStorageProvider() persistence.StorageProvider
- func RegisterFutureAskType(handler func(ctx any) *ActorSystem)
- type AbyssProcess
- type Actor
- type ActorBehavior
- type ActorContext
- type ActorDescriptor
- func (d *ActorDescriptor) WithDispatcherProvider(provider DispatcherProvider) *ActorDescriptor
- func (d *ActorDescriptor) WithExpireDuration(duration time.Duration) *ActorDescriptor
- func (d *ActorDescriptor) WithIdleDeadline(deadline time.Duration) *ActorDescriptor
- func (d *ActorDescriptor) WithMailboxProvider(provider MailboxProvider) *ActorDescriptor
- func (d *ActorDescriptor) WithName(name string) *ActorDescriptor
- func (d *ActorDescriptor) WithNamePrefix(prefix string) *ActorDescriptor
- func (d *ActorDescriptor) WithPersistenceEventThreshold(threshold int) *ActorDescriptor
- func (d *ActorDescriptor) WithPersistenceName(name persistence.Name) *ActorDescriptor
- func (d *ActorDescriptor) WithPersistenceStorageProvider(provider persistence.StorageProvider) *ActorDescriptor
- func (d *ActorDescriptor) WithSlowProcessingDuration(duration time.Duration, receivers ...ActorRef) *ActorDescriptor
- func (d *ActorDescriptor) WithSupervisionStrategyProvider(provider supervision.StrategyProvider, loggers ...supervision.Logger) *ActorDescriptor
- type ActorDescriptorConfigurator
- type ActorPerformance
- type ActorProvider
- type ActorRef
- type ActorSystem
- func (sys *ActorSystem) Abyss() ActorRef
- func (sys *ActorSystem) ActorOf(provider ActorProvider, configurator ...ActorDescriptorConfigurator) ActorRef
- func (sys *ActorSystem) ActorOfF(provider FunctionalActorProvider, ...) ActorRef
- func (sys *ActorSystem) Ask(target ActorRef, message Message)
- func (sys *ActorSystem) AwaitForward(target ActorRef, asyncFunc func() Message)
- func (sys *ActorSystem) Broadcast(message Message)
- func (sys *ActorSystem) Context() ActorContext
- func (sys *ActorSystem) FutureAsk(target ActorRef, message Message, timeout ...time.Duration) future.Future[Message]
- func (sys *ActorSystem) Logger() *log.Logger
- func (sys *ActorSystem) Name() string
- func (sys *ActorSystem) PhysicalAddress() prc.PhysicalAddress
- func (sys *ActorSystem) Publish(topic Topic, message Message)
- func (sys *ActorSystem) Shutdown(gracefully bool)
- func (sys *ActorSystem) Signal(handler func(system *ActorSystem, signal os.Signal))
- func (sys *ActorSystem) Tell(target ActorRef, message Message)
- func (sys *ActorSystem) Terminate(target ActorRef, gracefully bool)
- type ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithAbyss(abyss AbyssProcess) *ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithAccidentTrace() *ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithGRPCServerHooks(hooks ...func(server *grpc.Server)) *ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithLoggerProvider(provider log.LoggerProvider) *ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithName(name string) *ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithShared(address prc.PhysicalAddress, codec ...codec.Codec) *ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithShutdownAfterHooks(hooks ...ShutdownAfterHook) *ActorSystemConfiguration
- func (c *ActorSystemConfiguration) WithSubscriptionContactProviders(providers ...SubscriptionContactProvider) *ActorSystemConfiguration
- type ActorSystemConfigurator
- type DispatcherProvider
- type FunctionalActor
- type FunctionalActorDescriptorConfigurator
- type FunctionalActorPerformance
- type FunctionalActorProvider
- type FunctionalActorSystemConfigurator
- type FunctionalDispatcherProvider
- type FunctionalMailboxProvider
- type FunctionalStatefulActorPerformance
- type MailboxProvider
- type Message
- type MessageWrapper
- type OnAbyssMessageEvent
- type OnLaunch
- type OnPersistenceSnapshot
- type OnRestarted
- type OnRestarting
- type OnSlowProcess
- type OnTerminate
- type OnTerminated
- type ShutdownAfterHook
- type Subscription
- type SubscriptionContactEvent
- type SubscriptionContactProvider
- type Topic
Constants ¶
const (
// AbyssTopic 默认的深渊主题,订阅该主题的订阅者将会收到 OnAbyssMessageEvent 事件
AbyssTopic = "vivid_abyss"
)
const (
DefaultFutureAskTimeout = time.Second
)
const (
DefaultPersistenceEventThreshold = 1000
)
Variables ¶
var File_messages_proto protoreflect.FileDescriptor
Functions ¶
func FutureAsk ¶
func FutureAsk[M Message](ctx mixinDeliver, target ActorRef, message Message, timeout ...time.Duration) future.Future[M]
FutureAsk 向目标 Actor 非阻塞地发送可被回复的消息,这个回复是有限期的,返回一个 future.Future 对象,可被用于获取响应消息
- 当 timeout 参数为空时,将会使用默认的超时时间 DefaultFutureAskTimeout
func GetDefaultPersistenceStorageProvider ¶
func GetDefaultPersistenceStorageProvider() persistence.StorageProvider
func RegisterFutureAskType ¶
func RegisterFutureAskType(handler func(ctx any) *ActorSystem)
Types ¶
type AbyssProcess ¶
type AbyssProcess interface { OnInitialize(system *ActorSystem) prc.Process }
type Actor ¶
type Actor interface {
OnReceive(ctx ActorContext)
}
type ActorBehavior ¶
type ActorBehavior = behavior.Behavior[ActorContext]
type ActorContext ¶
type ActorContext interface {
// contains filtered or unexported methods
}
ActorContext 是一个 Actor 完整的上下文,也是对外暴露的可用接口。
type ActorDescriptor ¶
type ActorDescriptor struct {
// contains filtered or unexported fields
}
ActorDescriptor 用于定义 Actor 个性化行为的描述符,它仅在 Actor 创建时使用并释放
func (*ActorDescriptor) WithDispatcherProvider ¶
func (d *ActorDescriptor) WithDispatcherProvider(provider DispatcherProvider) *ActorDescriptor
WithDispatcherProvider 设置调度器提供者
func (*ActorDescriptor) WithExpireDuration ¶
func (d *ActorDescriptor) WithExpireDuration(duration time.Duration) *ActorDescriptor
WithExpireDuration 设置 Actor 过期时间
- 过期是指该 Actor 在到达期限后将会被终止
func (*ActorDescriptor) WithIdleDeadline ¶
func (d *ActorDescriptor) WithIdleDeadline(deadline time.Duration) *ActorDescriptor
WithIdleDeadline 设置 Actor 空闲截止时间
- 空闲截止时间是指 Actor 在空闲时间超过该时间后将会被终止
func (*ActorDescriptor) WithMailboxProvider ¶
func (d *ActorDescriptor) WithMailboxProvider(provider MailboxProvider) *ActorDescriptor
WithMailboxProvider 设置邮箱提供者
func (*ActorDescriptor) WithName ¶
func (d *ActorDescriptor) WithName(name string) *ActorDescriptor
WithName 设置 Actor 名称,名称中禁止包含空格、换行符等特殊字符、以及 '\'、'/'
func (*ActorDescriptor) WithNamePrefix ¶
func (d *ActorDescriptor) WithNamePrefix(prefix string) *ActorDescriptor
WithNamePrefix 设置 Actor 名称前缀,名称中禁止包含空格、换行符等特殊字符、以及 '\'、'/'
- 前缀将会与名称使用 "-" 连接
func (*ActorDescriptor) WithPersistenceEventThreshold ¶
func (d *ActorDescriptor) WithPersistenceEventThreshold(threshold int) *ActorDescriptor
WithPersistenceEventThreshold 设置持久化事件数量阈值
- 当 Actor 的事件数量超过该阈值时,将会触发快照的持久化
默认值: DefaultPersistenceEventThreshold
func (*ActorDescriptor) WithPersistenceName ¶
func (d *ActorDescriptor) WithPersistenceName(name persistence.Name) *ActorDescriptor
WithPersistenceName 设置持久化名称,持久化名称用于标识 Actor 的持久化状态。
默认值为 Actor 的 prc.LogicalAddress
func (*ActorDescriptor) WithPersistenceStorageProvider ¶
func (d *ActorDescriptor) WithPersistenceStorageProvider(provider persistence.StorageProvider) *ActorDescriptor
WithPersistenceStorageProvider 设置持久化存储器提供者
func (*ActorDescriptor) WithSlowProcessingDuration ¶
func (d *ActorDescriptor) WithSlowProcessingDuration(duration time.Duration, receivers ...ActorRef) *ActorDescriptor
WithSlowProcessingDuration 设置慢处理时间
- 当 duration > 0 且消息处理耗时超过该值时,将会打印一条警告日志,并且你可以设置接收人来处理 OnSlowProcess 消息以取代日志行为
func (*ActorDescriptor) WithSupervisionStrategyProvider ¶
func (d *ActorDescriptor) WithSupervisionStrategyProvider(provider supervision.StrategyProvider, loggers ...supervision.Logger) *ActorDescriptor
WithSupervisionStrategyProvider 设置监督策略提供者
type ActorDescriptorConfigurator ¶
type ActorDescriptorConfigurator interface { // Configure 配置 ActorDescriptor Configure(descriptor *ActorDescriptor) }
ActorDescriptorConfigurator 是用于配置 ActorDescriptor 的配置器
type ActorPerformance ¶
type ActorPerformance = behavior.Performance[ActorContext]
type ActorProvider ¶
type ActorProvider interface { // Provide 每次调用都应返回一个新的 Actor 实例,错误的使用可能导致 Actor 状态被污染。 Provide() Actor }
ActorProvider 是一个 Actor 生成器接口,它定义了生成 Actor 实例的方法。
type ActorRef ¶
func NewActorRef ¶
func NewActorRef(physicalAddress prc.PhysicalAddress, logicAddress prc.LogicalAddress) ActorRef
NewActorRef 通过特定的物理地址和逻辑地址,创建一个指向特定 ActorSystem 的 ActorRef
type ActorSystem ¶
type ActorSystem struct {
// contains filtered or unexported fields
}
func NewActorSystem ¶
func NewActorSystem(configurator ...ActorSystemConfigurator) *ActorSystem
func NewActorSystemWithConfiguration ¶
func NewActorSystemWithConfiguration(configuration *ActorSystemConfiguration, configurator ...ActorSystemConfigurator) *ActorSystem
func (*ActorSystem) ActorOf ¶
func (sys *ActorSystem) ActorOf(provider ActorProvider, configurator ...ActorDescriptorConfigurator) ActorRef
ActorOf 生成一个新的 Actor 实例,并以该实例作为其父 Actor。返回生成的 Actor 引用(ActorRef)
- 该函数接收多个 ActorDescriptorConfigurator 参数,用于配置生成的 Actor 实例,当包含多个 ActorDescriptorConfigurator 参数时,它们的配置将会是向前覆盖的。
该函数不是并发安全的,你不应该在多个 goroutine 中同时调用 ActorOf 函数。
func (*ActorSystem) ActorOfF ¶
func (sys *ActorSystem) ActorOfF(provider FunctionalActorProvider, configurator ...FunctionalActorDescriptorConfigurator) ActorRef
ActorOfF 该函数是 ActorOf 的快捷方式,它提供了更为简便的使用方式,但是会额外创建一个切片并拷贝,用于 FunctionalActorDescriptorConfigurator 到 ActorDescriptorConfigurator 的转换。
func (*ActorSystem) Ask ¶
func (sys *ActorSystem) Ask(target ActorRef, message Message)
Ask 向目标 Actor 非阻塞地发送可被回复的消息,这个回复可能是无限期的
func (*ActorSystem) AwaitForward ¶
func (sys *ActorSystem) AwaitForward(target ActorRef, asyncFunc func() Message)
AwaitForward 异步地等待阻塞结束后向目标 Actor 转发消息
func (*ActorSystem) Broadcast ¶
func (sys *ActorSystem) Broadcast(message Message)
Broadcast 向所有子级 Actor 广播消息,广播消息是可以被回复的
- 子级的子级不会收到广播消息
func (*ActorSystem) Context ¶
func (sys *ActorSystem) Context() ActorContext
Context 获取 Actor 系统的根 Actor 上下文
func (*ActorSystem) FutureAsk ¶
func (sys *ActorSystem) FutureAsk(target ActorRef, message Message, timeout ...time.Duration) future.Future[Message]
FutureAsk 向目标 Actor 非阻塞地发送可被回复的消息,这个回复是有限期的,返回一个 future.Future 对象,可被用于获取响应消息
- 当 timeout 参数为空时,将会使用默认的超时时间 DefaultFutureAskTimeout
func (*ActorSystem) Logger ¶
func (sys *ActorSystem) Logger() *log.Logger
Logger 获取 ActorSystem 的日志记录器。
func (*ActorSystem) PhysicalAddress ¶
func (sys *ActorSystem) PhysicalAddress() prc.PhysicalAddress
PhysicalAddress 获取 Actor 系统的物理地址
func (*ActorSystem) Publish ¶
func (sys *ActorSystem) Publish(topic Topic, message Message)
Publish 向所有订阅者发布消息
func (*ActorSystem) Shutdown ¶
func (sys *ActorSystem) Shutdown(gracefully bool)
Shutdown 关闭 Actor 系统。
- 该函数会等待所有 Actor 终止后再关闭 Actor 系统。
func (*ActorSystem) Signal ¶
func (sys *ActorSystem) Signal(handler func(system *ActorSystem, signal os.Signal))
Signal 监听系统信号,当系统接收到指定信号时执行 handler
func (*ActorSystem) Tell ¶
func (sys *ActorSystem) Tell(target ActorRef, message Message)
Tell 向指定的 Actor 引用(ActorRef) 发送消息。
func (*ActorSystem) Terminate ¶
func (sys *ActorSystem) Terminate(target ActorRef, gracefully bool)
Terminate 终止目标 Actor。
- 当 gracefully 参数为 true 时,会将终止消息作为用户级消息进行发送,在该消息之前的用户消息被处理完毕后升级为系统消息终止 Actor。
type ActorSystemConfiguration ¶
type ActorSystemConfiguration struct {
// contains filtered or unexported fields
}
ActorSystemConfiguration 是 ActorSystem 的配置
func NewActorSystemConfiguration ¶
func NewActorSystemConfiguration() *ActorSystemConfiguration
NewActorSystemConfiguration 创建 ActorSystemConfiguration 默认实例
func (*ActorSystemConfiguration) WithAbyss ¶
func (c *ActorSystemConfiguration) WithAbyss(abyss AbyssProcess) *ActorSystemConfiguration
WithAbyss 设置深渊进程,深渊进程将在进程无法寻址到时作为替代进程进行返回。这在其他地方也叫做死信
func (*ActorSystemConfiguration) WithAccidentTrace ¶
func (c *ActorSystemConfiguration) WithAccidentTrace() *ActorSystemConfiguration
WithAccidentTrace 开启事故堆栈追踪
func (*ActorSystemConfiguration) WithGRPCServerHooks ¶
func (c *ActorSystemConfiguration) WithGRPCServerHooks(hooks ...func(server *grpc.Server)) *ActorSystemConfiguration
WithGRPCServerHooks 设置 GRPC 服务器钩子,该方法将在创建 GRPC 服务器后调用
func (*ActorSystemConfiguration) WithLoggerProvider ¶
func (c *ActorSystemConfiguration) WithLoggerProvider(provider log.LoggerProvider) *ActorSystemConfiguration
WithLoggerProvider 设置日志提供者
func (*ActorSystemConfiguration) WithName ¶
func (c *ActorSystemConfiguration) WithName(name string) *ActorSystemConfiguration
WithName 设置 ActorSystem 名称
func (*ActorSystemConfiguration) WithShared ¶
func (c *ActorSystemConfiguration) WithShared(address prc.PhysicalAddress, codec ...codec.Codec) *ActorSystemConfiguration
WithShared 设置是否开启网络共享,开启后 ActorSystem 将允许通过网络与其他 ActorSystem 交互。
- 默认的网络序列化是采用的 ProtoBuffer,如果需要调整,可指定编解码器
func (*ActorSystemConfiguration) WithShutdownAfterHooks ¶
func (c *ActorSystemConfiguration) WithShutdownAfterHooks(hooks ...ShutdownAfterHook) *ActorSystemConfiguration
WithShutdownAfterHooks 设置 ActorSystem 关闭后将调用此回调
func (*ActorSystemConfiguration) WithSubscriptionContactProviders ¶
func (c *ActorSystemConfiguration) WithSubscriptionContactProviders(providers ...SubscriptionContactProvider) *ActorSystemConfiguration
WithSubscriptionContactProviders 设置订阅联系人提供者
type ActorSystemConfigurator ¶
type ActorSystemConfigurator interface { // Configure 配置 ActorSystem Configure(config *ActorSystemConfiguration) }
ActorSystemConfigurator 是用于配置 ActorSystem 的配置器
type DispatcherProvider ¶
type DispatcherProvider interface { // Provide 返回一个可用的 dispatcher.Dispatcher 实例 Provide() dispatcher.Dispatcher }
DispatcherProvider 是一个提供 dispatcher.Dispatcher 实例的接口
func GetDefaultDispatcherProvider ¶
func GetDefaultDispatcherProvider() DispatcherProvider
GetDefaultDispatcherProvider 返回默认的 DispatcherProvider 实例
type FunctionalActor ¶
type FunctionalActor func(ctx ActorContext)
func (FunctionalActor) OnReceive ¶
func (f FunctionalActor) OnReceive(ctx ActorContext)
type FunctionalActorDescriptorConfigurator ¶
type FunctionalActorDescriptorConfigurator func(descriptor *ActorDescriptor)
func (FunctionalActorDescriptorConfigurator) Configure ¶
func (f FunctionalActorDescriptorConfigurator) Configure(descriptor *ActorDescriptor)
Configure 配置 ActorDescriptor
type FunctionalActorPerformance ¶
type FunctionalActorPerformance = behavior.FunctionalPerformance[ActorContext]
type FunctionalActorProvider ¶
type FunctionalActorProvider func() Actor
FunctionalActorProvider 是一个函数类型的 Actor 生成器,它定义了生成 Actor 实例的方法。
func (FunctionalActorProvider) Provide ¶
func (f FunctionalActorProvider) Provide() Actor
Provide 每次调用都应返回一个新的 Actor 实例,错误的使用可能导致 Actor 状态被污染。
type FunctionalActorSystemConfigurator ¶
type FunctionalActorSystemConfigurator func(config *ActorSystemConfiguration)
FunctionalActorSystemConfigurator 是用于配置 ActorSystem 的配置器
func (FunctionalActorSystemConfigurator) Configure ¶
func (f FunctionalActorSystemConfigurator) Configure(config *ActorSystemConfiguration)
Configure 配置 ActorSystem
type FunctionalDispatcherProvider ¶
type FunctionalDispatcherProvider func() dispatcher.Dispatcher
FunctionalDispatcherProvider 是一个函数类型的 DispatcherProvider,它定义了生成 dispatcher.Dispatcher 实例的方法。
func (FunctionalDispatcherProvider) Provide ¶
func (f FunctionalDispatcherProvider) Provide() dispatcher.Dispatcher
Provide 返回一个可用的 dispatcher.Dispatcher 实例
type FunctionalMailboxProvider ¶
type FunctionalMailboxProvider func(dispatcher dispatcher.Dispatcher, recipient mailbox.Recipient) mailbox.Mailbox
FunctionalMailboxProvider 是一个��数类型的 MailboxProvider,它定义了生成 mailbox.Mailbox 实例的方法。
func (FunctionalMailboxProvider) Provide ¶
func (f FunctionalMailboxProvider) Provide(dispatcher dispatcher.Dispatcher, recipient mailbox.Recipient) mailbox.Mailbox
Provide 根据给定的 dispatcher.Dispatcher 和 mailbox.Recipient 返回一个 mailbox.Mailbox
type FunctionalStatefulActorPerformance ¶
type FunctionalStatefulActorPerformance = behavior.FunctionalStatefulPerformance[ActorContext]
type MailboxProvider ¶
type MailboxProvider interface { // Provide 根据给定的 dispatcher.Dispatcher 和 mailbox.Recipient 返回一个 mailbox.Mailbox Provide(dispatcher dispatcher.Dispatcher, recipient mailbox.Recipient) mailbox.Mailbox }
MailboxProvider 是一个提供 mailbox.Mailbox 实例的接口
func GetDefaultMailboxProvider ¶
func GetDefaultMailboxProvider() MailboxProvider
GetDefaultMailboxProvider 返回默认的 MailboxProvider 实例
type MessageWrapper ¶
type OnAbyssMessageEvent ¶
type OnAbyssMessageEvent struct { Sender ActorRef Receiver ActorRef Forward ActorRef Message Message Time time.Time }
OnAbyssMessageEvent 当消息发送到深渊之中时,将会收到该消息。
type OnPersistenceSnapshot ¶
type OnPersistenceSnapshot int8
OnPersistenceSnapshot 当 Actor 的事件数量超过持久化事件数量阈值时,将会触发快照的持久化,收到该消息时应主动调用 SaveSnapshot 函数保存快照。
type OnRestarting ¶
type OnRestarting int8
OnRestarting 在 Actor 由于意外情况被监管者执行重启策略时,将收到该消息,后续还会根据生命周期收到一系列消息,具体如下:
- OnTerminate
- OnTerminated
- OnRestarted
- OnLaunch
type OnSlowProcess ¶
OnSlowProcess 当 Actor 处理消息耗时超过阈值时,将会收到该消息。
type OnTerminate ¶
type OnTerminate struct { Gracefully bool `protobuf:"varint,1,opt,name=gracefully,proto3" json:"gracefully,omitempty"` // contains filtered or unexported fields }
OnTerminate 在 Actor 处理完该消息后,将会被终止,适用于释放 Actor 资源等场景。
func (*OnTerminate) Descriptor
deprecated
func (*OnTerminate) Descriptor() ([]byte, []int)
Deprecated: Use OnTerminate.ProtoReflect.Descriptor instead.
func (*OnTerminate) GetGracefully ¶
func (x *OnTerminate) GetGracefully() bool
func (*OnTerminate) ProtoMessage ¶
func (*OnTerminate) ProtoMessage()
func (*OnTerminate) ProtoReflect ¶
func (x *OnTerminate) ProtoReflect() protoreflect.Message
func (*OnTerminate) Reset ¶
func (x *OnTerminate) Reset()
func (*OnTerminate) String ¶
func (x *OnTerminate) String() string
type OnTerminated ¶
type OnTerminated struct {
TerminatedActor ActorRef
}
OnTerminated 当收到该消息时,说明 TerminatedActor 已经被终止,如果是自身,那么表示自身已被终止。
type ShutdownAfterHook ¶
type ShutdownAfterHook func() // 在 ActorSystem 被关闭后将调用此回调
type Subscription ¶
type Subscription interface {
SubscriptionId() uint64
}
type SubscriptionContactEvent ¶
type SubscriptionContactEvent struct { Address prc.PhysicalAddress Stop bool }
type SubscriptionContactProvider ¶
type SubscriptionContactProvider interface {
ChangeNotify() <-chan *SubscriptionContactEvent
}
SubscriptionContactProvider 订阅联络提供者
Source Files ¶
- abyss.go
- abyss_process.go
- actor.go
- actor_behavior.go
- actor_context.go
- actor_descriptor.go
- actor_descriptor_configurator.go
- actor_internal_descriptor.go
- actor_mixin.go
- actor_process.go
- actor_provider.go
- actor_ref.go
- actor_system.go
- actor_system_configuration.go
- actor_system_configurator.go
- dispatcher_provider.go
- future.go
- guard.go
- mailbox_provider.go
- messages.go
- messages.pb.go
- persistence_storage_provider.go
- subscription.go
- subscription_actor.go
- subscription_contact_provider.go
- topic.go