Commit a1aea81366ceb39ad4b32265d4b099ece0e07e55

Authored by VoBa
Committed by Igor Kulikov
1 parent 75702b64

Added usage of msg count in the generator node

... ... @@ -54,6 +54,7 @@ public class TbMsgGeneratorNode implements TbNode {
54 54 private ScriptEngine jsEngine;
55 55 private long delay;
56 56 private long lastScheduledTs;
  57 + private int currentMsgCount;
57 58 private EntityId originatorId;
58 59 private UUID nextTickId;
59 60 private TbMsg prevMsg;
... ... @@ -63,6 +64,7 @@ public class TbMsgGeneratorNode implements TbNode {
63 64 public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
64 65 this.config = TbNodeUtils.convert(configuration, TbMsgGeneratorNodeConfiguration.class);
65 66 this.delay = TimeUnit.SECONDS.toMillis(config.getPeriodInSeconds());
  67 + this.currentMsgCount = 0;
66 68 if (!StringUtils.isEmpty(config.getOriginatorId())) {
67 69 originatorId = EntityIdFactory.getByTypeAndUuid(config.getOriginatorType(), config.getOriginatorId());
68 70 } else {
... ... @@ -94,9 +96,10 @@ public class TbMsgGeneratorNode implements TbNode {
94 96 if (initialized && msg.getType().equals(TB_MSG_GENERATOR_NODE_MSG) && msg.getId().equals(nextTickId)) {
95 97 withCallback(generate(ctx),
96 98 m -> {
97   - if (initialized) {
  99 + if (initialized && (config.getMsgCount() == TbMsgGeneratorNodeConfiguration.UNLIMITED_MSG_COUNT || currentMsgCount < config.getMsgCount())) {
98 100 ctx.tellNext(m, SUCCESS);
99 101 scheduleTickMsg(ctx);
  102 + currentMsgCount++;
100 103 }
101 104 },
102 105 t -> {
... ...
... ... @@ -19,11 +19,11 @@ import lombok.Data;
19 19 import org.thingsboard.rule.engine.api.NodeConfiguration;
20 20 import org.thingsboard.server.common.data.EntityType;
21 21
22   -import java.util.Map;
23   -
24 22 @Data
25 23 public class TbMsgGeneratorNodeConfiguration implements NodeConfiguration<TbMsgGeneratorNodeConfiguration> {
26 24
  25 + public static final int UNLIMITED_MSG_COUNT = 0;
  26 +
27 27 private int msgCount;
28 28 private int periodInSeconds;
29 29 private String originatorId;
... ... @@ -33,7 +33,7 @@ public class TbMsgGeneratorNodeConfiguration implements NodeConfiguration<TbMsgG
33 33 @Override
34 34 public TbMsgGeneratorNodeConfiguration defaultConfiguration() {
35 35 TbMsgGeneratorNodeConfiguration configuration = new TbMsgGeneratorNodeConfiguration();
36   - configuration.setMsgCount(0);
  36 + configuration.setMsgCount(UNLIMITED_MSG_COUNT);
37 37 configuration.setPeriodInSeconds(1);
38 38 configuration.setJsScript("var msg = { temp: 42, humidity: 77 };\n" +
39 39 "var metadata = { data: 40 };\n" +
... ...