|
|
@ -49,9 +49,6 @@ import java.util.concurrent.locks.Lock; |
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
import java.util.function.Consumer; |
|
|
import java.util.function.Consumer; |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @author Andrew Shvayka |
|
|
|
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { |
|
|
public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { |
|
|
|
|
|
|
|
|
@ -84,13 +81,18 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { |
|
|
private volatile MqttTopicFilter attributesSubscribeTopicFilter = MqttTopicFilterFactory.getDefaultAttributesFilter(); |
|
|
private volatile MqttTopicFilter attributesSubscribeTopicFilter = MqttTopicFilterFactory.getDefaultAttributesFilter(); |
|
|
@Getter |
|
|
@Getter |
|
|
private volatile TransportPayloadType payloadType = TransportPayloadType.JSON; |
|
|
private volatile TransportPayloadType payloadType = TransportPayloadType.JSON; |
|
|
|
|
|
@Getter |
|
|
private volatile Descriptors.Descriptor attributesDynamicMessageDescriptor; |
|
|
private volatile Descriptors.Descriptor attributesDynamicMessageDescriptor; |
|
|
|
|
|
@Getter |
|
|
private volatile Descriptors.Descriptor telemetryDynamicMessageDescriptor; |
|
|
private volatile Descriptors.Descriptor telemetryDynamicMessageDescriptor; |
|
|
|
|
|
@Getter |
|
|
private volatile Descriptors.Descriptor rpcResponseDynamicMessageDescriptor; |
|
|
private volatile Descriptors.Descriptor rpcResponseDynamicMessageDescriptor; |
|
|
|
|
|
@Getter |
|
|
private volatile DynamicMessage.Builder rpcRequestDynamicMessageBuilder; |
|
|
private volatile DynamicMessage.Builder rpcRequestDynamicMessageBuilder; |
|
|
private volatile MqttTransportAdaptor adaptor; |
|
|
private volatile MqttTransportAdaptor adaptor; |
|
|
private volatile boolean jsonPayloadFormatCompatibilityEnabled; |
|
|
private volatile boolean jsonPayloadFormatCompatibilityEnabled; |
|
|
private volatile boolean useJsonPayloadFormatForDefaultDownlinkTopics; |
|
|
private volatile boolean useJsonPayloadFormatForDefaultDownlinkTopics; |
|
|
|
|
|
@Getter |
|
|
private volatile boolean sendAckOnValidationException; |
|
|
private volatile boolean sendAckOnValidationException; |
|
|
|
|
|
|
|
|
@Getter |
|
|
@Getter |
|
|
@ -131,26 +133,6 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { |
|
|
return payloadType.equals(TransportPayloadType.JSON); |
|
|
return payloadType.equals(TransportPayloadType.JSON); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public boolean isSendAckOnValidationException() { |
|
|
|
|
|
return sendAckOnValidationException; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Descriptors.Descriptor getTelemetryDynamicMsgDescriptor() { |
|
|
|
|
|
return telemetryDynamicMessageDescriptor; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Descriptors.Descriptor getAttributesDynamicMessageDescriptor() { |
|
|
|
|
|
return attributesDynamicMessageDescriptor; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Descriptors.Descriptor getRpcResponseDynamicMessageDescriptor() { |
|
|
|
|
|
return rpcResponseDynamicMessageDescriptor; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DynamicMessage.Builder getRpcRequestDynamicMessageBuilder() { |
|
|
|
|
|
return rpcRequestDynamicMessageBuilder; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void setDeviceProfile(DeviceProfile deviceProfile) { |
|
|
public void setDeviceProfile(DeviceProfile deviceProfile) { |
|
|
super.setDeviceProfile(deviceProfile); |
|
|
super.setDeviceProfile(deviceProfile); |
|
|
@ -166,8 +148,7 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { |
|
|
private void updateDeviceSessionConfiguration(DeviceProfile deviceProfile) { |
|
|
private void updateDeviceSessionConfiguration(DeviceProfile deviceProfile) { |
|
|
DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); |
|
|
DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); |
|
|
if (transportConfiguration.getType().equals(DeviceTransportType.MQTT) && |
|
|
if (transportConfiguration.getType().equals(DeviceTransportType.MQTT) && |
|
|
transportConfiguration instanceof MqttDeviceProfileTransportConfiguration) { |
|
|
transportConfiguration instanceof MqttDeviceProfileTransportConfiguration mqttConfig) { |
|
|
MqttDeviceProfileTransportConfiguration mqttConfig = (MqttDeviceProfileTransportConfiguration) transportConfiguration; |
|
|
|
|
|
TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = mqttConfig.getTransportPayloadTypeConfiguration(); |
|
|
TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = mqttConfig.getTransportPayloadTypeConfiguration(); |
|
|
payloadType = transportPayloadTypeConfiguration.getTransportPayloadType(); |
|
|
payloadType = transportPayloadTypeConfiguration.getTransportPayloadType(); |
|
|
deviceProfileMqttTransportType = true; |
|
|
deviceProfileMqttTransportType = true; |
|
|
@ -199,16 +180,12 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public MqttTransportAdaptor getAdaptor(TopicType topicType) { |
|
|
public MqttTransportAdaptor getAdaptor(TopicType topicType) { |
|
|
switch (topicType) { |
|
|
return switch (topicType) { |
|
|
case V2: |
|
|
case V2 -> getDefaultAdaptor(); |
|
|
return getDefaultAdaptor(); |
|
|
case V2_JSON -> context.getJsonMqttAdaptor(); |
|
|
case V2_JSON: |
|
|
case V2_PROTO -> context.getProtoMqttAdaptor(); |
|
|
return context.getJsonMqttAdaptor(); |
|
|
default -> useJsonPayloadFormatForDefaultDownlinkTopics ? context.getJsonMqttAdaptor() : getDefaultAdaptor(); |
|
|
case V2_PROTO: |
|
|
}; |
|
|
return context.getProtoMqttAdaptor(); |
|
|
|
|
|
default: |
|
|
|
|
|
return useJsonPayloadFormatForDefaultDownlinkTopics ? context.getJsonMqttAdaptor() : getDefaultAdaptor(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private MqttTransportAdaptor getDefaultAdaptor() { |
|
|
private MqttTransportAdaptor getDefaultAdaptor() { |
|
|
@ -269,7 +246,7 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Collection<MqttMessage> getMsgQueueSnapshot(){ |
|
|
public Collection<MqttMessage> getMsgQueueSnapshot() { |
|
|
return Collections.unmodifiableCollection(msgQueue); |
|
|
return Collections.unmodifiableCollection(msgQueue); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|