ProjectEvent.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package jnpf.module;
  2. import com.github.yitter.idgen.YitIdHelper;
  3. import jnpf.consts.ProjectEventConst;
  4. import lombok.Data;
  5. import lombok.experimental.Accessors;
  6. import java.util.Optional;
  7. /**
  8. * 项目事件基础类
  9. */
  10. @Data
  11. @Accessors(chain = true)
  12. public class ProjectEvent{
  13. /**
  14. * 数据
  15. */
  16. private Object source;
  17. /**
  18. * 消息ID
  19. */
  20. private Long eventId;
  21. /**
  22. * 主题
  23. */
  24. private String toptic;
  25. /**
  26. * 频道
  27. */
  28. private String channel;
  29. /**
  30. * 是否异步
  31. */
  32. private boolean async;
  33. /**
  34. * 1:集群, 2:广播, 3:本地
  35. * @see jnpf.consts.ProjectEventConst#EVENT_PUBLISH_MODEL_CLUSTERING
  36. * @see jnpf.consts.ProjectEventConst#EVENT_PUBLISH_MODEL_BROADCASTING
  37. * @see jnpf.consts.ProjectEventConst#EVENT_PUBLISH_MODEL_LOCAL
  38. */
  39. private int messageModel;
  40. /**
  41. * 是否事务提交后才发送
  42. */
  43. private boolean afterCommitTransaction;
  44. /**
  45. * 用户TOKEN
  46. */
  47. private String token;
  48. /**
  49. * 租户编码
  50. */
  51. private String tenantId;
  52. public ProjectEvent(){
  53. }
  54. public ProjectEvent(String topic, String channel, Object source) {
  55. this(null, topic, channel, source, null, true, false);
  56. }
  57. public ProjectEvent(Long eventId, String topic, String channel, Object source, Integer messageModel, boolean async, boolean afterCommitTransaction) {
  58. this.source = source;
  59. this.eventId = Optional.ofNullable(eventId).orElseGet(YitIdHelper::nextId);
  60. this.toptic = Optional.ofNullable(topic).orElse(ProjectEventConst.DEFAULT_TOPIC_NAME);
  61. this.messageModel = Optional.ofNullable(messageModel).orElse(ProjectEventConst.EVENT_PUBLISH_MODEL_CLUSTERING);
  62. this.channel = channel;
  63. this.async = async;
  64. this.afterCommitTransaction = afterCommitTransaction;
  65. }
  66. }