fixed race condition during unreq and updating lwm2m client
This commit is contained in:
parent
bfb055cc6e
commit
ee74bbed21
@ -166,7 +166,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
|
||||
this.lwM2mClientsByRegistrationId.put(registration.getId(), client);
|
||||
client.setState(LwM2MClientState.REGISTERED);
|
||||
onUplink(client);
|
||||
if(!compareAndSetSleepFlag(client, false)){
|
||||
if (!compareAndSetSleepFlag(client, false)) {
|
||||
clientStore.put(client);
|
||||
}
|
||||
} finally {
|
||||
@ -316,7 +316,11 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
|
||||
public void update(LwM2mClient client) {
|
||||
client.lock();
|
||||
try {
|
||||
clientStore.put(client);
|
||||
if (client.getState().equals(LwM2MClientState.REGISTERED)) {
|
||||
clientStore.put(client);
|
||||
} else {
|
||||
log.error("[{}] Client is in invalid state: {}!", client.getEndpoint(), client.getState());
|
||||
}
|
||||
} finally {
|
||||
client.unlock();
|
||||
}
|
||||
|
||||
@ -106,6 +106,7 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
|
||||
|
||||
public abstract OtaPackageType getType();
|
||||
|
||||
@JsonIgnore
|
||||
public String getTargetPackageId() {
|
||||
return getPackageId(targetName, targetVersion);
|
||||
}
|
||||
|
||||
@ -15,11 +15,13 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.lwm2m.server.store;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nustaq.serialization.FSTConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisClusterConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientState;
|
||||
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -27,6 +29,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
public class TbRedisLwM2MClientStore implements TbLwM2MClientStore {
|
||||
|
||||
private static final String CLIENT_EP = "CLIENT#EP#";
|
||||
@ -76,9 +79,13 @@ public class TbRedisLwM2MClientStore implements TbLwM2MClientStore {
|
||||
|
||||
@Override
|
||||
public void put(LwM2mClient client) {
|
||||
byte[] clientSerialized = serializer.asByteArray(client);
|
||||
try (var connection = connectionFactory.getConnection()) {
|
||||
connection.getSet(getKey(client.getEndpoint()), clientSerialized);
|
||||
if (client.getState().equals(LwM2MClientState.UNREGISTERED)) {
|
||||
log.error("[{}] Client is in invalid state: {}!", client.getEndpoint(), client.getState(), new Exception());
|
||||
} else {
|
||||
byte[] clientSerialized = serializer.asByteArray(client);
|
||||
try (var connection = connectionFactory.getConnection()) {
|
||||
connection.getSet(getKey(client.getEndpoint()), clientSerialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user