Moved the clientIDs map (ConnectionDescriptors cache) from SimpleMessaging to ProtocolProcessor
This commit is contained in:
+5
-4
@@ -1,6 +1,7 @@
|
|||||||
package org.dna.mqtt.moquette.messaging.spi.impl;
|
package org.dna.mqtt.moquette.messaging.spi.impl;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.dna.mqtt.moquette.messaging.spi.IMatchingCondition;
|
import org.dna.mqtt.moquette.messaging.spi.IMatchingCondition;
|
||||||
@@ -39,7 +40,7 @@ class ProtocolProcessor {
|
|||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ProtocolProcessor.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ProtocolProcessor.class);
|
||||||
|
|
||||||
private Map<String, ConnectionDescriptor> m_clientIDs;
|
private Map<String, ConnectionDescriptor> m_clientIDs = new HashMap<String, ConnectionDescriptor>();
|
||||||
private SubscriptionsStore subscriptions;
|
private SubscriptionsStore subscriptions;
|
||||||
private IStorageService m_storageService;
|
private IStorageService m_storageService;
|
||||||
private IAuthenticator m_authenticator;
|
private IAuthenticator m_authenticator;
|
||||||
@@ -48,9 +49,9 @@ class ProtocolProcessor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(Map<String, ConnectionDescriptor> clientIDs, SubscriptionsStore subscriptions,
|
void init(/*Map<String, ConnectionDescriptor> clientIDs, */SubscriptionsStore subscriptions,
|
||||||
IStorageService storageService) {
|
IStorageService storageService) {
|
||||||
m_clientIDs = clientIDs;
|
//m_clientIDs = clientIDs;
|
||||||
this.subscriptions = subscriptions;
|
this.subscriptions = subscriptions;
|
||||||
m_storageService = storageService;
|
m_storageService = storageService;
|
||||||
}
|
}
|
||||||
@@ -244,7 +245,7 @@ class ProtocolProcessor {
|
|||||||
}
|
}
|
||||||
LOG.debug("clientIDs are " + m_clientIDs);
|
LOG.debug("clientIDs are " + m_clientIDs);
|
||||||
if (m_clientIDs.get(clientId) == null) {
|
if (m_clientIDs.get(clientId) == null) {
|
||||||
throw new RuntimeException(String.format("Can't find a ConnectionDEwcriptor for client %s in cache %s", clientId, m_clientIDs));
|
throw new RuntimeException(String.format("Can't find a ConnectionDescriptor for client %s in cache %s", clientId, m_clientIDs));
|
||||||
}
|
}
|
||||||
LOG.debug("Session for clientId " + clientId + " is " + m_clientIDs.get(clientId).getSession());
|
LOG.debug("Session for clientId " + clientId + " is " + m_clientIDs.get(clientId).getSession());
|
||||||
m_clientIDs.get(clientId).getSession().write(pubMessage);
|
m_clientIDs.get(clientId).getSession().write(pubMessage);
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
|
|||||||
|
|
||||||
private IStorageService m_storageService;
|
private IStorageService m_storageService;
|
||||||
|
|
||||||
Map<String, ConnectionDescriptor> m_clientIDs = new HashMap<String, ConnectionDescriptor>();
|
|
||||||
|
|
||||||
private ExecutorService m_executor;
|
private ExecutorService m_executor;
|
||||||
BatchEventProcessor<ValueEvent> m_eventProcessor;
|
BatchEventProcessor<ValueEvent> m_eventProcessor;
|
||||||
|
|
||||||
@@ -166,7 +164,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
|
|||||||
m_storageService.initStore();
|
m_storageService.initStore();
|
||||||
|
|
||||||
subscriptions.init(m_storageService);
|
subscriptions.init(m_storageService);
|
||||||
m_processor.init(m_clientIDs, subscriptions, m_storageService);
|
m_processor.init(subscriptions, m_storageService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+16
-9
@@ -84,7 +84,7 @@ public class ProtocolProcessorTest {
|
|||||||
subscriptions = new SubscriptionsStore();
|
subscriptions = new SubscriptionsStore();
|
||||||
subscriptions.init(m_storageService);
|
subscriptions.init(m_storageService);
|
||||||
m_processor = new ProtocolProcessor();
|
m_processor = new ProtocolProcessor();
|
||||||
m_processor.init(new HashMap<String, ConnectionDescriptor>(), subscriptions, m_storageService);
|
m_processor.init(subscriptions, m_storageService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -143,13 +143,18 @@ public class ProtocolProcessorTest {
|
|||||||
throw new IllegalArgumentException("Expected " + FAKE_TOPIC + " buf found " + topic);
|
throw new IllegalArgumentException("Expected " + FAKE_TOPIC + " buf found " + topic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//simulate a connect that register a clientID to an IoSession
|
//simulate a connect that register a clientID to an IoSession
|
||||||
Map<String, ConnectionDescriptor> connectionsMap = new HashMap<String, ConnectionDescriptor>();
|
subs.init(m_storageService);
|
||||||
ConnectionDescriptor connDescr = new ConnectionDescriptor(FAKE_CLIENT_ID, m_session, subscription.isCleanSession());
|
m_processor.init(subs, m_storageService);
|
||||||
connectionsMap.put(FAKE_CLIENT_ID, connDescr);
|
ConnectMessage connectMessage = new ConnectMessage();
|
||||||
m_processor.init(connectionsMap, subs, m_storageService);
|
connectMessage.setProcotolVersion((byte)3);
|
||||||
|
connectMessage.setClientID(FAKE_CLIENT_ID);
|
||||||
|
connectMessage.setCleanSession(subscription.isCleanSession());
|
||||||
|
m_processor.processConnect(m_session, connectMessage);
|
||||||
|
|
||||||
|
|
||||||
//Exercise
|
//Exercise
|
||||||
@@ -236,10 +241,12 @@ public class ProtocolProcessorTest {
|
|||||||
subs.init(new MemoryStorageService());
|
subs.init(new MemoryStorageService());
|
||||||
|
|
||||||
//simulate a connect that register a clientID to an IoSession
|
//simulate a connect that register a clientID to an IoSession
|
||||||
Map<String, ConnectionDescriptor> connectionsMap = new HashMap<String, ConnectionDescriptor>();
|
m_processor.init(subs, m_storageService);
|
||||||
ConnectionDescriptor connDescr = new ConnectionDescriptor(FAKE_CLIENT_ID, m_session, subscription.isCleanSession());
|
ConnectMessage connectMessage = new ConnectMessage();
|
||||||
connectionsMap.put(FAKE_CLIENT_ID, connDescr);
|
connectMessage.setClientID(FAKE_CLIENT_ID);
|
||||||
m_processor.init(connectionsMap, subs, m_storageService);
|
connectMessage.setProcotolVersion((byte)3);
|
||||||
|
connectMessage.setCleanSession(subscription.isCleanSession());
|
||||||
|
m_processor.processConnect(m_session, connectMessage);
|
||||||
PublishEvent pubEvt = new PublishEvent(FAKE_TOPIC, AbstractMessage.QOSType.MOST_ONE, "Hello".getBytes(), true, "FakeCLI", null);
|
PublishEvent pubEvt = new PublishEvent(FAKE_TOPIC, AbstractMessage.QOSType.MOST_ONE, "Hello".getBytes(), true, "FakeCLI", null);
|
||||||
m_processor.processPublish(pubEvt);
|
m_processor.processPublish(pubEvt);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user