actor_base.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package mhayaActor
  2. import (
  3. cfacade "github.com/mhaya/facade"
  4. )
  5. type Base struct {
  6. Actor
  7. }
  8. func (p *Base) load(a Actor) {
  9. p.Actor = a
  10. }
  11. func (p *Base) AliasID() string {
  12. return ""
  13. }
  14. // OnInit Actor初始化前触发该函数
  15. func (*Base) OnInit() {
  16. }
  17. // OnStop Actor停止前触发该函数
  18. func (*Base) OnStop() {
  19. }
  20. // OnLocalReceived Actor收到Local消息时触发该函数
  21. func (*Base) OnLocalReceived(_ *cfacade.Message) (next bool, invoke bool) {
  22. next = true
  23. invoke = false
  24. return
  25. }
  26. // OnRemoteReceived Actor收到Remote消息时触发该函数
  27. func (*Base) OnRemoteReceived(_ *cfacade.Message) (next bool, invoke bool) {
  28. next = true
  29. invoke = false
  30. return
  31. }
  32. // OnFindChild 寻找子Actor时触发该函数.开发者可以自定义创建子Actor
  33. func (*Base) OnFindChild(_ *cfacade.Message) (cfacade.IActor, bool) {
  34. return nil, false
  35. }
  36. func (p *Base) NewPath(nodeID, actorID interface{}) string {
  37. return cfacade.NewPath(nodeID, actorID)
  38. }
  39. func (p *Base) NewNodePath(actorID interface{}) string {
  40. return cfacade.NewPath(p.path.NodeID, actorID)
  41. }
  42. func (p *Base) NewChildPath(actorID, childID interface{}) string {
  43. return cfacade.NewChildPath(p.path.NodeID, actorID, childID)
  44. }
  45. func (p *Base) NewMyChildPath(childID interface{}) string {
  46. return cfacade.NewChildPath(p.path.NodeID, p.path.ActorID, childID)
  47. }