Commit 6d7a8706097cc7c703d2d07e2231ded76f442703
1 parent
def5fe4c
Correct sequence of client initialization
Showing
2 changed files
with
9 additions
and
26 deletions
... | ... | @@ -77,8 +77,6 @@ public class LwM2mClient implements Cloneable { |
77 | 77 | @Getter |
78 | 78 | private final Map<String, TsKvProto> sharedAttributes; |
79 | 79 | @Getter |
80 | - private final List<String> pendingReadRequests; | |
81 | - @Getter | |
82 | 80 | private final Queue<LwM2mQueuedRequest> queuedRequests; |
83 | 81 | |
84 | 82 | @Getter |
... | ... | @@ -110,9 +108,6 @@ public class LwM2mClient implements Cloneable { |
110 | 108 | |
111 | 109 | private ValidateDeviceCredentialsResponse credentials; |
112 | 110 | |
113 | - @Getter | |
114 | - private boolean init; | |
115 | - | |
116 | 111 | public Object clone() throws CloneNotSupportedException { |
117 | 112 | return super.clone(); |
118 | 113 | } |
... | ... | @@ -122,7 +117,6 @@ public class LwM2mClient implements Cloneable { |
122 | 117 | this.endpoint = endpoint; |
123 | 118 | this.lock = new ReentrantLock(); |
124 | 119 | this.sharedAttributes = new ConcurrentHashMap<>(); |
125 | - this.pendingReadRequests = new CopyOnWriteArrayList<>(); | |
126 | 120 | this.resources = new ConcurrentHashMap<>(); |
127 | 121 | this.queuedRequests = new ConcurrentLinkedQueue<>(); |
128 | 122 | this.state = LwM2MClientState.CREATED; |
... | ... | @@ -132,7 +126,6 @@ public class LwM2mClient implements Cloneable { |
132 | 126 | this.identity = identity; |
133 | 127 | this.securityInfo = securityInfo; |
134 | 128 | this.credentials = credentials; |
135 | - this.init = false; | |
136 | 129 | this.session = createSession(nodeId, sessionId, credentials); |
137 | 130 | this.tenantId = new TenantId(new UUID(session.getTenantIdMSB(), session.getTenantIdLSB())); |
138 | 131 | this.deviceId = new UUID(session.getDeviceIdMSB(), session.getDeviceIdLSB()); |
... | ... | @@ -365,16 +358,6 @@ public class LwM2mClient implements Cloneable { |
365 | 358 | .collect(Collectors.toSet()); |
366 | 359 | } |
367 | 360 | |
368 | - public void initReadValue(DefaultLwM2MUplinkMsgHandler serviceImpl, String path) { | |
369 | - if (path != null) { | |
370 | - this.pendingReadRequests.remove(path); | |
371 | - } | |
372 | - if (this.pendingReadRequests.size() == 0) { | |
373 | - this.init = true; | |
374 | - serviceImpl.initAttributes(this); | |
375 | - } | |
376 | - } | |
377 | - | |
378 | 361 | public ContentFormat getDefaultContentFormat() { |
379 | 362 | if (registration == null) { |
380 | 363 | return ContentFormat.DEFAULT; | ... | ... |
... | ... | @@ -61,7 +61,6 @@ import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener; |
61 | 61 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext; |
62 | 62 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; |
63 | 63 | import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil; |
64 | -import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor; | |
65 | 64 | import org.thingsboard.server.transport.lwm2m.server.attributes.LwM2MAttributesService; |
66 | 65 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientState; |
67 | 66 | import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException; |
... | ... | @@ -86,6 +85,7 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttrib |
86 | 85 | import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest; |
87 | 86 | import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteResponseCallback; |
88 | 87 | import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteReplaceRequest; |
88 | +import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService; | |
89 | 89 | import org.thingsboard.server.transport.lwm2m.server.rpc.LwM2MRpcRequestHandler; |
90 | 90 | import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore; |
91 | 91 | import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; |
... | ... | @@ -109,7 +109,6 @@ import java.util.stream.Collectors; |
109 | 109 | |
110 | 110 | import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; |
111 | 111 | import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED; |
112 | -import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.INITIATED; | |
113 | 112 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper.getValueFromKvProto; |
114 | 113 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_5_ID; |
115 | 114 | import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_RESULT_ID; |
... | ... | @@ -138,10 +137,10 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler { |
138 | 137 | private final TransportService transportService; |
139 | 138 | private final LwM2mTransportContext context; |
140 | 139 | private final LwM2MAttributesService attributesService; |
140 | + private final LwM2MOtaUpdateService otaService; | |
141 | 141 | public final LwM2MTransportServerConfig config; |
142 | 142 | public final OtaPackageDataCache otaPackageDataCache; |
143 | 143 | public final LwM2mTransportServerHelper helper; |
144 | - private final LwM2MJsonAdaptor adaptor; | |
145 | 144 | private final TbLwM2MDtlsSessionStore sessionStore; |
146 | 145 | public final LwM2mClientContext clientContext; |
147 | 146 | private final LwM2MRpcRequestHandler rpcHandler; |
... | ... | @@ -149,14 +148,16 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler { |
149 | 148 | |
150 | 149 | public final Map<String, Integer> firmwareUpdateState; |
151 | 150 | |
152 | - public DefaultLwM2MUplinkMsgHandler(TransportService transportService, LwM2MAttributesService attributesService, LwM2MTransportServerConfig config, LwM2mTransportServerHelper helper, | |
151 | + public DefaultLwM2MUplinkMsgHandler(TransportService transportService, LwM2MAttributesService attributesService, LwM2MOtaUpdateService otaService, | |
152 | + LwM2MTransportServerConfig config, LwM2mTransportServerHelper helper, | |
153 | 153 | LwM2mClientContext clientContext, |
154 | 154 | @Lazy LwM2MRpcRequestHandler rpcHandler, |
155 | 155 | @Lazy LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler, |
156 | 156 | OtaPackageDataCache otaPackageDataCache, |
157 | - LwM2mTransportContext context, LwM2MJsonAdaptor adaptor, TbLwM2MDtlsSessionStore sessionStore) { | |
157 | + LwM2mTransportContext context, TbLwM2MDtlsSessionStore sessionStore) { | |
158 | 158 | this.transportService = transportService; |
159 | 159 | this.attributesService = attributesService; |
160 | + this.otaService = otaService; | |
160 | 161 | this.config = config; |
161 | 162 | this.helper = helper; |
162 | 163 | this.clientContext = clientContext; |
... | ... | @@ -164,7 +165,6 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler { |
164 | 165 | this.defaultLwM2MDownlinkMsgHandler = defaultLwM2MDownlinkMsgHandler; |
165 | 166 | this.otaPackageDataCache = otaPackageDataCache; |
166 | 167 | this.context = context; |
167 | - this.adaptor = adaptor; | |
168 | 168 | this.firmwareUpdateState = new ConcurrentHashMap<>(); |
169 | 169 | this.sessionStore = sessionStore; |
170 | 170 | } |
... | ... | @@ -218,6 +218,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler { |
218 | 218 | this.getInfoSoftwareUpdate(lwM2MClient); |
219 | 219 | this.initClientTelemetry(lwM2MClient); |
220 | 220 | this.initAttributes(lwM2MClient); |
221 | + otaService.init(lwM2MClient); | |
221 | 222 | } else { |
222 | 223 | log.error("Client: [{}] onRegistered [{}] name [{}] lwM2MClient ", registration.getId(), registration.getEndpoint(), null); |
223 | 224 | } |
... | ... | @@ -441,7 +442,6 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler { |
441 | 442 | if (supportedObjects != null && supportedObjects.size() > 0) { |
442 | 443 | if (LwM2mTransportUtil.LwM2MClientStrategy.CLIENT_STRATEGY_2.code == profile.getClientLwM2mSettings().getClientOnlyObserveAfterConnect()) { |
443 | 444 | // #2 |
444 | - lwM2MClient.getPendingReadRequests().addAll(supportedObjects); | |
445 | 445 | supportedObjects.forEach(versionedId -> sendReadRequest(lwM2MClient, versionedId)); |
446 | 446 | } |
447 | 447 | // #1 |
... | ... | @@ -464,7 +464,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler { |
464 | 464 | try { |
465 | 465 | latch.await(); |
466 | 466 | } catch (InterruptedException e) { |
467 | - log.error("Failed to await Read requests!"); | |
467 | + log.error("[{}] Failed to await Read requests!", lwM2MClient.getEndpoint()); | |
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
... | ... | @@ -478,7 +478,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler { |
478 | 478 | try { |
479 | 479 | latch.await(); |
480 | 480 | } catch (InterruptedException e) { |
481 | - log.error("Failed to await Observe requests!"); | |
481 | + log.error("[{}] Failed to await Observe requests!", lwM2MClient.getEndpoint()); | |
482 | 482 | } |
483 | 483 | } |
484 | 484 | ... | ... |