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