Fixed bad qos publish, issue #56

This commit is contained in:
andrea
2015-06-28 19:53:22 +02:00
parent b8af814940
commit ac2eb6dce0
5 changed files with 89 additions and 27 deletions
@@ -34,13 +34,13 @@ import static org.eclipse.moquette.spi.impl.Utils.defaultGet;
*/
public class MemoryStorageService implements IMessagesStore, ISessionsStore {
private Map<String, Set<Subscription>> m_persistentSubscriptions = new HashMap<String, Set<Subscription>>();
private Map<String, StoredMessage> m_retainedStore = new HashMap<String, StoredMessage>();
private Map<String, Set<Subscription>> m_persistentSubscriptions = new HashMap<>();
private Map<String, StoredMessage> m_retainedStore = new HashMap<>();
//TODO move in a multimap because only Qos1 and QoS2 are stored here and they have messageID(key of secondary map)
private Map<String, List<PublishEvent>> m_persistentMessageStore = new HashMap<String, List<PublishEvent>>();
private Map<String, PublishEvent> m_inflightStore = new HashMap<String, PublishEvent>();
private Map<String, List<PublishEvent>> m_persistentMessageStore = new HashMap<>();
private Map<String, PublishEvent> m_inflightStore = new HashMap<>();
private Map<String, Set<Integer>> m_inflightIDs = new HashMap<>();
private Map<String, PublishEvent> m_qos2Store = new HashMap<String, PublishEvent>();
private Map<String, PublishEvent> m_qos2Store = new HashMap<>();
private static final Logger LOG = LoggerFactory.getLogger(MemoryStorageService.class);
@@ -221,25 +221,6 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
m_willStore.put(msg.getClientID(), will);
}
// //handle user authentication
// if (msg.isUserFlag()) {
// String pwd = null;
// if (msg.isPasswordFlag()) {
// pwd = msg.getPassword();
// } else if (!this.allowAnonymous) {
// failedCredentials(session);
// return;
// }
// if (!m_authenticator.checkValid(msg.getUsername(), pwd)) {
// failedCredentials(session);
// return;
// }
// session.setAttribute(NettyChannel.ATTR_KEY_USERNAME, msg.getUsername());
// } else if (!this.allowAnonymous) {
// failedCredentials(session);
// return;
// }
subscriptions.activate(msg.getClientID());
//handle clean session flag
@@ -381,9 +362,9 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
/**
* Flood the subscribers with the message to notify. MessageID is optional and should only used for QoS 1 and 2
* */
private void forward2Subscribers(PublishEvent pubEvt) {
void forward2Subscribers(PublishEvent pubEvt) {
final String topic = pubEvt.getTopic();
AbstractMessage.QOSType qos = pubEvt.getQos();
final AbstractMessage.QOSType publishingQos = pubEvt.getQos();
final ByteBuffer origMessage = pubEvt.getMessage();
boolean retain = pubEvt.isRetain();
final Integer messageID = pubEvt.getMessageID();
@@ -393,6 +374,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
LOG.debug("subscription tree {}", subscriptions.dumpTree());
}
for (final Subscription sub : subscriptions.matches(topic)) {
AbstractMessage.QOSType qos = publishingQos;
if (qos.ordinal() > sub.getRequestedQos().ordinal()) {
qos = sub.getRequestedQos();
}
@@ -428,7 +410,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
}
}
private void sendPublish(String clientId, String topic, AbstractMessage.QOSType qos, ByteBuffer message, boolean retained, Integer messageID) {
protected void sendPublish(String clientId, String topic, AbstractMessage.QOSType qos, ByteBuffer message, boolean retained, Integer messageID) {
LOG.debug("sendPublish invoked clientId <{}> on topic <{}> QoS {} retained {} messageID {}", clientId, topic, qos, retained, messageID);
PublishMessage pubMessage = new PublishMessage();
pubMessage.setRetainFlag(retained);