package actors import ( "github.com/gogf/gf/util/guid" "sparrow/pkg/actor" "sparrow/pkg/protocol" "sparrow/pkg/server" ) // AppActor 服务级actor type AppActor struct { actor.ContextBasedCreator } func (a *AppActor) CreateActorId() string { panic("implement me") } func (a *AppActor) CreateActor() actor.Actor { panic("implement me") } func (a *AppActor) GetActorRef() actor.Ref { return a.Ctx } func (a *AppActor) Init(ctx actor.Ctx) error { a.Ctx = ctx return nil } func (a *AppActor) Process(msg protocol.ActorMsg) error { switch msg.GetMessageType() { case protocol.APP_INIT_MSG: server.Log.Debugf("收到应用初始化消息") default: server.Log.Debugf("未知的消息类型:%s", msg.GetMessageType()) } return nil } func (a *AppActor) Destroy() error { return nil } func (a *AppActor) OnProcessFailure(err error) *actor.ProcessFailureStrategy { if err != nil { return actor.Stop() } else { return actor.Resume() } } // AppActorCreator app actor creator implements creator interface type AppActorCreator struct { actor.ContextBasedCreator } func NewAppActorCreator(systemCtx *actor.SystemContext) *AppActorCreator { ins := new(AppActorCreator) ins.SystemCtx = systemCtx return ins } func (a *AppActorCreator) CreateActorId() string { return guid.S() } func (a *AppActorCreator) CreateActor() actor.Actor { appC := new(AppActor) appC.SystemCtx = a.SystemCtx return appC }