Commit 5fddab8528a09961658549e0c3a0f20aac606e3b

Authored by nickAS21
Committed by Andrew Shvayka
1 parent 8022cfb1

Lwm2m: back: fix review

@@ -236,7 +236,9 @@ public class LwM2MTransportRequest { @@ -236,7 +236,9 @@ public class LwM2MTransportRequest {
236 private void sendRequest(LeshanServer lwServer, Registration registration, DownlinkRequest request, long timeoutInMs) { 236 private void sendRequest(LeshanServer lwServer, Registration registration, DownlinkRequest request, long timeoutInMs) {
237 LwM2MClient lwM2MClient = this.service.lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null); 237 LwM2MClient lwM2MClient = this.service.lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
238 lwServer.send(registration, request, timeoutInMs, (ResponseCallback<?>) response -> { 238 lwServer.send(registration, request, timeoutInMs, (ResponseCallback<?>) response -> {
239 - if (!lwM2MClient.isInit()) lwM2MClient.initValue(this.service, request.getPath().toString()); 239 + if (!lwM2MClient.isInit()) {
  240 + lwM2MClient.initValue(this.service, request.getPath().toString());
  241 + }
240 if (isSuccess(((Response) response.getCoapResponse()).getCode())) { 242 if (isSuccess(((Response) response.getCoapResponse()).getCode())) {
241 this.handleResponse(registration, request.getPath().toString(), response, request); 243 this.handleResponse(registration, request.getPath().toString(), response, request);
242 if (request instanceof WriteRequest && ((WriteRequest) request).isReplaceRequest()) { 244 if (request instanceof WriteRequest && ((WriteRequest) request).isReplaceRequest()) {
@@ -254,7 +256,9 @@ public class LwM2MTransportRequest { @@ -254,7 +256,9 @@ public class LwM2MTransportRequest {
254 log.error("[{}] - [{}] [{}] error SendRequest", ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString()); 256 log.error("[{}] - [{}] [{}] error SendRequest", ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString());
255 } 257 }
256 }, e -> { 258 }, e -> {
257 - if (!lwM2MClient.isInit()) lwM2MClient.initValue(this.service, request.getPath().toString()); 259 + if (!lwM2MClient.isInit()) {
  260 + lwM2MClient.initValue(this.service, request.getPath().toString());
  261 + }
258 String msg = String.format(LOG_LW2M_ERROR + ": sendRequest: Resource path - %s msg error - %s SendRequest to Client", 262 String msg = String.format(LOG_LW2M_ERROR + ": sendRequest: Resource path - %s msg error - %s SendRequest to Client",
259 request.getPath().toString(), e.toString()); 263 request.getPath().toString(), e.toString());
260 service.sentLogsToThingsboard(msg, registration); 264 service.sentLogsToThingsboard(msg, registration);
@@ -28,10 +28,11 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCreden @@ -28,10 +28,11 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCreden
28 import org.thingsboard.server.transport.lwm2m.server.LwM2MTransportServiceImpl; 28 import org.thingsboard.server.transport.lwm2m.server.LwM2MTransportServiceImpl;
29 import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; 29 import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
30 30
31 -import java.util.ArrayList; 31 +import java.util.List;
32 import java.util.Map; 32 import java.util.Map;
33 import java.util.UUID; 33 import java.util.UUID;
34 import java.util.concurrent.ConcurrentHashMap; 34 import java.util.concurrent.ConcurrentHashMap;
  35 +import java.util.concurrent.CopyOnWriteArrayList;
35 36
36 @Slf4j 37 @Slf4j
37 @Data 38 @Data
@@ -51,7 +52,7 @@ public class LwM2MClient implements Cloneable { @@ -51,7 +52,7 @@ public class LwM2MClient implements Cloneable {
51 private Map<String, String> attributes; 52 private Map<String, String> attributes;
52 private Map<String, ResourceValue> resources; 53 private Map<String, ResourceValue> resources;
53 private Map<String, TransportProtos.TsKvProto> delayedRequests; 54 private Map<String, TransportProtos.TsKvProto> delayedRequests;
54 - private ArrayList<String> pendingRequests; 55 + private List<String> pendingRequests;
55 private boolean init; 56 private boolean init;
56 private final LwM2mValueConverterImpl converter; 57 private final LwM2mValueConverterImpl converter;
57 58
@@ -66,7 +67,7 @@ public class LwM2MClient implements Cloneable { @@ -66,7 +67,7 @@ public class LwM2MClient implements Cloneable {
66 this.credentialsResponse = credentialsResponse; 67 this.credentialsResponse = credentialsResponse;
67 this.attributes = new ConcurrentHashMap<>(); 68 this.attributes = new ConcurrentHashMap<>();
68 this.delayedRequests = new ConcurrentHashMap<>(); 69 this.delayedRequests = new ConcurrentHashMap<>();
69 - this.pendingRequests = new ArrayList<>(); 70 + this.pendingRequests = new CopyOnWriteArrayList<>();
70 this.resources = new ConcurrentHashMap<>(); 71 this.resources = new ConcurrentHashMap<>();
71 this.profileUuid = profileUuid; 72 this.profileUuid = profileUuid;
72 this.sessionUuid = sessionUuid; 73 this.sessionUuid = sessionUuid;
@@ -165,12 +165,12 @@ public class LwM2mInMemorySecurityStore extends InMemorySecurityStore { @@ -165,12 +165,12 @@ public class LwM2mInMemorySecurityStore extends InMemorySecurityStore {
165 if (this.sessions.get(registration.getEndpoint()) == null) { 165 if (this.sessions.get(registration.getEndpoint()) == null) {
166 this.addLwM2MClientToSession(registration.getEndpoint()); 166 this.addLwM2MClientToSession(registration.getEndpoint());
167 } 167 }
168 - LwM2MClient lwM2MClient = this.sessions.get(registration.getEndpoint()).copy(); 168 + LwM2MClient lwM2MClient = this.sessions.get(registration.getEndpoint());
169 lwM2MClient.setLwServer(lwServer); 169 lwM2MClient.setLwServer(lwServer);
170 lwM2MClient.setRegistration(registration); 170 lwM2MClient.setRegistration(registration);
171 lwM2MClient.setAttributes(registration.getAdditionalRegistrationAttributes()); 171 lwM2MClient.setAttributes(registration.getAdditionalRegistrationAttributes());
172 - this.sessions.put(registration.getId(), lwM2MClient);  
173 this.sessions.remove(registration.getEndpoint()); 172 this.sessions.remove(registration.getEndpoint());
  173 + this.sessions.put(registration.getId(), lwM2MClient);
174 return lwM2MClient; 174 return lwM2MClient;
175 } finally { 175 } finally {
176 writeLock.unlock(); 176 writeLock.unlock();
@@ -248,7 +248,8 @@ public class LwM2mInMemorySecurityStore extends InMemorySecurityStore { @@ -248,7 +248,8 @@ public class LwM2mInMemorySecurityStore extends InMemorySecurityStore {
248 LwM2MClientProfile lwM2MClientProfile = LwM2MTransportHandler.getLwM2MClientProfileFromThingsboard(deviceProfile); 248 LwM2MClientProfile lwM2MClientProfile = LwM2MTransportHandler.getLwM2MClientProfileFromThingsboard(deviceProfile);
249 if (lwM2MClientProfile != null) { 249 if (lwM2MClientProfile != null) {
250 profiles.put(deviceProfile.getUuidId(), lwM2MClientProfile); 250 profiles.put(deviceProfile.getUuidId(), lwM2MClientProfile);
  251 + return true;
251 } 252 }
252 - return (lwM2MClientProfile != null); 253 + return false;
253 } 254 }
254 } 255 }