actor.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package mhayaFacade
  2. import (
  3. "time"
  4. creflect "github.com/mhaya/extend/reflect"
  5. )
  6. type (
  7. IActorSystem interface {
  8. GetIActor(id string) (IActor, bool)
  9. CreateActor(id string, handler IActorHandler) (IActor, error)
  10. PostRemote(m *Message) bool
  11. PostLocal(m *Message) bool
  12. PostEvent(data IEventData)
  13. Call(source, target, funcName string, arg interface{}) int32
  14. CallWait(source, target, funcName string, arg interface{}, reply interface{}) int32
  15. SetLocalInvoke(invoke InvokeFunc)
  16. SetRemoteInvoke(invoke InvokeFunc)
  17. SetCallTimeout(d time.Duration)
  18. SetArrivalTimeout(t int64)
  19. SetExecutionTimeout(t int64)
  20. }
  21. InvokeFunc func(app IApplication, fi *creflect.FuncInfo, m *Message)
  22. IActor interface {
  23. App() IApplication
  24. ActorID() string
  25. Path() *ActorPath
  26. Call(targetPath, funcName string, arg interface{}) int32
  27. CallWait(targetPath, funcName string, arg interface{}, reply interface{}) int32
  28. PostRemote(m *Message)
  29. PostLocal(m *Message)
  30. LastAt() int64
  31. Exit()
  32. }
  33. IActorHandler interface {
  34. AliasID() string // actorId
  35. OnInit() // 当Actor启动前触发该函数
  36. OnStop() // 当Actor停止前触发该函数
  37. OnLocalReceived(m *Message) (bool, bool) // 当Actor接收local消息时触发该函数
  38. OnRemoteReceived(m *Message) (bool, bool) // 当Actor接收remote消息时执行的函数
  39. OnFindChild(m *Message) (IActor, bool) // 当actor查找子Actor时触发该函数
  40. }
  41. IActorChild interface {
  42. Create(id string, handler IActorHandler) (IActor, error) // 创建子Actor
  43. Get(id string) (IActor, bool) // 获取子Actor
  44. Remove(id string) // 称除子Actor
  45. Each(fn func(i IActor)) // 遍历所有子Actor
  46. }
  47. )
  48. type (
  49. IEventData interface {
  50. Name() string // 事件名
  51. UniqueId() string // 唯一id
  52. }
  53. )