improvements

This commit is contained in:
YevhenBondarenko 2024-09-11 11:26:04 +02:00
parent f64ec5ca56
commit dfb633b8e8
2 changed files with 9 additions and 10 deletions

View File

@ -67,10 +67,7 @@ public class GatewayLatencyService {
}
public void onDeviceDelete(DeviceId deviceId) {
var state = states.remove(deviceId);
if (state != null) {
state.clear();
}
states.remove(deviceId);
}
public void onDeviceDisconnect(DeviceId deviceId) {
@ -100,7 +97,6 @@ public class GatewayLatencyService {
return;
}
var result = state.getLatencyStateResult();
state.clear();
var kvProto = TransportProtos.KeyValueProto.newBuilder()
.setKey("latencyCheck")
.setType(TransportProtos.KeyValueType.JSON_V)

View File

@ -54,13 +54,16 @@ public class GatewayLatencyState {
}
}
public void clear() {
connectors.clear();
}
public Map<String, ConnectorLatencyResult> getLatencyStateResult() {
Map<String, ConnectorLatencyResult> result = new HashMap<>();
updateLock.lock();
try {
connectors.forEach((name, state) -> result.put(name, state.getResult()));
connectors.clear();
} finally {
updateLock.unlock();
}
return result;
}