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