Browse Source

Lwm2m: backEnd: add to updateReg new registerAsyncSession

pull/3980/head
nickAS21 6 years ago
parent
commit
02615cb93d
  1. 2
      application/src/main/resources/thingsboard.yml
  2. 23
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportService.java
  3. 4
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/TransportService.java
  4. 4
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java
  5. 1
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/SessionMetaData.java

2
application/src/main/resources/thingsboard.yml

@ -433,7 +433,7 @@ spring:
database-platform: "${SPRING_JPA_DATABASE_PLATFORM:org.hibernate.dialect.PostgreSQLDialect}"
datasource:
driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}"
url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard_ce_3_3_test}"
url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}"
username: "${SPRING_DATASOURCE_USERNAME:postgres}"
password: "${SPRING_DATASOURCE_PASSWORD:postgres}"
hikari:

23
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportService.java

@ -177,6 +177,7 @@ public class LwM2MTransportService {
}
/**
* if sessionInfo removed from sessions, then new registerAsyncSession
* @param lwServer - LeshanServer
* @param registration - Registration LwM2M Client
*/
@ -185,8 +186,7 @@ public class LwM2MTransportService {
try {
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration.getId());
if (sessionInfo != null) {
// transportService.reportActivity(sessionInfo);
// transportService.registerAsyncSession(sessionInfo, new LwM2MSessionMsgListener(this, sessionInfo));
this.checkInactivity(sessionInfo);
log.info("Client: [{}] updatedReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType());
} else {
log.error("Client: [{}] updatedReg [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
@ -197,6 +197,7 @@ public class LwM2MTransportService {
});
}
/**
* @param registration - Registration LwM2M Client
* @param observations - All paths observations before unReg
@ -691,11 +692,11 @@ public class LwM2MTransportService {
ResourceValue resValueOld = lwM2MClient.getResources().get(path);
// #2
if (resValueOld.isMultiInstances() && !values.toString().equals(resValueOld.getResourceValue().toString())) {
ResourceValue resourceValue = new ResourceValue ( values, null, true);
ResourceValue resourceValue = new ResourceValue(values, null, true);
lwM2MClient.getResources().put(path, resourceValue);
isChange = true;
} else if (!LwM2MTransportHandler.equalsResourceValue(resValueOld.getValue(), value, resModelType, pathIds)) {
ResourceValue resourceValue = new ResourceValue ( null, value, false);
ResourceValue resourceValue = new ResourceValue(null, value, false);
lwM2MClient.getResources().put(path, resourceValue);
isChange = true;
}
@ -739,7 +740,7 @@ public class LwM2MTransportService {
String value = de.getValue().getAsString();
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getSession(new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB())).entrySet().iterator().next().getValue();
AttrTelemetryObserveValue profile = lwM2mInMemorySecurityStore.getProfile(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
ResourceModel resourceModel = context.getCtxServer().getResourceModel(new LwM2mPath(path));
ResourceModel resourceModel = context.getCtxServer().getResourceModel(new LwM2mPath(path));
if (path != null && (this.validatePathInAttrProfile(profile, path) || this.validatePathInTelemetryProfile(profile, path))) {
if (resourceModel != null && resourceModel.operations.isWritable()) {
lwM2MTransportRequest.sendAllRequest(lwM2MClient.getLwServer(), lwM2MClient.getRegistration(), path, POST_TYPE_OPER_WRITE_REPLACE,
@ -1125,7 +1126,17 @@ public class LwM2MTransportService {
}
private void checkInactivityAndReportActivity() {
lwM2mInMemorySecurityStore.getSessions().forEach((key, value) -> transportService.reportActivity(this.getValidateSessionInfo(key)));
lwM2mInMemorySecurityStore.getSessions().forEach((key, value) -> this.checkInactivity(this.getValidateSessionInfo(key)));
}
/**
* if sessionInfo removed from sessions, then new registerAsyncSession
* @param sessionInfo
*/
private void checkInactivity(SessionInfoProto sessionInfo) {
if (transportService.reportActivity(sessionInfo) == null) {
transportService.registerAsyncSession(sessionInfo, new LwM2MSessionMsgListener(this, sessionInfo));
}
}
public void sentLogsToThingsboard(String msg, String registrationId) {

4
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/TransportService.java

@ -19,7 +19,7 @@ import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse;
import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse;
import org.thingsboard.server.gen.transport.TransportProtos;
import org.thingsboard.server.common.transport.service.SessionMetaData;
import org.thingsboard.server.gen.transport.TransportProtos.ClaimDeviceMsg;
import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg;
import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg;
@ -98,7 +98,7 @@ public interface TransportService {
void registerSyncSession(SessionInfoProto sessionInfo, SessionMsgListener listener, long timeout);
void reportActivity(SessionInfoProto sessionInfo);
SessionMetaData reportActivity(SessionInfoProto sessionInfo);
void deregisterSession(SessionInfoProto sessionInfo);
}

4
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java

@ -509,8 +509,8 @@ public class DefaultTransportService implements TransportService {
}
@Override
public void reportActivity(TransportProtos.SessionInfoProto sessionInfo) {
reportActivityInternal(sessionInfo);
public SessionMetaData reportActivity(TransportProtos.SessionInfoProto sessionInfo) {
return reportActivityInternal(sessionInfo);
}
private SessionMetaData reportActivityInternal(TransportProtos.SessionInfoProto sessionInfo) {

1
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/SessionMetaData.java

@ -25,6 +25,7 @@ import java.util.concurrent.ScheduledFuture;
* Created by ashvayka on 15.10.18.
*/
@Data
public
class SessionMetaData {
private volatile TransportProtos.SessionInfoProto sessionInfo;

Loading…
Cancel
Save