Added usage of msg count in the generator node
This commit is contained in:
parent
75702b6474
commit
a1aea81366
@ -54,6 +54,7 @@ public class TbMsgGeneratorNode implements TbNode {
|
||||
private ScriptEngine jsEngine;
|
||||
private long delay;
|
||||
private long lastScheduledTs;
|
||||
private int currentMsgCount;
|
||||
private EntityId originatorId;
|
||||
private UUID nextTickId;
|
||||
private TbMsg prevMsg;
|
||||
@ -63,6 +64,7 @@ public class TbMsgGeneratorNode implements TbNode {
|
||||
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
|
||||
this.config = TbNodeUtils.convert(configuration, TbMsgGeneratorNodeConfiguration.class);
|
||||
this.delay = TimeUnit.SECONDS.toMillis(config.getPeriodInSeconds());
|
||||
this.currentMsgCount = 0;
|
||||
if (!StringUtils.isEmpty(config.getOriginatorId())) {
|
||||
originatorId = EntityIdFactory.getByTypeAndUuid(config.getOriginatorType(), config.getOriginatorId());
|
||||
} else {
|
||||
@ -94,9 +96,10 @@ public class TbMsgGeneratorNode implements TbNode {
|
||||
if (initialized && msg.getType().equals(TB_MSG_GENERATOR_NODE_MSG) && msg.getId().equals(nextTickId)) {
|
||||
withCallback(generate(ctx),
|
||||
m -> {
|
||||
if (initialized) {
|
||||
if (initialized && (config.getMsgCount() == TbMsgGeneratorNodeConfiguration.UNLIMITED_MSG_COUNT || currentMsgCount < config.getMsgCount())) {
|
||||
ctx.tellNext(m, SUCCESS);
|
||||
scheduleTickMsg(ctx);
|
||||
currentMsgCount++;
|
||||
}
|
||||
},
|
||||
t -> {
|
||||
|
||||
@ -19,11 +19,11 @@ import lombok.Data;
|
||||
import org.thingsboard.rule.engine.api.NodeConfiguration;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class TbMsgGeneratorNodeConfiguration implements NodeConfiguration<TbMsgGeneratorNodeConfiguration> {
|
||||
|
||||
public static final int UNLIMITED_MSG_COUNT = 0;
|
||||
|
||||
private int msgCount;
|
||||
private int periodInSeconds;
|
||||
private String originatorId;
|
||||
@ -33,7 +33,7 @@ public class TbMsgGeneratorNodeConfiguration implements NodeConfiguration<TbMsgG
|
||||
@Override
|
||||
public TbMsgGeneratorNodeConfiguration defaultConfiguration() {
|
||||
TbMsgGeneratorNodeConfiguration configuration = new TbMsgGeneratorNodeConfiguration();
|
||||
configuration.setMsgCount(0);
|
||||
configuration.setMsgCount(UNLIMITED_MSG_COUNT);
|
||||
configuration.setPeriodInSeconds(1);
|
||||
configuration.setJsScript("var msg = { temp: 42, humidity: 77 };\n" +
|
||||
"var metadata = { data: 40 };\n" +
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user