Use the same device session info in transport service and in context
This commit is contained in:
		
							parent
							
								
									7834b92217
								
							
						
					
					
						commit
						63406b010f
					
				@ -706,7 +706,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onDeviceProfileUpdate(Device device) {
 | 
			
		||||
        deviceSessionCtx.onDeviceProfileUpdate(device);
 | 
			
		||||
    public void onDeviceProfileUpdate(Device device, TransportProtos.SessionInfoProto sessionInfo) {
 | 
			
		||||
        deviceSessionCtx.onDeviceProfileUpdate(device, sessionInfo);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,6 @@ import io.netty.channel.ChannelHandlerContext;
 | 
			
		||||
import lombok.Getter;
 | 
			
		||||
import lombok.Setter;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceTransportType;
 | 
			
		||||
import org.thingsboard.server.common.data.TransportPayloadType;
 | 
			
		||||
@ -114,11 +113,6 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext {
 | 
			
		||||
        updateTopicFilters(deviceProfile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onDeviceProfileUpdate(Device device) {
 | 
			
		||||
        super.onDeviceProfileUpdate(device);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void updateTopicFilters(DeviceProfile deviceProfile) {
 | 
			
		||||
        DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
 | 
			
		||||
        if (transportConfiguration.getType().equals(DeviceTransportType.MQTT) &&
 | 
			
		||||
 | 
			
		||||
@ -17,6 +17,7 @@ package org.thingsboard.server.common.transport;
 | 
			
		||||
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos.ToServerRpcResponseMsg;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeResponseMsg;
 | 
			
		||||
@ -41,6 +42,6 @@ public interface SessionMsgListener {
 | 
			
		||||
    default void onProfileUpdate(DeviceProfile deviceProfile) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    default void onDeviceProfileUpdate(Device device) {
 | 
			
		||||
    default void onDeviceProfileUpdate(Device device, TransportProtos.SessionInfoProto sessionInfo) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,7 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.common.transport;
 | 
			
		||||
 | 
			
		||||
import org.thingsboard.server.common.msg.session.SessionContext;
 | 
			
		||||
import org.thingsboard.server.common.transport.session.SessionContext;
 | 
			
		||||
 | 
			
		||||
public interface TransportAdaptor<C extends SessionContext, T, V> {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -684,14 +684,28 @@ public class DefaultTransportService implements TransportService {
 | 
			
		||||
        long deviceIdLSB = device.getId().getId().getLeastSignificantBits();
 | 
			
		||||
        long deviceProfileIdMSB = device.getDeviceProfileId().getId().getMostSignificantBits();
 | 
			
		||||
        long deviceProfileIdLSB = device.getDeviceProfileId().getId().getLeastSignificantBits();
 | 
			
		||||
        sessions.forEach((id, md) -> {
 | 
			
		||||
        for (Map.Entry<UUID, SessionMetaData> entry : sessions.entrySet()) {
 | 
			
		||||
            SessionMetaData md = entry.getValue();
 | 
			
		||||
            if ((md.getSessionInfo().getDeviceIdMSB() == deviceIdMSB
 | 
			
		||||
                    && md.getSessionInfo().getDeviceIdLSB() == deviceIdLSB)
 | 
			
		||||
                    && (md.getSessionInfo().getDeviceProfileIdMSB() != deviceProfileIdMSB
 | 
			
		||||
                    && md.getSessionInfo().getDeviceProfileIdLSB() != deviceProfileIdLSB)) {
 | 
			
		||||
                transportCallbackExecutor.submit(() -> md.getListener().onDeviceProfileUpdate(device));
 | 
			
		||||
                updateSessionMetadata(device, entry, md);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void updateSessionMetadata(Device device, Map.Entry<UUID, SessionMetaData> entry, SessionMetaData md) {
 | 
			
		||||
        TransportProtos.SessionInfoProto newSessionInfo = TransportProtos.SessionInfoProto.newBuilder()
 | 
			
		||||
                .mergeFrom(md.getSessionInfo())
 | 
			
		||||
                .setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setDeviceType(device.getType())
 | 
			
		||||
                .build();
 | 
			
		||||
        SessionMetaData newSessionMetaData = new SessionMetaData(newSessionInfo, md.getSessionType(), md.getListener());
 | 
			
		||||
        entry.setValue(newSessionMetaData);
 | 
			
		||||
        transportCallbackExecutor.submit(() -> newSessionMetaData.getListener().onDeviceProfileUpdate(device,
 | 
			
		||||
                newSessionMetaData.getSessionInfo()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected UUID toSessionId(TransportProtos.SessionInfoProto sessionInfo) {
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,6 @@ import lombok.Setter;
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
			
		||||
import org.thingsboard.server.common.msg.session.SessionContext;
 | 
			
		||||
import org.thingsboard.server.common.transport.auth.TransportDeviceInfo;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos;
 | 
			
		||||
 | 
			
		||||
@ -65,14 +64,10 @@ public abstract class DeviceAwareSessionContext implements SessionContext {
 | 
			
		||||
        this.sessionInfo = TransportProtos.SessionInfoProto.newBuilder().mergeFrom(sessionInfo).setDeviceType(deviceProfile.getName()).build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onDeviceProfileUpdate(Device device) {
 | 
			
		||||
    public void onDeviceProfileUpdate(Device device, TransportProtos.SessionInfoProto sessionInfo) {
 | 
			
		||||
        this.deviceInfo.setDeviceProfileId(device.getDeviceProfileId());
 | 
			
		||||
        this.deviceInfo.setDeviceType(device.getType());
 | 
			
		||||
        this.sessionInfo = TransportProtos.SessionInfoProto.newBuilder().mergeFrom(sessionInfo)
 | 
			
		||||
                .setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setDeviceType(device.getType())
 | 
			
		||||
                .build();
 | 
			
		||||
        this.sessionInfo = sessionInfo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isConnected() {
 | 
			
		||||
 | 
			
		||||
@ -13,10 +13,11 @@
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.common.msg.session;
 | 
			
		||||
package org.thingsboard.server.common.transport.session;
 | 
			
		||||
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
@ -28,5 +29,5 @@ public interface SessionContext {
 | 
			
		||||
 | 
			
		||||
    void onProfileUpdate(DeviceProfile deviceProfile);
 | 
			
		||||
 | 
			
		||||
    void onDeviceProfileUpdate(Device device);
 | 
			
		||||
    void onDeviceProfileUpdate(Device device, TransportProtos.SessionInfoProto sessionInfo);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user