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