Fixed merge
This commit is contained in:
@@ -209,8 +209,9 @@ public class ProtocolProcessor {
|
|||||||
byte[] willPayload = msg.getWillMessage();
|
byte[] willPayload = msg.getWillMessage();
|
||||||
ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(willPayload.length).put(willPayload).flip();
|
ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(willPayload.length).put(willPayload).flip();
|
||||||
//save the will testament in the clientID store
|
//save the will testament in the clientID store
|
||||||
WillMessage will = new WillMessage(msg.getWillTopic(), bb, msg.isWillRetain(),willQos );
|
WillMessage will = new WillMessage(msg.getWillTopic(), bb, msg.isWillRetain(),willQos);
|
||||||
m_willStore.put(msg.getClientID(), will);
|
m_willStore.put(msg.getClientID(), will);
|
||||||
|
LOG.info("Session for clientID <{}> with will to topic {}", msg.getClientID(), msg.getWillTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnAckMessage okResp = new ConnAckMessage();
|
ConnAckMessage okResp = new ConnAckMessage();
|
||||||
@@ -277,10 +278,10 @@ public class ProtocolProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPubAck(Channel session, PubAckMessage msg) {
|
public void processPubAck(Channel channel, PubAckMessage msg) {
|
||||||
String clientID = NettyUtils.clientID(session);
|
String clientID = NettyUtils.clientID(channel);
|
||||||
int messageID = msg.getMessageID();
|
int messageID = msg.getMessageID();
|
||||||
String username = NettyUtils.userName(session);
|
String username = NettyUtils.userName(channel);
|
||||||
StoredMessage inflightMsg = m_sessionsStore.getInflightMessage(clientID, messageID);
|
StoredMessage inflightMsg = m_sessionsStore.getInflightMessage(clientID, messageID);
|
||||||
|
|
||||||
//Remove the message from message store
|
//Remove the message from message store
|
||||||
@@ -312,12 +313,12 @@ public class ProtocolProcessor {
|
|||||||
return pub;
|
return pub;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPublish(Channel session, PublishMessage msg) {
|
public void processPublish(Channel channel, PublishMessage msg) {
|
||||||
LOG.trace("PUB --PUBLISH--> SRV executePublish invoked with {}", msg);
|
LOG.trace("PUB --PUBLISH--> SRV executePublish invoked with {}", msg);
|
||||||
String clientID = NettyUtils.clientID(session);
|
String clientID = NettyUtils.clientID(channel);
|
||||||
final String topic = msg.getTopicName();
|
final String topic = msg.getTopicName();
|
||||||
//check if the topic can be wrote
|
//check if the topic can be wrote
|
||||||
String username = NettyUtils.userName(session);
|
String username = NettyUtils.userName(channel);
|
||||||
if (!m_authorizator.canWrite(topic, username, clientID)) {
|
if (!m_authorizator.canWrite(topic, username, clientID)) {
|
||||||
LOG.debug("topic {} doesn't have write credentials", topic);
|
LOG.debug("topic {} doesn't have write credentials", topic);
|
||||||
return;
|
return;
|
||||||
@@ -466,9 +467,11 @@ public class ProtocolProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void directSend(ClientSession clientsession, String topic, AbstractMessage.QOSType qos, ByteBuffer message, boolean retained, Integer messageID) {
|
protected void directSend(ClientSession clientsession, String topic, AbstractMessage.QOSType qos,
|
||||||
|
ByteBuffer message, boolean retained, Integer messageID) {
|
||||||
String clientId = clientsession.clientID;
|
String clientId = clientsession.clientID;
|
||||||
LOG.debug("directSend invoked clientId <{}> on topic <{}> QoS {} retained {} messageID {}", clientId, topic, qos, retained, messageID);
|
LOG.debug("directSend invoked clientId <{}> on topic <{}> QoS {} retained {} messageID {}",
|
||||||
|
clientId, topic, qos, retained, messageID);
|
||||||
PublishMessage pubMessage = new PublishMessage();
|
PublishMessage pubMessage = new PublishMessage();
|
||||||
pubMessage.setRetainFlag(retained);
|
pubMessage.setRetainFlag(retained);
|
||||||
pubMessage.setTopicName(topic);
|
pubMessage.setTopicName(topic);
|
||||||
@@ -484,22 +487,31 @@ public class ProtocolProcessor {
|
|||||||
pubMessage.setMessageID(messageID);
|
pubMessage.setMessageID(messageID);
|
||||||
} else {
|
} else {
|
||||||
if (messageID != null) {
|
if (messageID != null) {
|
||||||
throw new RuntimeException("Internal bad error, trying to forwardPublish a QoS 0 message with PacketIdentifier: " + messageID);
|
throw new RuntimeException("Internal bad error, trying to forwardPublish a QoS 0 message " +
|
||||||
|
"with PacketIdentifier: " + messageID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_clientIDs == null) {
|
if (m_clientIDs == null) {
|
||||||
throw new RuntimeException("Internal bad error, found m_clientIDs to null while it should be initialized, somewhere it's overwritten!!");
|
throw new RuntimeException("Internal bad error, found m_clientIDs to null while it should be " +
|
||||||
|
"initialized, somewhere it's overwritten!!");
|
||||||
}
|
}
|
||||||
LOG.debug("clientIDs are {}", m_clientIDs);
|
//LOG.trace("clientIDs are {}", m_clientIDs);
|
||||||
if (m_clientIDs.get(clientId) == null) {
|
if (m_clientIDs.get(clientId) == null) {
|
||||||
//TODO while we were publishing to the target client, that client disconnected,
|
//TODO while we were publishing to the target client, that client disconnected,
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
Channel channel = m_clientIDs.get(clientId).channel;
|
Channel channel = m_clientIDs.get(clientId).channel;
|
||||||
LOG.debug("Session for clientId {} is {}", clientId, channel);
|
LOG.trace("Session for clientId {}", clientId);
|
||||||
channel.writeAndFlush(pubMessage);
|
if (channel.isWritable()) {
|
||||||
|
//if channel is writable don't enqueue
|
||||||
|
channel.write(pubMessage);
|
||||||
|
} else {
|
||||||
|
//enqueue to the client session
|
||||||
|
clientsession.enqueue(pubMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPubRec(String clientID, int messageID) {
|
private void sendPubRec(String clientID, int messageID) {
|
||||||
@@ -593,7 +605,8 @@ public class ProtocolProcessor {
|
|||||||
m_interceptor.notifyMessageAcknowledged( new InterceptAcknowledgedMessage(inflightMsg, topic, username) );
|
m_interceptor.notifyMessageAcknowledged( new InterceptAcknowledgedMessage(inflightMsg, topic, username) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processDisconnect(Channel channel) {
|
public void processDisconnect(Channel channel) throws InterruptedException {
|
||||||
|
channel.flush();
|
||||||
String clientID = NettyUtils.clientID(channel);
|
String clientID = NettyUtils.clientID(channel);
|
||||||
boolean cleanSession = NettyUtils.cleanSession(channel);
|
boolean cleanSession = NettyUtils.cleanSession(channel);
|
||||||
LOG.info("DISCONNECT client <{}> with clean session {}", clientID, cleanSession);
|
LOG.info("DISCONNECT client <{}> with clean session {}", clientID, cleanSession);
|
||||||
@@ -714,7 +727,7 @@ public class ProtocolProcessor {
|
|||||||
//TODO this is ugly, it does a linear scan on potential big dataset
|
//TODO this is ugly, it does a linear scan on potential big dataset
|
||||||
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore.searchMatching(new IMatchingCondition() {
|
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore.searchMatching(new IMatchingCondition() {
|
||||||
@Override
|
@Override
|
||||||
public boolean match(String key) {
|
public boolean match(String key) {
|
||||||
return SubscriptionsStore.matchTopics(key, newSubscription.getTopicFilter());
|
return SubscriptionsStore.matchTopics(key, newSubscription.getTopicFilter());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user