fixed registration looping
This commit is contained in:
		
							parent
							
								
									4cbbefdd26
								
							
						
					
					
						commit
						9a1000a45d
					
				@ -51,6 +51,7 @@ import java.util.Set;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.concurrent.ConcurrentHashMap;
 | 
			
		||||
import java.util.concurrent.Future;
 | 
			
		||||
import java.util.concurrent.atomic.AtomicInteger;
 | 
			
		||||
import java.util.concurrent.locks.Lock;
 | 
			
		||||
import java.util.concurrent.locks.ReentrantLock;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
@ -113,6 +114,9 @@ public class LwM2mClient implements Serializable {
 | 
			
		||||
 | 
			
		||||
    private boolean firstEdrxDownlink = true;
 | 
			
		||||
 | 
			
		||||
    @Getter
 | 
			
		||||
    private final AtomicInteger retryAttempts;
 | 
			
		||||
 | 
			
		||||
    public Object clone() throws CloneNotSupportedException {
 | 
			
		||||
        return super.clone();
 | 
			
		||||
    }
 | 
			
		||||
@ -124,6 +128,7 @@ public class LwM2mClient implements Serializable {
 | 
			
		||||
        this.resources = new ConcurrentHashMap<>();
 | 
			
		||||
        this.state = LwM2MClientState.CREATED;
 | 
			
		||||
        this.lock = new ReentrantLock();
 | 
			
		||||
        this.retryAttempts = new AtomicInteger(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void init(ValidateDeviceCredentialsResponse credentials, UUID sessionId) {
 | 
			
		||||
 | 
			
		||||
@ -110,11 +110,11 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.c
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertOtaUpdateValueToString;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.fromVersionedIdToObjectId;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_3_VER_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_VER_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_DELIVERY_METHOD;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_NAME_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_RESULT_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_STATE_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_VER_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_3_VER_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_NAME_ID;
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_RESULT_ID;
 | 
			
		||||
@ -219,11 +219,16 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
 | 
			
		||||
                this.initClientTelemetry(lwM2MClient);
 | 
			
		||||
                this.initAttributes(lwM2MClient);
 | 
			
		||||
                otaService.init(lwM2MClient);
 | 
			
		||||
                lwM2MClient.getRetryAttempts().set(0);
 | 
			
		||||
            } catch (LwM2MClientStateException stateException) {
 | 
			
		||||
                if (LwM2MClientState.UNREGISTERED.equals(stateException.getState())) {
 | 
			
		||||
                    log.info("[{}] retry registration due to race condition: [{}].", registration.getEndpoint(), stateException.getState());
 | 
			
		||||
                    // Race condition detected and the client was in progress of unregistration while new registration arrived. Let's try again.
 | 
			
		||||
                    onRegistered(registration, previousObservations);
 | 
			
		||||
                    if (lwM2MClient.getRetryAttempts().incrementAndGet() <= 5) {
 | 
			
		||||
                        context.getScheduler().schedule(() -> onRegistered(registration, previousObservations), 1, TimeUnit.SECONDS);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        logService.log(lwM2MClient, LOG_LWM2M_WARN + ": Client registration failed due to retry attempts: " + lwM2MClient.getRetryAttempts().get());
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    logService.log(lwM2MClient, LOG_LWM2M_WARN + ": Client registration failed due to invalid state: " + stateException.getState());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user