Fixed merge
This commit is contained in:
@@ -209,8 +209,9 @@ public class ProtocolProcessor {
|
||||
byte[] willPayload = msg.getWillMessage();
|
||||
ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(willPayload.length).put(willPayload).flip();
|
||||
//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);
|
||||
LOG.info("Session for clientID <{}> with will to topic {}", msg.getClientID(), msg.getWillTopic());
|
||||
}
|
||||
|
||||
ConnAckMessage okResp = new ConnAckMessage();
|
||||
@@ -277,10 +278,10 @@ public class ProtocolProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public void processPubAck(Channel session, PubAckMessage msg) {
|
||||
String clientID = NettyUtils.clientID(session);
|
||||
public void processPubAck(Channel channel, PubAckMessage msg) {
|
||||
String clientID = NettyUtils.clientID(channel);
|
||||
int messageID = msg.getMessageID();
|
||||
String username = NettyUtils.userName(session);
|
||||
String username = NettyUtils.userName(channel);
|
||||
StoredMessage inflightMsg = m_sessionsStore.getInflightMessage(clientID, messageID);
|
||||
|
||||
//Remove the message from message store
|
||||
@@ -312,12 +313,12 @@ public class ProtocolProcessor {
|
||||
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);
|
||||
String clientID = NettyUtils.clientID(session);
|
||||
String clientID = NettyUtils.clientID(channel);
|
||||
final String topic = msg.getTopicName();
|
||||
//check if the topic can be wrote
|
||||
String username = NettyUtils.userName(session);
|
||||
String username = NettyUtils.userName(channel);
|
||||
if (!m_authorizator.canWrite(topic, username, clientID)) {
|
||||
LOG.debug("topic {} doesn't have write credentials", topic);
|
||||
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;
|
||||
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();
|
||||
pubMessage.setRetainFlag(retained);
|
||||
pubMessage.setTopicName(topic);
|
||||
@@ -484,22 +487,31 @@ public class ProtocolProcessor {
|
||||
pubMessage.setMessageID(messageID);
|
||||
} else {
|
||||
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) {
|
||||
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) {
|
||||
//TODO while we were publishing to the target client, that client disconnected,
|
||||
// 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;
|
||||
LOG.debug("Session for clientId {} is {}", clientId, channel);
|
||||
channel.writeAndFlush(pubMessage);
|
||||
LOG.trace("Session for clientId {}", clientId);
|
||||
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) {
|
||||
@@ -593,7 +605,8 @@ public class ProtocolProcessor {
|
||||
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);
|
||||
boolean cleanSession = NettyUtils.cleanSession(channel);
|
||||
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
|
||||
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore.searchMatching(new IMatchingCondition() {
|
||||
@Override
|
||||
public boolean match(String key) {
|
||||
public boolean match(String key) {
|
||||
return SubscriptionsStore.matchTopics(key, newSubscription.getTopicFilter());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user