@ -36,7 +36,6 @@ import org.eclipse.leshan.core.util.NamedThreadFactory;
import org.eclipse.leshan.server.californium.LeshanServer ;
import org.eclipse.leshan.server.registration.Registration ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression ;
import org.springframework.stereotype.Service ;
import org.thingsboard.server.common.data.Device ;
import org.thingsboard.server.common.data.DeviceProfile ;
@ -48,11 +47,12 @@ import org.thingsboard.server.gen.transport.TransportProtos;
import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg ;
import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent ;
import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClient ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientProfile ;
import org.thingsboard.server.queue.util.TbLwM2mTransportComponent ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientProfile ;
import org.thingsboard.server.transport.lwm2m.server.client.ResourceValue ;
import org.thingsboard.server.transport.lwm2m.server.client.ResultsAnalyzerParameters ;
import org.thingsboard.server.transport.lwm2m.server.secure.LwM2mInMemorySecurityStore ;
import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl ;
import javax.annotation.PostConstruct ;
@ -79,24 +79,24 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors ;
import static org.thingsboard.server.common.transport.util.JsonUtils.getJsonObject ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.CLIENT_NOT_AUTHORIZED ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.DEVICE_ATTRIBUTES_REQUEST ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.DEVICE_ATTRIBUTES_TOPIC ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.DEVICE_TELEMETRY_TOPIC ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.GET_TYPE_OPER_OBSERVE ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.GET_TYPE_OPER_READ ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.LOG_LW2M_ERROR ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.LOG_LW2M_INFO ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.LOG_LW2M_TELEMETRY ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.POST_TYPE_OPER_EXECUTE ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.POST_TYPE_OPER_WRITE_REPLACE ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.SERVICE_CHANNEL ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2M TransportHandler.getAckCallback ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.CLIENT_NOT_AUTHORIZED ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.DEVICE_ATTRIBUTES_REQUEST ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.DEVICE_ATTRIBUTES_TOPIC ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.DEVICE_TELEMETRY_TOPIC ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.GET_TYPE_OPER_OBSERVE ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.GET_TYPE_OPER_READ ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.LOG_LW2M_ERROR ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.LOG_LW2M_INFO ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.LOG_LW2M_TELEMETRY ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.POST_TYPE_OPER_EXECUTE ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.POST_TYPE_OPER_WRITE_REPLACE ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.SERVICE_CHANNEL ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2m TransportHandler.getAckCallback ;
@Slf4j
@Service ( "LwM2MTransportService" )
@ConditionalOnExpression ( "('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true' ) || ('${service.type:null}'=='monolith' && '${transport.lwm2m.enabled}'=='true')" )
public class LwM2MTransportServiceImpl implements LwM2M TransportService {
@Service
@TbLwM2mTransportComponent
public class LwM2mTransportServiceImpl implements LwM2m TransportService {
private ExecutorService executorRegistered ;
private ExecutorService executorUpdateRegistered ;
@ -105,27 +105,29 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
protected final ReadWriteLock readWriteLock = new ReentrantReadWriteLock ( ) ;
protected final Lock writeLock = readWriteLock . writeLock ( ) ;
@Autowired
private TransportService transportService ;
@Autowired
public LwM2M TransportContextServer context ;
public LwM2m TransportContextServer context ;
@Autowired
private LwM2MTransportRequest lwM2M TransportRequest ;
private LwM2mTransportRequest lwM2m TransportRequest ;
@Autowired
LwM2mInMemorySecurityStore lwM2mInMemorySecurityStore ;
private LwM2mClientContext lwM2mClientContext ;
@Autowired ( required = false )
private LeshanServer leshanServer ;
@PostConstruct
public void init ( ) {
this . context . getScheduler ( ) . scheduleAtFixedRate ( this : : checkInactivityAndReportActivity , new Random ( ) . nextInt ( ( int ) context . getCtx Server ( ) . getSessionReportTimeout ( ) ) , context . getCtx Server ( ) . getSessionReportTimeout ( ) , TimeUnit . MILLISECONDS ) ;
this . executorRegistered = Executors . newFixedThreadPool ( this . context . getCtx Server ( ) . getRegisteredPoolSize ( ) ,
this . context . getScheduler ( ) . scheduleAtFixedRate ( this : : checkInactivityAndReportActivity , new Random ( ) . nextInt ( ( int ) context . getLwM2MTransportConfig Server ( ) . getSessionReportTimeout ( ) ) , context . getLwM2MTransportConfig Server ( ) . getSessionReportTimeout ( ) , TimeUnit . MILLISECONDS ) ;
this . executorRegistered = Executors . newFixedThreadPool ( this . context . getLwM2MTransportConfig Server ( ) . getRegisteredPoolSize ( ) ,
new NamedThreadFactory ( String . format ( "LwM2M %s channel registered" , SERVICE_CHANNEL ) ) ) ;
this . executorUpdateRegistered = Executors . newFixedThreadPool ( this . context . getCtx Server ( ) . getUpdateRegisteredPoolSize ( ) ,
this . executorUpdateRegistered = Executors . newFixedThreadPool ( this . context . getLwM2MTransportConfig Server ( ) . getUpdateRegisteredPoolSize ( ) ,
new NamedThreadFactory ( String . format ( "LwM2M %s channel update registered" , SERVICE_CHANNEL ) ) ) ;
this . executorUnRegistered = Executors . newFixedThreadPool ( this . context . getCtx Server ( ) . getUnRegisteredPoolSize ( ) ,
this . executorUnRegistered = Executors . newFixedThreadPool ( this . context . getLwM2MTransportConfig Server ( ) . getUnRegisteredPoolSize ( ) ,
new NamedThreadFactory ( String . format ( "LwM2M %s channel un registered" , SERVICE_CHANNEL ) ) ) ;
this . converter = LwM2mValueConverterImpl . getInstance ( ) ;
}
@ -149,17 +151,16 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
executorRegistered . submit ( ( ) - > {
try {
log . warn ( "[{}] [{{}] Client: create after Registration" , registration . getEndpoint ( ) , registration . getId ( ) ) ;
LwM2M Client lwM2MClient = this . lwM2mInMemorySecurityStore . updateInSessionsLwM2MClient ( lwServer , registration ) ;
LwM2m Client lwM2MClient = this . lwM2mClientContext . updateInSessionsLwM2MClient ( registration ) ;
if ( lwM2MClient ! = null ) {
lwM2MClient . setLwM2MTransportServiceImpl ( this ) ;
this . sentLogsToThingsboard ( LOG_LW2M_INFO + ": Client Registered" , registration ) ;
SessionInfoProto sessionInfo = this . getValidateSessionInfo ( registration ) ;
if ( sessionInfo ! = null ) {
lwM2MClient . setDeviceUui d ( new UUID ( sessionInfo . getDeviceIdMSB ( ) , sessionInfo . getDeviceIdLSB ( ) ) ) ;
lwM2MClient . setProfileUui d ( new UUID ( sessionInfo . getDeviceProfileIdMSB ( ) , sessionInfo . getDeviceProfileIdLSB ( ) ) ) ;
lwM2MClient . setDeviceI d ( new UUID ( sessionInfo . getDeviceIdMSB ( ) , sessionInfo . getDeviceIdLSB ( ) ) ) ;
lwM2MClient . setProfileI d ( new UUID ( sessionInfo . getDeviceProfileIdMSB ( ) , sessionInfo . getDeviceProfileIdLSB ( ) ) ) ;
lwM2MClient . setDeviceName ( sessionInfo . getDeviceName ( ) ) ;
lwM2MClient . setDeviceProfileName ( sessionInfo . getDeviceType ( ) ) ;
transportService . registerAsyncSession ( sessionInfo , new LwM2M SessionMsgListener ( this , sessionInfo ) ) ;
transportService . registerAsyncSession ( sessionInfo , new LwM2m SessionMsgListener ( this , sessionInfo ) ) ;
transportService . process ( sessionInfo , DefaultTransportService . getSessionEventMsg ( SessionEvent . OPEN ) , null ) ;
transportService . process ( sessionInfo , TransportProtos . SubscribeToAttributeUpdatesMsg . newBuilder ( ) . build ( ) , null ) ;
this . sentLogsToThingsboard ( LOG_LW2M_INFO + ": Client create after Registration" , registration ) ;
@ -221,8 +222,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
if ( sessionInfo ! = null ) {
transportService . deregisterSession ( sessionInfo ) ;
this . doCloseSession ( sessionInfo ) ;
lwM2mInMemorySecurityStore . delRemoveSessionAndListener ( registration . getId ( ) ) ;
if ( lwM2mInMemorySecurityStore . getProfiles ( ) . size ( ) > 0 ) {
lwM2mClientContext . delRemoveSessionAndListener ( registration . getId ( ) ) ;
if ( lwM2mClientContext . getProfiles ( ) . size ( ) > 0 ) {
this . syncSessionsAndProfiles ( ) ;
}
log . info ( "Client close session: [{}] unReg [{}] name [{}] profile " , registration . getId ( ) , registration . getEndpoint ( ) , sessionInfo . getDeviceType ( ) ) ;
@ -292,13 +293,13 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
el . getAsJsonObject ( ) . entrySet ( ) . forEach ( de - > {
String path = this . getPathAttributeUpdate ( sessionInfo , de . getKey ( ) ) ;
String value = de . getValue ( ) . getAsString ( ) ;
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getSession ( new UUID ( sessionInfo . getSessionIdMSB ( ) , sessionInfo . getSessionIdLSB ( ) ) ) . entrySet ( ) . iterator ( ) . next ( ) . getValue ( ) ;
LwM2MClientProfile profile = lwM2mInMemorySecurityStore . getProfile ( new UUID ( sessionInfo . getDeviceProfileIdMSB ( ) , sessionInfo . getDeviceProfileIdLSB ( ) ) ) ;
ResourceModel resourceModel = context . getCtx Server ( ) . getResourceModel ( lwM2MClient . getRegistration ( ) , new LwM2mPath ( path ) ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2mClient ( new UUID ( sessionInfo . getSessionIdMSB ( ) , sessionInfo . getSessionIdLSB ( ) ) ) ;
LwM2mClientProfile profile = lwM2mClientContext . getProfile ( new UUID ( sessionInfo . getDeviceProfileIdMSB ( ) , sessionInfo . getDeviceProfileIdLSB ( ) ) ) ;
ResourceModel resourceModel = context . getLwM2MTransportConfig Server ( ) . getResourceModel ( lwM2MClient . getRegistration ( ) , new LwM2mPath ( path ) ) ;
if ( ! path . isEmpty ( ) & & ( this . validatePathInAttrProfile ( profile , path ) | | this . validatePathInTelemetryProfile ( profile , path ) ) ) {
if ( resourceModel ! = null & & resourceModel . operations . isWritable ( ) ) {
lwM2M TransportRequest . sendAllRequest ( lwM2MClient . getLwServer ( ) , lwM2MClient . getRegistration ( ) , path , POST_TYPE_OPER_WRITE_REPLACE ,
ContentFormat . TLV . getName ( ) , null , value , this . context . getCtx Server ( ) . getTimeout ( ) ) ;
lwM2m TransportRequest . sendAllRequest ( leshanServer , lwM2MClient . getRegistration ( ) , path , POST_TYPE_OPER_WRITE_REPLACE ,
ContentFormat . TLV . getName ( ) , null , value , this . context . getLwM2MTransportConfig Server ( ) . getTimeout ( ) ) ;
} else {
log . error ( "Resource path - [{}] value - [{}] is not Writable and cannot be updated" , path , value ) ;
String logMsg = String . format ( "%s: attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated" ,
@ -323,9 +324,9 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* /
@Override
public void onDeviceProfileUpdate ( SessionInfoProto sessionInfo , DeviceProfile deviceProfile ) {
Set < String > registrationIds = lwM2mInMemorySecurityStore . getSession s ( ) . entrySet ( )
Set < String > registrationIds = lwM2mClientContext . getLwM2mClient s ( ) . entrySet ( )
. stream ( )
. filter ( e - > e . getValue ( ) . getProfileUui d ( ) . equals ( deviceProfile . getUuidId ( ) ) )
. filter ( e - > e . getValue ( ) . getProfileI d ( ) . equals ( deviceProfile . getUuidId ( ) ) )
. map ( Map . Entry : : getKey ) . sorted ( ) . collect ( Collectors . toCollection ( LinkedHashSet : : new ) ) ;
if ( registrationIds . size ( ) > 0 ) {
this . onDeviceUpdateChangeProfile ( registrationIds , deviceProfile ) ;
@ -339,8 +340,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* /
@Override
public void onDeviceUpdate ( SessionInfoProto sessionInfo , Device device , Optional < DeviceProfile > deviceProfileOpt ) {
Optional < String > registrationIdOpt = lwM2mInMemorySecurityStore . getSession s ( ) . entrySet ( ) . stream ( )
. filter ( e - > device . getUuidId ( ) . equals ( e . getValue ( ) . getDeviceUui d ( ) ) )
Optional < String > registrationIdOpt = lwM2mClientContext . getLwM2mClient s ( ) . entrySet ( ) . stream ( )
. filter ( e - > device . getUuidId ( ) . equals ( e . getValue ( ) . getDeviceI d ( ) ) )
. map ( Map . Entry : : getKey )
. findFirst ( ) ;
registrationIdOpt . ifPresent ( registrationId - > this . onDeviceUpdateLwM2MClient ( registrationId , device , deviceProfileOpt ) ) ;
@ -353,8 +354,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* /
@Override
public void doTrigger ( LeshanServer lwServer , Registration registration , String path ) {
lwM2M TransportRequest . sendAllRequest ( lwServer , registration , path , POST_TYPE_OPER_EXECUTE ,
ContentFormat . TLV . getName ( ) , null , null , this . context . getCtx Server ( ) . getTimeout ( ) ) ;
lwM2m TransportRequest . sendAllRequest ( lwServer , registration , path , POST_TYPE_OPER_EXECUTE ,
ContentFormat . TLV . getName ( ) , null , null , this . context . getLwM2MTransportConfig Server ( ) . getTimeout ( ) ) ;
}
/ * *
@ -397,18 +398,18 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* Removes a profile if not used in sessions
* /
private void syncSessionsAndProfiles ( ) {
Map < UUID , LwM2M ClientProfile > profilesClone = lwM2mInMemorySecurityStore . getProfiles ( ) . entrySet ( )
Map < UUID , LwM2m ClientProfile > profilesClone = lwM2mClientContext . getProfiles ( ) . entrySet ( )
. stream ( )
. collect ( Collectors . toMap ( Map . Entry : : getKey , Map . Entry : : getValue ) ) ;
profilesClone . forEach ( ( k , v ) - > {
String registrationId = lwM2mInMemorySecurityStore . getSession s ( ) . entrySet ( )
String registrationId = lwM2mClientContext . getLwM2mClient s ( ) . entrySet ( )
. stream ( )
. filter ( e - > e . getValue ( ) . getProfileUui d ( ) . equals ( k ) )
. filter ( e - > e . getValue ( ) . getProfileI d ( ) . equals ( k ) )
. findFirst ( )
. map ( Map . Entry : : getKey ) // return the key of the matching entry if found
. orElse ( "" ) ;
if ( registrationId . isEmpty ( ) ) {
lwM2mInMemorySecurityStore . getProfiles ( ) . remove ( k ) ;
lwM2mClientContext . getProfiles ( ) . remove ( k ) ;
}
} ) ;
}
@ -458,12 +459,12 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param registration - Registration LwM2M Client
* @param lwM2MClient - object with All parameters off client
* /
private void initLwM2mFromClientValue ( LeshanServer lwServer , Registration registration , LwM2M Client lwM2MClient ) {
LwM2M ClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore . getProfile ( registration . getId ( ) ) ;
private void initLwM2mFromClientValue ( LeshanServer lwServer , Registration registration , LwM2m Client lwM2MClient ) {
LwM2m ClientProfile lwM2MClientProfile = lwM2mClientContext . getProfile ( registration ) ;
Set < String > clientObjects = this . getAllOjectsInClient ( registration ) ;
if ( clientObjects ! = null & & ! LwM2M TransportHandler . getClientOnlyObserveAfterConnect ( lwM2MClientProfile ) ) {
if ( clientObjects ! = null & & ! LwM2m TransportHandler . getClientOnlyObserveAfterConnect ( lwM2MClientProfile ) ) {
// #2
if ( ! LwM2M TransportHandler . getClientUpdateValueAfterConnect ( lwM2MClientProfile ) ) {
if ( ! LwM2m TransportHandler . getClientUpdateValueAfterConnect ( lwM2MClientProfile ) ) {
this . initReadAttrTelemetryObserveToClient ( lwServer , registration , lwM2MClient , GET_TYPE_OPER_READ ) ;
}
@ -471,8 +472,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
else {
lwM2MClient . getPendingRequests ( ) . addAll ( clientObjects ) ;
clientObjects . forEach ( path - > {
lwM2M TransportRequest . sendAllRequest ( lwServer , registration , path , GET_TYPE_OPER_READ , ContentFormat . TLV . getName ( ) ,
null , null , this . context . getCtx Server ( ) . getTimeout ( ) ) ;
lwM2m TransportRequest . sendAllRequest ( lwServer , registration , path , GET_TYPE_OPER_READ , ContentFormat . TLV . getName ( ) ,
null , null , this . context . getLwM2MTransportConfig Server ( ) . getTimeout ( ) ) ;
} ) ;
}
}
@ -517,7 +518,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param path - resource
* /
private void updateResourcesValue ( Registration registration , LwM2mResource lwM2mResource , String path ) {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getLwM2M ClientWithReg ( registration , null ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2m ClientWithReg ( registration , null ) ;
lwM2MClient . updateResourceValue ( path , lwM2mResource ) ;
Set < String > paths = new HashSet < > ( ) ;
paths . add ( path ) ;
@ -565,8 +566,9 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param path -
* @return true if path isPresent in postAttributeProfile
* /
private boolean validatePathInAttrProfile ( LwM2MClientProfile profile , String path ) {
Set < String > attributesSet = new Gson ( ) . fromJson ( profile . getPostAttributeProfile ( ) , new TypeToken < > ( ) { } . getType ( ) ) ;
private boolean validatePathInAttrProfile ( LwM2mClientProfile profile , String path ) {
Set < String > attributesSet = new Gson ( ) . fromJson ( profile . getPostAttributeProfile ( ) , new TypeToken < > ( ) {
} . getType ( ) ) ;
return attributesSet . stream ( ) . filter ( p - > p . equals ( path ) ) . findFirst ( ) . isPresent ( ) ;
}
@ -575,8 +577,9 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param path -
* @return true if path isPresent in postAttributeProfile
* /
private boolean validatePathInTelemetryProfile ( LwM2MClientProfile profile , String path ) {
Set < String > telemetriesSet = new Gson ( ) . fromJson ( profile . getPostTelemetryProfile ( ) , new TypeToken < > ( ) { } . getType ( ) ) ;
private boolean validatePathInTelemetryProfile ( LwM2mClientProfile profile , String path ) {
Set < String > telemetriesSet = new Gson ( ) . fromJson ( profile . getPostTelemetryProfile ( ) , new TypeToken < > ( ) {
} . getType ( ) ) ;
return telemetriesSet . stream ( ) . filter ( p - > p . equals ( path ) ) . findFirst ( ) . isPresent ( ) ;
}
@ -588,16 +591,19 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param lwServer -
* @param registration -
* /
private void initReadAttrTelemetryObserveToClient ( LeshanServer lwServer , Registration registration , LwM2M Client lwM2MClient , String typeOper ) {
private void initReadAttrTelemetryObserveToClient ( LeshanServer lwServer , Registration registration , LwM2m Client lwM2MClient , String typeOper ) {
try {
LwM2M ClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore . getProfile ( registration . getId ( ) ) ;
LwM2m ClientProfile lwM2MClientProfile = lwM2mClientContext . getProfile ( registration ) ;
Set < String > clientInstances = this . getAllInstancesInClient ( registration ) ;
Set < String > result ;
if ( GET_TYPE_OPER_READ . equals ( typeOper ) ) {
result = new ObjectMapper ( ) . readValue ( lwM2MClientProfile . getPostAttributeProfile ( ) . getAsJsonArray ( ) . toString ( ) . getBytes ( ) , new TypeReference < > ( ) { } ) ;
result . addAll ( new ObjectMapper ( ) . readValue ( lwM2MClientProfile . getPostTelemetryProfile ( ) . getAsJsonArray ( ) . toString ( ) . getBytes ( ) , new TypeReference < > ( ) { } ) ) ;
result = new ObjectMapper ( ) . readValue ( lwM2MClientProfile . getPostAttributeProfile ( ) . getAsJsonArray ( ) . toString ( ) . getBytes ( ) , new TypeReference < > ( ) {
} ) ;
result . addAll ( new ObjectMapper ( ) . readValue ( lwM2MClientProfile . getPostTelemetryProfile ( ) . getAsJsonArray ( ) . toString ( ) . getBytes ( ) , new TypeReference < > ( ) {
} ) ) ;
} else {
result = new ObjectMapper ( ) . readValue ( lwM2MClientProfile . getPostObserveProfile ( ) . getAsJsonArray ( ) . toString ( ) . getBytes ( ) , new TypeReference < > ( ) { } ) ;
result = new ObjectMapper ( ) . readValue ( lwM2MClientProfile . getPostObserveProfile ( ) . getAsJsonArray ( ) . toString ( ) . getBytes ( ) , new TypeReference < > ( ) {
} ) ;
}
Set < String > pathSent = ConcurrentHashMap . newKeySet ( ) ;
result . forEach ( p - > {
@ -611,8 +617,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
} ) ;
lwM2MClient . getPendingRequests ( ) . addAll ( pathSent ) ;
pathSent . forEach ( target - > {
lwM2M TransportRequest . sendAllRequest ( lwServer , registration , target , typeOper , ContentFormat . TLV . getName ( ) ,
null , null , this . context . getCtx Server ( ) . getTimeout ( ) ) ;
lwM2m TransportRequest . sendAllRequest ( lwServer , registration , target , typeOper , ContentFormat . TLV . getName ( ) ,
null , null , this . context . getLwM2MTransportConfig Server ( ) . getTimeout ( ) ) ;
} ) ;
if ( GET_TYPE_OPER_OBSERVE . equals ( typeOper ) ) {
lwM2MClient . initValue ( this , null ) ;
@ -630,15 +636,15 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param device -
* /
private void onDeviceUpdateLwM2MClient ( String registrationId , Device device , Optional < DeviceProfile > deviceProfileOpt ) {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getSession s ( ) . get ( registrationId ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2mClient s ( ) . get ( registrationId ) ;
lwM2MClient . setDeviceName ( device . getName ( ) ) ;
if ( ! lwM2MClient . getProfileUui d ( ) . equals ( device . getDeviceProfileId ( ) . getId ( ) ) ) {
if ( ! lwM2MClient . getProfileI d ( ) . equals ( device . getDeviceProfileId ( ) . getId ( ) ) ) {
Set < String > registrationIds = new HashSet < > ( ) ;
registrationIds . add ( registrationId ) ;
deviceProfileOpt . ifPresent ( deviceProfile - > this . onDeviceUpdateChangeProfile ( registrationIds , deviceProfile ) ) ;
}
lwM2MClient . setProfileUui d ( device . getDeviceProfileId ( ) . getId ( ) ) ;
lwM2MClient . setProfileI d ( device . getDeviceProfileId ( ) . getId ( ) ) ;
}
/ * *
@ -693,20 +699,20 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param path
* /
private void getParametersFromProfile ( JsonObject attributes , JsonObject telemetry , Registration registration , Set < String > path ) {
LwM2M ClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore . getProfile ( registration . getId ( ) ) ;
LwM2m ClientProfile lwM2MClientProfile = lwM2mClientContext . getProfile ( registration ) ;
lwM2MClientProfile . getPostAttributeProfile ( ) . forEach ( p - > {
LwM2mPath pathIds = new LwM2mPath ( p . getAsString ( ) . toString ( ) ) ;
LwM2mPath pathIds = new LwM2mPath ( p . getAsString ( ) ) ;
if ( pathIds . isResource ( ) ) {
if ( path = = null | | path . contains ( p . getAsString ( ) ) ) {
this . addParameters ( p . getAsString ( ) . toString ( ) , attributes , registration ) ;
this . addParameters ( p . getAsString ( ) , attributes , registration ) ;
}
}
} ) ;
lwM2MClientProfile . getPostTelemetryProfile ( ) . forEach ( p - > {
LwM2mPath pathIds = new LwM2mPath ( p . getAsString ( ) . toString ( ) ) ;
LwM2mPath pathIds = new LwM2mPath ( p . getAsString ( ) ) ;
if ( pathIds . isResource ( ) ) {
if ( path = = null | | path . contains ( p . getAsString ( ) ) ) {
this . addParameters ( p . getAsString ( ) . toString ( ) , telemetry , registration ) ;
this . addParameters ( p . getAsString ( ) , telemetry , registration ) ;
}
}
} ) ;
@ -717,8 +723,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param registration - Registration LwM2M Client
* /
private void addParameters ( String path , JsonObject parameters , Registration registration ) {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getSessions ( ) . get ( registration . getId ( ) ) ;
JsonObject names = lwM2mInMemorySecurityStore . getProfiles ( ) . get ( lwM2MClient . getProfileUui d ( ) ) . getPostKeyNameProfile ( ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2mClientWithReg ( registration , null ) ;
JsonObject names = lwM2mClientContext . getProfiles ( ) . get ( lwM2MClient . getProfileI d ( ) ) . getPostKeyNameProfile ( ) ;
String resName = String . valueOf ( names . get ( path ) ) ;
if ( resName ! = null & & ! resName . isEmpty ( ) ) {
try {
@ -727,7 +733,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
parameters . addProperty ( resName , resValue ) ;
}
} catch ( Exception e ) {
log . error ( e . getStackTrace ( ) . toString ( ) ) ;
log . error ( "Failed to add parameters." , e ) ;
}
}
}
@ -736,11 +742,11 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param path - path resource
* @return - value of Resource or null
* /
private String getResourceValueToString ( LwM2M Client lwM2MClient , String path ) {
private String getResourceValueToString ( LwM2m Client lwM2MClient , String path ) {
LwM2mPath pathIds = new LwM2mPath ( path ) ;
ResourceValue resourceValue = this . returnResourceValueFromLwM2MClient ( lwM2MClient , pathIds ) ;
return ( resourceValue = = null ) ? null :
( String ) this . converter . convertValue ( resourceValue . getResourceValue ( ) , this . context . getCtx Server ( ) . getResourceModelType ( lwM2MClient . getRegistration ( ) , pathIds ) , ResourceModel . Type . STRING , pathIds ) ;
return resourceValue = = null ? null :
this . converter . convertValue ( resourceValue . getResourceValue ( ) , this . context . getLwM2MTransportConfig Server ( ) . getResourceModelType ( lwM2MClient . getRegistration ( ) , pathIds ) , ResourceModel . Type . STRING , pathIds ) . toString ( ) ;
}
/ * *
@ -749,7 +755,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param pathIds -
* @return - return value of Resource by idPath
* /
private ResourceValue returnResourceValueFromLwM2MClient ( LwM2M Client lwM2MClient , LwM2mPath pathIds ) {
private ResourceValue returnResourceValueFromLwM2MClient ( LwM2m Client lwM2MClient , LwM2mPath pathIds ) {
ResourceValue resourceValue = null ;
if ( pathIds . isResource ( ) ) {
resourceValue = lwM2MClient . getResources ( ) . get ( pathIds . toString ( ) ) ;
@ -790,23 +796,25 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param deviceProfile -
* /
private void onDeviceUpdateChangeProfile ( Set < String > registrationIds , DeviceProfile deviceProfile ) {
LwM2MClientProfile lwM2MClientProfileOld = lwM2mInMemorySecurityStore . getProfiles ( ) . get ( deviceProfile . getUuidId ( ) ) ;
if ( lwM2mInMemorySecurityStore . addUpdateProfileParameters ( deviceProfile ) ) {
LwM2mClientProfile lwM2MClientProfileOld = lwM2mClientContext . getProfiles ( ) . get ( deviceProfile . getUuidId ( ) ) ;
if ( lwM2mClientContext . addUpdateProfileParameters ( deviceProfile ) ) {
// #1
JsonArray attributeOld = lwM2MClientProfileOld . getPostAttributeProfile ( ) ;
Set < String > attributeSetOld = new Gson ( ) . fromJson ( attributeOld , new TypeToken < > ( ) { } . getType ( ) ) ;
Set < String > attributeSetOld = new Gson ( ) . fromJson ( attributeOld , new TypeToken < > ( ) {
} . getType ( ) ) ;
JsonArray telemetryOld = lwM2MClientProfileOld . getPostTelemetryProfile ( ) ;
Set < String > telemetrySetOld = new Gson ( ) . fromJson ( telemetryOld , new TypeToken < > ( ) { } . getType ( ) ) ;
Set < String > telemetrySetOld = new Gson ( ) . fromJson ( telemetryOld , new TypeToken < > ( ) {
} . getType ( ) ) ;
JsonArray observeOld = lwM2MClientProfileOld . getPostObserveProfile ( ) ;
JsonObject keyNameOld = lwM2MClientProfileOld . getPostKeyNameProfile ( ) ;
LwM2M ClientProfile lwM2MClientProfileNew = lwM2mInMemorySecurityStore . getProfiles ( ) . get ( deviceProfile . getUuidId ( ) ) ;
LwM2m ClientProfile lwM2MClientProfileNew = lwM2mClientContext . getProfiles ( ) . get ( deviceProfile . getUuidId ( ) ) ;
JsonArray attributeNew = lwM2MClientProfileNew . getPostAttributeProfile ( ) ;
Set < String > attributeSetNew = new Gson ( ) . fromJson ( attributeNew , new TypeToken < > ( ) { } . getType ( ) ) ;
Set < String > attributeSetNew = new Gson ( ) . fromJson ( attributeNew , new TypeToken < > ( ) {
} . getType ( ) ) ;
JsonArray telemetryNew = lwM2MClientProfileNew . getPostTelemetryProfile ( ) ;
Set < String > telemetrySetNew = new Gson ( ) . fromJson ( telemetryNew , new TypeToken < > ( ) { } . getType ( ) ) ;
Set < String > telemetrySetNew = new Gson ( ) . fromJson ( telemetryNew , new TypeToken < > ( ) {
} . getType ( ) ) ;
JsonArray observeNew = lwM2MClientProfileNew . getPostObserveProfile ( ) ;
JsonObject keyNameNew = lwM2MClientProfileNew . getPostKeyNameProfile ( ) ;
@ -814,20 +822,24 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
ResultsAnalyzerParameters sentAttrToThingsboard = new ResultsAnalyzerParameters ( ) ;
// #3.1
if ( ! attributeOld . equals ( attributeNew ) ) {
ResultsAnalyzerParameters postAttributeAnalyzer = this . getAnalyzerParameters ( new Gson ( ) . fromJson ( attributeOld , new TypeToken < Set < String > > ( ) { } . getType ( ) ) , attributeSetNew ) ;
ResultsAnalyzerParameters postAttributeAnalyzer = this . getAnalyzerParameters ( new Gson ( ) . fromJson ( attributeOld , new TypeToken < Set < String > > ( ) {
} . getType ( ) ) , attributeSetNew ) ;
sentAttrToThingsboard . getPathPostParametersAdd ( ) . addAll ( postAttributeAnalyzer . getPathPostParametersAdd ( ) ) ;
sentAttrToThingsboard . getPathPostParametersDel ( ) . addAll ( postAttributeAnalyzer . getPathPostParametersDel ( ) ) ;
}
// #3.2
if ( ! attributeOld . equals ( attributeNew ) ) {
ResultsAnalyzerParameters postTelemetryAnalyzer = this . getAnalyzerParameters ( new Gson ( ) . fromJson ( telemetryOld , new TypeToken < Set < String > > ( ) { } . getType ( ) ) , telemetrySetNew ) ;
if ( ! telemetryOld . equals ( telemetryNew ) ) {
ResultsAnalyzerParameters postTelemetryAnalyzer = this . getAnalyzerParameters ( new Gson ( ) . fromJson ( telemetryOld , new TypeToken < Set < String > > ( ) {
} . getType ( ) ) , telemetrySetNew ) ;
sentAttrToThingsboard . getPathPostParametersAdd ( ) . addAll ( postTelemetryAnalyzer . getPathPostParametersAdd ( ) ) ;
sentAttrToThingsboard . getPathPostParametersDel ( ) . addAll ( postTelemetryAnalyzer . getPathPostParametersDel ( ) ) ;
}
// #3.3
if ( ! keyNameOld . equals ( keyNameNew ) ) {
ResultsAnalyzerParameters keyNameChange = this . getAnalyzerKeyName ( new Gson ( ) . fromJson ( keyNameOld . toString ( ) , new TypeToken < ConcurrentHashMap < String , String > > ( ) { } . getType ( ) ) ,
new Gson ( ) . fromJson ( keyNameNew . toString ( ) , new TypeToken < ConcurrentHashMap < String , String > > ( ) { } . getType ( ) ) ) ;
ResultsAnalyzerParameters keyNameChange = this . getAnalyzerKeyName ( new Gson ( ) . fromJson ( keyNameOld . toString ( ) , new TypeToken < ConcurrentHashMap < String , String > > ( ) {
} . getType ( ) ) ,
new Gson ( ) . fromJson ( keyNameNew . toString ( ) , new TypeToken < ConcurrentHashMap < String , String > > ( ) {
} . getType ( ) ) ) ;
sentAttrToThingsboard . getPathPostParametersAdd ( ) . addAll ( keyNameChange . getPathPostParametersAdd ( ) ) ;
}
@ -835,9 +847,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
if ( sentAttrToThingsboard . getPathPostParametersAdd ( ) . size ( ) > 0 ) {
// update value in Resources
registrationIds . forEach ( registrationId - > {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getLwM2MClientWithReg ( null , registrationId ) ;
LeshanServer lwServer = lwM2MClient . getLwServer ( ) ;
Registration registration = lwM2mInMemorySecurityStore . getByRegistration ( registrationId ) ;
LeshanServer lwServer = leshanServer ;
Registration registration = lwM2mClientContext . getRegistration ( registrationId ) ;
this . readResourceValueObserve ( lwServer , registration , sentAttrToThingsboard . getPathPostParametersAdd ( ) , GET_TYPE_OPER_READ ) ;
// sent attr/telemetry to tingsboard for new path
this . updateAttrTelemetry ( registration , false , sentAttrToThingsboard . getPathPostParametersAdd ( ) ) ;
@ -851,8 +862,10 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
// #5.1
if ( ! observeOld . equals ( observeNew ) ) {
Set < String > observeSetOld = new Gson ( ) . fromJson ( observeOld , new TypeToken < > ( ) { } . getType ( ) ) ;
Set < String > observeSetNew = new Gson ( ) . fromJson ( observeNew , new TypeToken < > ( ) { } . getType ( ) ) ;
Set < String > observeSetOld = new Gson ( ) . fromJson ( observeOld , new TypeToken < > ( ) {
} . getType ( ) ) ;
Set < String > observeSetNew = new Gson ( ) . fromJson ( observeNew , new TypeToken < > ( ) {
} . getType ( ) ) ;
//#5.2 add
// path Attr/Telemetry includes newObserve
attributeSetOld . addAll ( telemetrySetOld ) ;
@ -863,9 +876,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
ResultsAnalyzerParameters postObserveAnalyzer = this . getAnalyzerParameters ( sentObserveToClientOld . getPathPostParametersAdd ( ) , sentObserveToClientNew . getPathPostParametersAdd ( ) ) ;
// sent Request observe to Client
registrationIds . forEach ( registrationId - > {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getLwM2MClient ( null , registrationId ) ;
LeshanServer lwServer = lwM2MClient . getLwServer ( ) ;
Registration registration = lwM2mInMemorySecurityStore . getByRegistration ( registrationId ) ;
LeshanServer lwServer = leshanServer ;
Registration registration = lwM2mClientContext . getRegistration ( registrationId ) ;
this . readResourceValueObserve ( lwServer , registration , postObserveAnalyzer . getPathPostParametersAdd ( ) , GET_TYPE_OPER_OBSERVE ) ;
// 5.3 del
// sent Request cancel observe to Client
@ -914,11 +926,11 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
LwM2mPath pathIds = new LwM2mPath ( target ) ;
if ( pathIds . isResource ( ) ) {
if ( GET_TYPE_OPER_READ . equals ( typeOper ) ) {
lwM2M TransportRequest . sendAllRequest ( lwServer , registration , target , typeOper ,
ContentFormat . TLV . getName ( ) , null , null , this . context . getCtx Server ( ) . getTimeout ( ) ) ;
lwM2m TransportRequest . sendAllRequest ( lwServer , registration , target , typeOper ,
ContentFormat . TLV . getName ( ) , null , null , this . context . getLwM2MTransportConfig Server ( ) . getTimeout ( ) ) ;
} else if ( GET_TYPE_OPER_OBSERVE . equals ( typeOper ) ) {
lwM2M TransportRequest . sendAllRequest ( lwServer , registration , target , typeOper ,
null , null , null , this . context . getCtx Server ( ) . getTimeout ( ) ) ;
lwM2m TransportRequest . sendAllRequest ( lwServer , registration , target , typeOper ,
null , null , null , this . context . getLwM2MTransportConfig Server ( ) . getTimeout ( ) ) ;
}
}
} ) ;
@ -935,7 +947,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
}
private void cancelObserveIsValue ( LeshanServer lwServer , Registration registration , Set < String > paramAnallyzer ) {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getLwM2M ClientWithReg ( registration , null ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2m ClientWithReg ( registration , null ) ;
paramAnallyzer . forEach ( p - > {
if ( this . returnResourceValueFromLwM2MClient ( lwM2MClient , new LwM2mPath ( p ) ) ! = null ) {
this . setCancelObservationRecourse ( lwServer , registration , p ) ;
@ -944,10 +956,10 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
) ;
}
private void putDelayedUpdateResourcesClient ( LwM2M Client lwM2MClient , Object valueOld , Object valueNew , String path ) {
private void putDelayedUpdateResourcesClient ( LwM2m Client lwM2MClient , Object valueOld , Object valueNew , String path ) {
if ( valueNew ! = null & & ( valueOld = = null | | ! valueNew . toString ( ) . equals ( valueOld . toString ( ) ) ) ) {
lwM2M TransportRequest . sendAllRequest ( lwM2MClient . getLwServer ( ) , lwM2MClient . getRegistration ( ) , path , POST_TYPE_OPER_WRITE_REPLACE ,
ContentFormat . TLV . getName ( ) , null , valueNew , this . context . getCtx Server ( ) . getTimeout ( ) ) ;
lwM2m TransportRequest . sendAllRequest ( leshanServer , lwM2MClient . getRegistration ( ) , path , POST_TYPE_OPER_WRITE_REPLACE ,
ContentFormat . TLV . getName ( ) , null , valueNew , this . context . getLwM2MTransportConfig Server ( ) . getTimeout ( ) ) ;
} else {
log . error ( "05 delayError" ) ;
}
@ -982,7 +994,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @return -
* /
private String getPathAttributeUpdateProfile ( TransportProtos . SessionInfoProto sessionInfo , String name ) {
LwM2MClientProfile profile = lwM2mInMemorySecurityStore . getProfile ( new UUID ( sessionInfo . getDeviceProfileIdMSB ( ) , sessionInfo . getDeviceProfileIdLSB ( ) ) ) ;
LwM2mClientProfile profile = lwM2mClientContext . getProfile ( new UUID ( sessionInfo . getDeviceProfileIdMSB ( ) , sessionInfo . getDeviceProfileIdLSB ( ) ) ) ;
return profile . getPostKeyNameProfile ( ) . getAsJsonObject ( ) . entrySet ( ) . stream ( )
. filter ( e - > e . getValue ( ) . getAsString ( ) . equals ( name ) ) . findFirst ( ) . map ( Map . Entry : : getKey )
. orElse ( "" ) ;
@ -1002,7 +1014,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* /
public void onGetAttributesResponse ( TransportProtos . GetAttributeResponseMsg attributesResponse , TransportProtos . SessionInfoProto sessionInfo ) {
try {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getLwM2MClient ( sessionInfo ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2MClient ( sessionInfo ) ;
attributesResponse . getSharedAttributeListList ( ) . forEach ( attr - > {
String path = this . getPathAttributeUpdate ( sessionInfo , attr . getKv ( ) . getKey ( ) ) ;
// #1.1
@ -1027,18 +1039,18 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param lwM2MClient -
* @return
* /
private SessionInfoProto getNewSessionInfoProto ( LwM2M Client lwM2MClient ) {
private SessionInfoProto getNewSessionInfoProto ( LwM2m Client lwM2MClient ) {
if ( lwM2MClient ! = null ) {
TransportProtos . ValidateDeviceCredentialsResponseMsg msg = lwM2MClient . getCredentialsResponse ( ) ;
if ( msg = = null | | msg . getDeviceInfo ( ) = = null ) {
log . error ( "[{}] [{}]" , lwM2MClient . getEndP oint ( ) , CLIENT_NOT_AUTHORIZED ) ;
log . error ( "[{}] [{}]" , lwM2MClient . getEndp oint ( ) , CLIENT_NOT_AUTHORIZED ) ;
this . closeClientSession ( lwM2MClient . getRegistration ( ) ) ;
return null ;
} else {
return SessionInfoProto . newBuilder ( )
. setNodeId ( this . context . getNodeId ( ) )
. setSessionIdMSB ( lwM2MClient . getSessionUui d ( ) . getMostSignificantBits ( ) )
. setSessionIdLSB ( lwM2MClient . getSessionUui d ( ) . getLeastSignificantBits ( ) )
. setSessionIdMSB ( lwM2MClient . getSessionI d ( ) . getMostSignificantBits ( ) )
. setSessionIdLSB ( lwM2MClient . getSessionI d ( ) . getLeastSignificantBits ( ) )
. setDeviceIdMSB ( msg . getDeviceInfo ( ) . getDeviceIdMSB ( ) )
. setDeviceIdLSB ( msg . getDeviceInfo ( ) . getDeviceIdLSB ( ) )
. setTenantIdMSB ( msg . getDeviceInfo ( ) . getTenantIdMSB ( ) )
@ -1053,13 +1065,12 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
return null ;
}
/ * *
* @param registration - Registration LwM2M Client
* @return - sessionInfo after access connect client
* /
private SessionInfoProto getValidateSessionInfo ( Registration registration ) {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getLwM2M ClientWithReg ( registration , null ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2m ClientWithReg ( registration , null ) ;
return getNewSessionInfoProto ( lwM2MClient ) ;
}
@ -1068,7 +1079,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @return -
* /
private SessionInfoProto getValidateSessionInfo ( String registrationId ) {
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore . getLwM2M ClientWithReg ( null , registrationId ) ;
LwM2mClient lwM2MClient = lwM2mClientContext . getLwM2m ClientWithReg ( null , registrationId ) ;
return getNewSessionInfoProto ( lwM2MClient ) ;
}
@ -1079,12 +1090,12 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* /
private void checkInactivity ( SessionInfoProto sessionInfo ) {
if ( transportService . reportActivity ( sessionInfo ) = = null ) {
transportService . registerAsyncSession ( sessionInfo , new LwM2M SessionMsgListener ( this , sessionInfo ) ) ;
transportService . registerAsyncSession ( sessionInfo , new LwM2m SessionMsgListener ( this , sessionInfo ) ) ;
}
}
private void checkInactivityAndReportActivity ( ) {
lwM2mInMemorySecurityStore . getSession s ( ) . forEach ( ( key , value ) - > this . checkInactivity ( this . getValidateSessionInfo ( key ) ) ) ;
lwM2mClientContext . getLwM2mClient s ( ) . forEach ( ( key , value ) - > this . checkInactivity ( this . getValidateSessionInfo ( key ) ) ) ;
}
/ * *
@ -1095,7 +1106,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
*
* @param lwM2MClient - LwM2M Client
* /
public void putDelayedUpdateResourcesThingsboard ( LwM2M Client lwM2MClient ) {
public void putDelayedUpdateResourcesThingsboard ( LwM2m Client lwM2MClient ) {
SessionInfoProto sessionInfo = this . getValidateSessionInfo ( lwM2MClient . getRegistration ( ) ) ;
if ( sessionInfo ! = null ) {
//#1.1 + #1.2
@ -1119,15 +1130,16 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
* @param lwM2MClient -
* @return ArrayList keyNames from profile attr resources shared ! ! ! ! & & IsWritable
* /
private List < String > getNamesAttrFromProfileIsWritable ( LwM2M Client lwM2MClient ) {
LwM2MClientProfile profile = lwM2mInMemorySecurityStore . getProfile ( lwM2MClient . getProfileUui d ( ) ) ;
private List < String > getNamesAttrFromProfileIsWritable ( LwM2m Client lwM2MClient ) {
LwM2mClientProfile profile = lwM2mClientContext . getProfile ( lwM2MClient . getProfileI d ( ) ) ;
Set attrSet = new Gson ( ) . fromJson ( profile . getPostAttributeProfile ( ) , Set . class ) ;
ConcurrentMap < String , String > keyNamesMap = new Gson ( ) . fromJson ( profile . getPostKeyNameProfile ( ) . toString ( ) , new TypeToken < ConcurrentHashMap < String , String > > ( ) { } . getType ( ) ) ;
ConcurrentMap < String , String > keyNamesMap = new Gson ( ) . fromJson ( profile . getPostKeyNameProfile ( ) . toString ( ) , new TypeToken < ConcurrentHashMap < String , String > > ( ) {
} . getType ( ) ) ;
ConcurrentMap < String , String > keyNamesIsWritable = keyNamesMap . entrySet ( )
. stream ( )
. filter ( e - > ( attrSet . contains ( e . getKey ( ) ) & & context . getCtx Server ( ) . getResourceModel ( lwM2MClient . getRegistration ( ) , new LwM2mPath ( e . getKey ( ) ) ) ! = null & &
context . getCtx Server ( ) . getResourceModel ( lwM2MClient . getRegistration ( ) , new LwM2mPath ( e . getKey ( ) ) ) . operations . isWritable ( ) ) )
. filter ( e - > ( attrSet . contains ( e . getKey ( ) ) & & context . getLwM2MTransportConfig Server ( ) . getResourceModel ( lwM2MClient . getRegistration ( ) , new LwM2mPath ( e . getKey ( ) ) ) ! = null & &
context . getLwM2MTransportConfig Server ( ) . getResourceModel ( lwM2MClient . getRegistration ( ) , new LwM2mPath ( e . getKey ( ) ) ) . operations . isWritable ( ) ) )
. collect ( Collectors . toConcurrentMap ( Map . Entry : : getKey , Map . Entry : : getValue ) ) ;
Set < String > namesIsWritable = ConcurrentHashMap . newKeySet ( ) ;