Fixed NPE exception of inflight ACK because the publisher with clean=true removed all messages, also the published from message store
This commit is contained in:
@@ -43,6 +43,7 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
import io.netty.handler.timeout.IdleStateHandler;
|
import io.netty.handler.timeout.IdleStateHandler;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sun.misc.MessageUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible to handle the logic of MQTT protocol it's the director of
|
* Class responsible to handle the logic of MQTT protocol it's the director of
|
||||||
@@ -424,13 +425,16 @@ public class ProtocolProcessor {
|
|||||||
String username = NettyUtils.userName(channel);
|
String username = NettyUtils.userName(channel);
|
||||||
LOG.trace("retrieving inflight for messageID <{}>", messageID);
|
LOG.trace("retrieving inflight for messageID <{}>", messageID);
|
||||||
|
|
||||||
//Remove the message from message store
|
|
||||||
ClientSession targetSession = m_sessionsStore.sessionForClient(clientID);
|
ClientSession targetSession = m_sessionsStore.sessionForClient(clientID);
|
||||||
StoredMessage inflightMsg = targetSession.getInflightMessage(messageID);
|
StoredMessage inflightMsg = targetSession.getInflightMessage(messageID);
|
||||||
targetSession.inFlightAcknowledged(messageID);
|
targetSession.inFlightAcknowledged(messageID);
|
||||||
|
|
||||||
String topic = inflightMsg.getTopic();
|
String topic = inflightMsg.getTopic();
|
||||||
|
|
||||||
|
MessageGUID guid = inflightMsg.getGuid();
|
||||||
|
//Remove the message from message store
|
||||||
|
m_messagesStore.decUsageCounter(guid);
|
||||||
|
|
||||||
m_interceptor.notifyMessageAcknowledged(new InterceptAcknowledgedMessage(inflightMsg, topic, username));
|
m_interceptor.notifyMessageAcknowledged(new InterceptAcknowledgedMessage(inflightMsg, topic, username));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,9 +636,12 @@ public class ProtocolProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor.cleanSession) {
|
if (descriptor.cleanSession) {
|
||||||
LOG.debug("Removing messages in session for client <{}>", clientID);
|
LOG.debug("Removing messages in session's queue for client <{}>", clientID);
|
||||||
this.m_messagesStore.dropMessagesInSession(clientID);
|
Collection<MessageGUID> queue = this.m_sessionsStore.enqueued(clientID);
|
||||||
LOG.debug("Removed messages in session for client <{}>", clientID);
|
for (MessageGUID guid : queue) {
|
||||||
|
this.m_sessionsStore.removeEnqueued(clientID, guid);
|
||||||
|
}
|
||||||
|
LOG.debug("Removed messages in session for client's queue <{}>", clientID);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,9 +227,6 @@ class MapDBSessionsStore implements ISessionsStore {
|
|||||||
List<MessageGUID> guids = Utils.defaultGet(m_enqueuedStore, clientID, new ArrayList<MessageGUID>());
|
List<MessageGUID> guids = Utils.defaultGet(m_enqueuedStore, clientID, new ArrayList<MessageGUID>());
|
||||||
guids.remove(guid);
|
guids.remove(guid);
|
||||||
m_enqueuedStore.put(clientID, guids);
|
m_enqueuedStore.put(clientID, guids);
|
||||||
m_messagesStore.decUsageCounter(guid);
|
|
||||||
//if counter gets to 0 then remove from storage
|
|
||||||
m_messagesStore.removeStoredMessage(guid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class ServerIntegrationFuseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkWillTestamentIsPublishedOnConnectionKill_noRetain() throws Exception {
|
public void checkWillTestamentIsPublishedOnConnectionKill_noRetain() throws Exception {
|
||||||
LOG.info("checkWillTestamentIsPublishedOnConnectionKill");
|
LOG.info("checkWillTestamentIsPublishedOnConnectionKill_noRetain");
|
||||||
|
|
||||||
String willTestamentTopic = "/will/test";
|
String willTestamentTopic = "/will/test";
|
||||||
String willTestamentMsg = "Bye bye";
|
String willTestamentMsg = "Bye bye";
|
||||||
@@ -93,7 +93,6 @@ public class ServerIntegrationFuseTest {
|
|||||||
m_mqtt.setClientId("Subscriber");
|
m_mqtt.setClientId("Subscriber");
|
||||||
m_subscriber = m_mqtt.blockingConnection();
|
m_subscriber = m_mqtt.blockingConnection();
|
||||||
m_subscriber.connect();
|
m_subscriber.connect();
|
||||||
// Topic[] topics = new Topic[]{new Topic(willTestamentTopic, QoS.AT_LEAST_ONCE)};
|
|
||||||
Topic[] topics = new Topic[]{new Topic(willTestamentTopic, QoS.AT_MOST_ONCE)};
|
Topic[] topics = new Topic[]{new Topic(willTestamentTopic, QoS.AT_MOST_ONCE)};
|
||||||
m_subscriber.subscribe(topics);
|
m_subscriber.subscribe(topics);
|
||||||
|
|
||||||
|
|||||||
@@ -286,6 +286,7 @@ public class ServerIntegrationPahoTest {
|
|||||||
assertEquals("Hello MQTT", m_messagesCollector.getMessage(true).toString());
|
assertEquals("Hello MQTT", m_messagesCollector.getMessage(true).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession() throws Exception {
|
public void checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession() throws Exception {
|
||||||
LOG.info("*** checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession ***");
|
LOG.info("*** checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession ***");
|
||||||
@@ -461,10 +462,10 @@ public class ServerIntegrationPahoTest {
|
|||||||
clientForPublish.publish("topic", "Hello".getBytes(), 2, true);
|
clientForPublish.publish("topic", "Hello".getBytes(), 2, true);
|
||||||
|
|
||||||
//verify clientForSubscribe1 doesn't receive a notification but clientForSubscribe2 yes
|
//verify clientForSubscribe1 doesn't receive a notification but clientForSubscribe2 yes
|
||||||
System.out.println("Before waiting to receive 1 sec from " + clientForSubscribe1.getClientId());
|
LOG.info("Before waiting to receive 1 sec from " + clientForSubscribe1.getClientId());
|
||||||
assertFalse(clientForSubscribe1.isConnected());
|
assertFalse(clientForSubscribe1.isConnected());
|
||||||
assertTrue(clientForSubscribe2.isConnected());
|
assertTrue(clientForSubscribe2.isConnected());
|
||||||
System.out.println("Waiting to receive 1 sec from " + clientForSubscribe2.getClientId());
|
LOG.info("Waiting to receive 1 sec from " + clientForSubscribe2.getClientId());
|
||||||
MqttMessage messageOnB = cbSubscriber2.getMessage(true);
|
MqttMessage messageOnB = cbSubscriber2.getMessage(true);
|
||||||
assertEquals("Hello", new String(messageOnB.getPayload()));
|
assertEquals("Hello", new String(messageOnB.getPayload()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user