msg.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package ruleEngine
  2. import (
  3. "sparrow/pkg/entities"
  4. "sparrow/pkg/protocol"
  5. )
  6. // RuleChainToRuleNodeMsg 规则链到规则节点的消息定义
  7. type RuleChainToRuleNodeMsg struct {
  8. Message *protocol.Message
  9. Ctx Context
  10. FromRelationType string
  11. }
  12. func (r *RuleChainToRuleNodeMsg) GetMessageType() protocol.MsgType {
  13. return protocol.RULE_CHAIN_TO_RULE_MSG
  14. }
  15. // RuleChainToRuleChainMsg 规则链到另一个规则链的消息
  16. type RuleChainToRuleChainMsg struct {
  17. TargetId string
  18. SourceId string
  19. FromRelationType string
  20. Message *protocol.Message
  21. }
  22. func (t *RuleChainToRuleChainMsg) GetMessageType() protocol.MsgType {
  23. return protocol.RULE_CHAIN_TO_RULE_CHAIN_MSG
  24. }
  25. // TransportToDeviceActorMsg 传输层到设备actor的消息定义
  26. type TransportToDeviceActorMsg struct {
  27. Message *protocol.Message
  28. }
  29. func (t *TransportToDeviceActorMsg) GetMessageType() protocol.MsgType {
  30. return protocol.TRANSPORT_TO_DEVICE_ACTOR_MSG
  31. }
  32. // QueueToRuleEngineMsg 消息队列到规则引擎的消息定义
  33. type QueueToRuleEngineMsg struct {
  34. TenantId string
  35. Message *protocol.Message
  36. RelationTypes []string
  37. FailureMessage error
  38. }
  39. func (q *QueueToRuleEngineMsg) GetMessageType() protocol.MsgType {
  40. return protocol.QUEUE_TO_RULE_ENGINE_MSG
  41. }
  42. type RuleNodeToRuleChanTellNextMsg struct {
  43. RuleNodeId string
  44. RelationTypes protocol.RelationTypes
  45. Message *protocol.Message
  46. FailureMessage error
  47. }
  48. func (r *RuleNodeToRuleChanTellNextMsg) GetMessageType() protocol.MsgType {
  49. return protocol.RULE_TO_RULE_CHAIN_TELL_NEXT_MSG
  50. }
  51. type RuleToSelfMsg struct {
  52. Message *protocol.Message
  53. }
  54. func (r *RuleToSelfMsg) GetMessageType() protocol.MsgType {
  55. return protocol.RULE_TO_SELF_MSG
  56. }
  57. type RuleToSelfErrorMsg struct {
  58. Message *protocol.Message
  59. Err error
  60. }
  61. func (r *RuleToSelfErrorMsg) GetMessageType() protocol.MsgType {
  62. return protocol.RULE_TO_SELF_ERROR_MSG
  63. }
  64. // AppInitMsg app 初始化消息
  65. type AppInitMsg struct {
  66. }
  67. func (a *AppInitMsg) GetMessageType() protocol.MsgType {
  68. return protocol.APP_INIT_MSG
  69. }
  70. type ComponentLifecycleMsg struct {
  71. TenantId string
  72. EntityId entities.EntityId
  73. EventType ComponentLifecycleEvent
  74. }
  75. func (c *ComponentLifecycleMsg) GetRuleChainId() string {
  76. if c.EntityId.GetEntityType() == entities.RULE_CHAIN {
  77. return c.EntityId.GetId()
  78. } else {
  79. return ""
  80. }
  81. }
  82. func (c *ComponentLifecycleMsg) GetMessageType() protocol.MsgType {
  83. return protocol.COMPONENT_LIFE_CYCLE_MSG
  84. }
  85. // ComponentLifecycleEvent 组件节点生命周期
  86. type ComponentLifecycleEvent string
  87. const (
  88. CREATED ComponentLifecycleEvent = "CREATED"
  89. STARTED ComponentLifecycleEvent = "STARTED"
  90. ACTIVATED ComponentLifecycleEvent = "ACTIVATED"
  91. UPDATED ComponentLifecycleEvent = "UPDATED"
  92. STOPPED ComponentLifecycleEvent = "STOPPED"
  93. DELETED ComponentLifecycleEvent = "DELETED"
  94. )
  95. // ComponentLifecycleState 生命周期状态
  96. type ComponentLifecycleState int
  97. const (
  98. ACTIVE ComponentLifecycleState = iota
  99. SUSPENDED
  100. )