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