Reintroduced bad removed conditions

This commit is contained in:
andsel
2016-12-13 23:43:02 +01:00
parent 105a06537c
commit 968e021711
@@ -50,39 +50,51 @@ class Qos1Publisher {
LOG.debug("Broker republishing to client <{}> topic <{}> qos <{}>, active {}", LOG.debug("Broker republishing to client <{}> topic <{}> qos <{}>, active {}",
sub.getClientId(), sub.getTopicFilter(), qos, targetIsActive); sub.getClientId(), sub.getTopicFilter(), qos, targetIsActive);
ByteBuffer message = origMessage.duplicate(); ByteBuffer message = origMessage.duplicate();
//QoS 1 or 2 if (qos == AbstractMessage.QOSType.MOST_ONE && targetIsActive) {
//if the target subscription is not clean session and is not connected => store it //QoS 0
if (!targetSession.isCleanSession() && !targetIsActive) { publishQos1(targetSession, topic, qos, message, false, null);
//store the message in targetSession queue to deliver } else {
targetSession.enqueueToDeliver(guid); //QoS 1 or 2
} else { //if the target subscription is not clean session and is not connected => store it
//publish if (!targetSession.isCleanSession() && !targetIsActive) {
if (targetIsActive) { //store the message in targetSession queue to deliver
int messageId = targetSession.nextPacketId(); targetSession.enqueueToDeliver(guid);
targetSession.inFlightAckWaiting(guid, messageId); } else {
publishQos1(targetSession, topic, message, messageId, qos); //publish
if (targetIsActive) {
int messageId = targetSession.nextPacketId();
targetSession.inFlightAckWaiting(guid, messageId);
publishQos1(targetSession, topic, qos, message, false, messageId);
}
} }
} }
} }
} }
private void publishQos1(ClientSession clientsession, String topic, private void publishQos1(ClientSession clientsession, String topic, AbstractMessage.QOSType qos,
ByteBuffer message, int messageID, AbstractMessage.QOSType qos) { ByteBuffer message, boolean retained, Integer messageID) {
String clientId = clientsession.clientID; String clientId = clientsession.clientID;
LOG.debug("publishQos1 invoked clientId <{}> on topic <{}> QoS {} retained {} messageID {}", LOG.debug("directSend invoked clientId <{}> on topic <{}> QoS {} retained {} messageID {}",
clientId, topic, qos, false, messageID); clientId, topic, qos, retained, messageID);
PublishMessage pubMessage = new PublishMessage(); PublishMessage pubMessage = new PublishMessage();
pubMessage.setRetainFlag(false); pubMessage.setRetainFlag(retained);
pubMessage.setTopicName(topic); pubMessage.setTopicName(topic);
pubMessage.setQos(qos); pubMessage.setQos(qos);
pubMessage.setPayload(message); pubMessage.setPayload(message);
//QoS > 0 => set the PacketIdentifier
pubMessage.setMessageID(messageID);
LOG.info("send publish message to <{}> on topic <{}>", clientId, topic); LOG.info("send publish message to <{}> on topic <{}>", clientId, topic);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("content <{}>", DebugUtils.payload2Str(message)); LOG.debug("content <{}>", DebugUtils.payload2Str(message));
} }
//set the PacketIdentifier only for QoS > 0
if (pubMessage.getQos() != AbstractMessage.QOSType.MOST_ONE) {
pubMessage.setMessageID(messageID);
} else {
if (messageID != null) {
throw new RuntimeException("Internal bad error, trying to forwardPublish a QoS 0 message " +
"with PacketIdentifier: " + messageID);
}
}
if (connectionDescriptors == null) { if (connectionDescriptors == null) {
throw new RuntimeException("Internal bad error, found connectionDescriptors to null while it should be " + throw new RuntimeException("Internal bad error, found connectionDescriptors to null while it should be " +