Minor changes, refactored ConnectionDescriptor to be an immutable object
This commit is contained in:
@@ -16,38 +16,26 @@
|
|||||||
package org.eclipse.moquette.server;
|
package org.eclipse.moquette.server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maintains the information of single connection, like ClientID, IoSession,
|
* Value object to maintain the information of single connection, like ClientID, IoSession,
|
||||||
* and other connection related flags.
|
* and other clean session fla.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author andrea
|
* @author andrea
|
||||||
*/
|
*/
|
||||||
public class ConnectionDescriptor {
|
public class ConnectionDescriptor {
|
||||||
|
|
||||||
private String m_clientID;
|
public final String clientID;
|
||||||
private ServerChannel m_session;
|
public final ServerChannel session;
|
||||||
private boolean m_cleanSession;
|
public final boolean cleanSession;
|
||||||
|
|
||||||
public ConnectionDescriptor(String clientID, ServerChannel session, boolean cleanSession) {
|
public ConnectionDescriptor(String clientID, ServerChannel session, boolean cleanSession) {
|
||||||
this.m_clientID = clientID;
|
this.clientID = clientID;
|
||||||
this.m_session = session;
|
this.session = session;
|
||||||
this.m_cleanSession = cleanSession;
|
this.cleanSession = cleanSession;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCleanSession() {
|
|
||||||
return m_cleanSession;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getClientID() {
|
|
||||||
return m_clientID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerChannel getSession() {
|
|
||||||
return m_session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ConnectionDescriptor{" + "m_clientID=" + m_clientID + ", m_cleanSession=" + m_cleanSession + '}';
|
return "ConnectionDescriptor{" + "clientID=" + clientID + ", cleanSession=" + cleanSession + '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class ClientSession {
|
|||||||
* Remove a message previously stored for delivery.
|
* Remove a message previously stored for delivery.
|
||||||
* */
|
* */
|
||||||
public void removeDelivered(int messageID) {
|
public void removeDelivered(int messageID) {
|
||||||
messagesStore.removeMessageInSession(clientID, messageID);
|
messagesStore.removeMessage(clientID, messageID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public interface IMessagesStore {
|
|||||||
*/
|
*/
|
||||||
List<PublishEvent> listMessagesInSession(String clientID);
|
List<PublishEvent> listMessagesInSession(String clientID);
|
||||||
|
|
||||||
void removeMessageInSession(String clientID, Integer packetID);
|
void removeMessage(String clientID, Integer packetID);
|
||||||
|
|
||||||
void dropMessagesInSession(String clientID);
|
void dropMessagesInSession(String clientID);
|
||||||
|
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ public class ProtocolProcessor {
|
|||||||
if (m_clientIDs.containsKey(msg.getClientID())) {
|
if (m_clientIDs.containsKey(msg.getClientID())) {
|
||||||
LOG.info("Found an existing connection with same client ID <{}>, forcing to close", msg.getClientID());
|
LOG.info("Found an existing connection with same client ID <{}>, forcing to close", msg.getClientID());
|
||||||
//clean the subscriptions if the old used a cleanSession = true
|
//clean the subscriptions if the old used a cleanSession = true
|
||||||
ServerChannel oldSession = m_clientIDs.get(msg.getClientID()).getSession();
|
ServerChannel oldSession = m_clientIDs.get(msg.getClientID()).session;
|
||||||
ClientSession oldClientSession = m_sessionsStore.sessionForClient(msg.getClientID());
|
ClientSession oldClientSession = m_sessionsStore.sessionForClient(msg.getClientID());
|
||||||
oldClientSession.disconnect();
|
oldClientSession.disconnect();
|
||||||
oldSession.setAttribute(NettyChannel.ATTR_KEY_SESSION_STOLEN, true);
|
oldSession.setAttribute(NettyChannel.ATTR_KEY_SESSION_STOLEN, true);
|
||||||
@@ -263,7 +263,7 @@ public class ProtocolProcessor {
|
|||||||
String clientID = (String) session.getAttribute(NettyChannel.ATTR_KEY_CLIENTID);
|
String clientID = (String) session.getAttribute(NettyChannel.ATTR_KEY_CLIENTID);
|
||||||
int messageID = msg.getMessageID();
|
int messageID = msg.getMessageID();
|
||||||
//Remove the message from message store
|
//Remove the message from message store
|
||||||
m_messagesStore.removeMessageInSession(clientID, messageID);
|
m_messagesStore.removeMessage(clientID, messageID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPublish(ServerChannel session, PublishMessage msg) {
|
public void processPublish(ServerChannel session, PublishMessage msg) {
|
||||||
@@ -416,7 +416,7 @@ public class ProtocolProcessor {
|
|||||||
// could happen is not an error HANDLE IT
|
// could happen is not an error HANDLE IT
|
||||||
throw new RuntimeException(String.format("Can't find a ConnectionDescriptor 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));
|
||||||
}
|
}
|
||||||
ServerChannel session = m_clientIDs.get(clientId).getSession();
|
ServerChannel session = m_clientIDs.get(clientId).session;
|
||||||
LOG.debug("Session for clientId {} is {}", clientId, session);
|
LOG.debug("Session for clientId {} is {}", clientId, session);
|
||||||
|
|
||||||
String user = (String) session.getAttribute(NettyChannel.ATTR_KEY_USERNAME);
|
String user = (String) session.getAttribute(NettyChannel.ATTR_KEY_USERNAME);
|
||||||
@@ -431,7 +431,7 @@ public class ProtocolProcessor {
|
|||||||
LOG.trace("PUB <--PUBREC-- SRV sendPubRec invoked for clientID {} with messageID {}", clientID, messageID);
|
LOG.trace("PUB <--PUBREC-- SRV sendPubRec invoked for clientID {} with messageID {}", clientID, messageID);
|
||||||
PubRecMessage pubRecMessage = new PubRecMessage();
|
PubRecMessage pubRecMessage = new PubRecMessage();
|
||||||
pubRecMessage.setMessageID(messageID);
|
pubRecMessage.setMessageID(messageID);
|
||||||
m_clientIDs.get(clientID).getSession().write(pubRecMessage);
|
m_clientIDs.get(clientID).session.write(pubRecMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPubAck(PubAckEvent evt) {
|
private void sendPubAck(PubAckEvent evt) {
|
||||||
@@ -448,7 +448,7 @@ public class ProtocolProcessor {
|
|||||||
if (m_clientIDs.get(clientId) == null) {
|
if (m_clientIDs.get(clientId) == null) {
|
||||||
throw new RuntimeException(String.format("Can't find a ConnectionDescriptor 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));
|
||||||
}
|
}
|
||||||
m_clientIDs.get(clientId).getSession().write(pubAckMessage);
|
m_clientIDs.get(clientId).session.write(pubAckMessage);
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
LOG.error(null, t);
|
LOG.error(null, t);
|
||||||
}
|
}
|
||||||
@@ -481,7 +481,7 @@ public class ProtocolProcessor {
|
|||||||
PubCompMessage pubCompMessage = new PubCompMessage();
|
PubCompMessage pubCompMessage = new PubCompMessage();
|
||||||
pubCompMessage.setMessageID(messageID);
|
pubCompMessage.setMessageID(messageID);
|
||||||
|
|
||||||
m_clientIDs.get(clientID).getSession().write(pubCompMessage);
|
m_clientIDs.get(clientID).session.write(pubCompMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPubRec(ServerChannel session, PubRecMessage msg) {
|
public void processPubRec(ServerChannel session, PubRecMessage msg) {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class PublishEvent extends MessagingEvent {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "PublishEvent{" +
|
return "PublishEvent{" +
|
||||||
"m_msgID=" + m_msgID +
|
"m_msgID=" + m_msgID +
|
||||||
", m_clientID='" + m_clientID + '\'' +
|
", clientID='" + m_clientID + '\'' +
|
||||||
", m_retain=" + m_retain +
|
", m_retain=" + m_retain +
|
||||||
", m_qos=" + m_qos +
|
", m_qos=" + m_qos +
|
||||||
", m_topic='" + m_topic + '\'' +
|
", m_topic='" + m_topic + '\'' +
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMessageInSession(String clientID, Integer messageID) {
|
public void removeMessage(String clientID, Integer messageID) {
|
||||||
List<StoredPublishEvent> events = m_persistentMessageStore.get(clientID);
|
List<StoredPublishEvent> events = m_persistentMessageStore.get(clientID);
|
||||||
if (events == null) {
|
if (events == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class MemoryStorageService implements IMessagesStore, ISessionsStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMessageInSession(String clientID, Integer messageID) {
|
public void removeMessage(String clientID, Integer messageID) {
|
||||||
List<PublishEvent> events = m_persistentMessageStore.get(clientID);
|
List<PublishEvent> events = m_persistentMessageStore.get(clientID);
|
||||||
if (events == null) {
|
if (events == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user