Skip to content

Commit

Permalink
- Change logger level to debug for value conversion errors in Watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Nov 30, 2021
1 parent 17cc835 commit 152af7e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ subprojects {
apply plugin: 'maven-publish'

group = 'org.iot-dsa'
version = '1.0.0'
version = '1.0.1'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import org.dsa.iot.dslink.node.Writable;
import org.dsa.iot.dslink.node.actions.Action;
import org.dsa.iot.dslink.node.actions.ActionResult;
import org.dsa.iot.dslink.node.value.*;
import org.dsa.iot.dslink.node.value.SubscriptionValue;
import org.dsa.iot.dslink.node.value.Value;
import org.dsa.iot.dslink.node.value.ValuePair;
import org.dsa.iot.dslink.node.value.ValueType;
import org.dsa.iot.dslink.node.value.ValueUtils;
import org.dsa.iot.dslink.util.StringUtils;
import org.dsa.iot.dslink.util.handler.Handler;
import org.dsa.iot.dslink.util.json.JsonArray;
Expand All @@ -32,6 +36,7 @@
* @author Samuel Grenier
*/
public class Watch {

private static final Logger LOGGER = LoggerFactory.getLogger(Watch.class);
public static final String USE_NEW_ENCODING_METHOD_CONFIG_NAME = "useNewEncodingMethod";

Expand All @@ -55,6 +60,12 @@ public class Watch {

// Used for POINT_CHANGE
private Value lastValue;
private WatchUpdate lastWatchUpdate;

public Watch(final WatchGroup group, Node node) {
this.group = group;
this.node = node;
}

public WatchUpdate getLastWatchUpdate() {
Value value = node.getValue();
Expand All @@ -68,13 +79,6 @@ public WatchUpdate getLastWatchUpdate() {
return lastWatchUpdate;
}

private WatchUpdate lastWatchUpdate;

public Watch(final WatchGroup group, Node node) {
this.group = group;
this.node = node;
}

public Node getNode() {
return node;
}
Expand Down Expand Up @@ -108,22 +112,22 @@ public void handleLastWritten(Value value) {
lastWrittenTime = timestampOfValue.getTime();
}

public void setLastWrittenTime(long time) {
lastWrittenTime = time;
}

public long getLastWrittenTime() {
return lastWrittenTime;
}

public void setLastValue(Value value) {
lastValue = value;
public void setLastWrittenTime(long time) {
lastWrittenTime = time;
}

public Value getLastValue() {
return lastValue;
}

public void setLastValue(Value value) {
lastValue = value;
}

public void unsubscribe() {
group.removeFromWatches(this);
removeFromSubscriptionPool();
Expand Down Expand Up @@ -167,7 +171,11 @@ public void handle(ListResponse event) {
Node node = event.getNode();
ValueType valueType = node.getValueType();
Watch.this.node.setValueType(valueType);
Watch.this.node.setValue(node.getValue());
try {
Watch.this.node.setValue(node.getValue());
} catch (Exception x) {
LOGGER.debug(watchedPath, x);
}
}
});
}
Expand Down Expand Up @@ -271,7 +279,17 @@ public synchronized void handle(ValuePair event) {
*/
public void onData(SubscriptionValue sv) {
sv = tryConvert(sv);
realTimeValue.setValue(sv.getValue());
if (sv.getValue().getType() != realTimeValue.getValueType()) {
LOGGER.debug("{} cannot convert {} to {}", sv.getPath(), sv.getValue(),
realTimeValue.getValueType());
return;
}
try {
realTimeValue.setValue(tryConvert(sv).getValue());
} catch (Exception x) {
LOGGER.debug(sv.getPath(), x);
return;
}
if (group.canWriteOnNewData()) {
group.write(this, sv);
//The following is for when switching the logging type of the group from
Expand Down Expand Up @@ -317,16 +335,18 @@ public void notifyHandlers(QueryData data) {
}

/**
* Attempts to convert the value of the argument to the value type of the
* realTimeValue node.
* Attempts to convert the value of the argument to the value type of the realTimeValue node.
*
* @param arg The candidate for conversion.
* @return A new SubscriptionValue if the value in the argument was immutable.
*/
private SubscriptionValue tryConvert(SubscriptionValue arg) {
Value value = arg.getValue();
ValueType toType = realTimeValue.getValueType();
if (value.getType() == toType) {
if (toType == ValueType.DYNAMIC) {
return arg;
}
if (toType == value.getType()) {
return arg;
}
if (value.isImmutable()) {
Expand Down

0 comments on commit 152af7e

Please sign in to comment.