Browse Source

removed lazy initializer

pull/14419/head
IrynaMatveieva 10 months ago
parent
commit
66936c48ab
  1. 8
      application/src/main/java/org/thingsboard/server/service/cf/ctx/state/aggregation/RelatedEntitiesAggregationCalculatedFieldState.java
  2. 14
      application/src/main/java/org/thingsboard/server/service/cf/ctx/state/aggregation/single/EntityAggregationCalculatedFieldState.java

8
application/src/main/java/org/thingsboard/server/service/cf/ctx/state/aggregation/RelatedEntitiesAggregationCalculatedFieldState.java

@ -262,9 +262,11 @@ public class RelatedEntitiesAggregationCalculatedFieldState extends BaseCalculat
List<EntityArgument> entitiesArguments = new ArrayList<>(); List<EntityArgument> entitiesArguments = new ArrayList<>();
inputs.forEach((entityId, entityArguments) -> { inputs.forEach((entityId, entityArguments) -> {
EntityInfo entityInfo = entityIdEntityInfos.get(entityId); EntityInfo entityInfo = entityIdEntityInfos.get(entityId);
JsonNode entityArgumentsJson = JacksonUtil.valueToTree(entityArguments.entrySet().stream() if (entityInfo != null) {
.collect(Collectors.toMap(Entry::getKey, e -> e.getValue().jsonValue()))); JsonNode entityArgumentsJson = JacksonUtil.valueToTree(entityArguments.entrySet().stream()
entitiesArguments.add(new EntityArgument(entityInfo, entityArgumentsJson)); .collect(Collectors.toMap(Entry::getKey, e -> e.getValue().jsonValue())));
entitiesArguments.add(new EntityArgument(entityInfo, entityArgumentsJson));
}
}); });
return JacksonUtil.valueToTree(new RelatedEntitiesArgument(ArgumentEntryType.RELATED_ENTITIES, entitiesArguments)); return JacksonUtil.valueToTree(new RelatedEntitiesArgument(ArgumentEntryType.RELATED_ENTITIES, entitiesArguments));
} }

14
application/src/main/java/org/thingsboard/server/service/cf/ctx/state/aggregation/single/EntityAggregationCalculatedFieldState.java

@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import org.apache.commons.lang3.concurrent.LazyInitializer;
import org.thingsboard.common.util.DebugModeUtil; import org.thingsboard.common.util.DebugModeUtil;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.script.api.tbel.TbUtils; import org.thingsboard.script.api.tbel.TbUtils;
@ -103,10 +102,11 @@ public class EntityAggregationCalculatedFieldState extends BaseCalculatedFieldSt
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (DebugModeUtil.isDebugFailuresAvailable(ctx.getCalculatedField())) { if (DebugModeUtil.isDebugFailuresAvailable(ctx.getCalculatedField())) {
LazyInitializer<EntityAggregationDebugArgumentsTracker> lazy = LazyInitializer.<EntityAggregationDebugArgumentsTracker>builder() if (debugTracker == null) {
.setInitializer(() -> new EntityAggregationDebugArgumentsTracker(new HashMap<>())) debugTracker = new EntityAggregationDebugArgumentsTracker(new HashMap<>());
.get(); } else {
debugTracker = lazy.get(); debugTracker.reset();
}
debugTracker.recordUpdatedArgs(updatedArgs, arguments); debugTracker.recordUpdatedArgs(updatedArgs, arguments);
} }
@ -314,6 +314,10 @@ public class EntityAggregationCalculatedFieldState extends BaseCalculatedFieldSt
record EntityAggregationDebugArgumentsTracker(Map<AggIntervalEntry, Map<String, TbelCfArg>> processedIntervals) { record EntityAggregationDebugArgumentsTracker(Map<AggIntervalEntry, Map<String, TbelCfArg>> processedIntervals) {
public void reset() {
processedIntervals.clear();
}
public void addInterval(AggIntervalEntry interval) { public void addInterval(AggIntervalEntry interval) {
processedIntervals.computeIfAbsent(interval, k -> new HashMap<>()); processedIntervals.computeIfAbsent(interval, k -> new HashMap<>());
} }

Loading…
Cancel
Save