Minor, just code layout

This commit is contained in:
andsel
2017-03-20 21:58:18 +01:00
parent 22b1fa2b0e
commit c659a54158
@@ -19,7 +19,6 @@ package io.moquette.spi.impl;
import io.moquette.interception.InterceptHandler; import io.moquette.interception.InterceptHandler;
import io.moquette.interception.messages.InterceptAcknowledgedMessage; import io.moquette.interception.messages.InterceptAcknowledgedMessage;
import io.moquette.server.ConnectionDescriptor; import io.moquette.server.ConnectionDescriptor;
import io.moquette.server.ConnectionDescriptor.ConnectionState;
import io.moquette.server.ConnectionDescriptorStore; import io.moquette.server.ConnectionDescriptorStore;
import io.moquette.server.netty.NettyUtils; import io.moquette.server.netty.NettyUtils;
import io.moquette.spi.*; import io.moquette.spi.*;
@@ -50,6 +49,7 @@ import static io.moquette.spi.impl.Utils.readBytesAndRewind;
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*; import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
import static io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader.from; import static io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader.from;
import static io.netty.handler.codec.mqtt.MqttQoS.*; import static io.netty.handler.codec.mqtt.MqttQoS.*;
import static io.moquette.server.ConnectionDescriptor.ConnectionState.*;
/** /**
* Class responsible to handle the logic of MQTT protocol it's the director of the protocol * Class responsible to handle the logic of MQTT protocol it's the director of the protocol
@@ -160,47 +160,22 @@ public class ProtocolProcessor {
public void init(SubscriptionsStore subscriptions, IMessagesStore storageService, ISessionsStore sessionsStore, public void init(SubscriptionsStore subscriptions, IMessagesStore storageService, ISessionsStore sessionsStore,
IAuthenticator authenticator, boolean allowAnonymous, IAuthorizator authorizator, IAuthenticator authenticator, boolean allowAnonymous, IAuthorizator authorizator,
BrokerInterceptor interceptor) { BrokerInterceptor interceptor) {
init( init(subscriptions, storageService, sessionsStore, authenticator, allowAnonymous, false, authorizator,
subscriptions, interceptor, null);
storageService,
sessionsStore,
authenticator,
allowAnonymous,
false,
authorizator,
interceptor,
null);
} }
public void init(SubscriptionsStore subscriptions, IMessagesStore storageService, ISessionsStore sessionsStore, public void init(SubscriptionsStore subscriptions, IMessagesStore storageService, ISessionsStore sessionsStore,
IAuthenticator authenticator, boolean allowAnonymous, boolean allowZeroByteClientId, IAuthenticator authenticator, boolean allowAnonymous, boolean allowZeroByteClientId,
IAuthorizator authorizator, BrokerInterceptor interceptor) { IAuthorizator authorizator, BrokerInterceptor interceptor) {
init( init(subscriptions, storageService, sessionsStore, authenticator, allowAnonymous, allowZeroByteClientId,
subscriptions, authorizator, interceptor, null);
storageService,
sessionsStore,
authenticator,
allowAnonymous,
allowZeroByteClientId,
authorizator,
interceptor,
null);
} }
public void init(SubscriptionsStore subscriptions, IMessagesStore storageService, ISessionsStore sessionsStore, public void init(SubscriptionsStore subscriptions, IMessagesStore storageService, ISessionsStore sessionsStore,
IAuthenticator authenticator, boolean allowAnonymous, boolean allowZeroByteClientId, IAuthenticator authenticator, boolean allowAnonymous, boolean allowZeroByteClientId,
IAuthorizator authorizator, BrokerInterceptor interceptor, String serverPort) { IAuthorizator authorizator, BrokerInterceptor interceptor, String serverPort) {
init( init(new ConnectionDescriptorStore(sessionsStore), subscriptions, storageService, sessionsStore, authenticator,
new ConnectionDescriptorStore(sessionsStore), allowAnonymous, allowZeroByteClientId, authorizator, interceptor, serverPort);
subscriptions,
storageService,
sessionsStore,
authenticator,
allowAnonymous,
allowZeroByteClientId,
authorizator,
interceptor,
serverPort);
} }
/** /**
@@ -243,36 +218,16 @@ public class ProtocolProcessor {
LOG.info("Initializing messages publisher..."); LOG.info("Initializing messages publisher...");
final PersistentQueueMessageSender messageSender = new PersistentQueueMessageSender(this.connectionDescriptors); final PersistentQueueMessageSender messageSender = new PersistentQueueMessageSender(this.connectionDescriptors);
this.messagesPublisher = new MessagesPublisher( this.messagesPublisher = new MessagesPublisher(connectionDescriptors, sessionsStore, m_messagesStore,
connectionDescriptors,
sessionsStore,
m_messagesStore,
messageSender); messageSender);
LOG.info("Initializing QoS publish handlers..."); LOG.info("Initializing QoS publish handlers...");
this.qos0PublishHandler = new Qos0PublishHandler( this.qos0PublishHandler = new Qos0PublishHandler(m_authorizator, subscriptions, m_messagesStore, m_interceptor,
m_authorizator,
subscriptions,
m_messagesStore,
m_interceptor,
this.messagesPublisher);
this.qos1PublishHandler = new Qos1PublishHandler(
m_authorizator,
subscriptions,
m_messagesStore,
m_interceptor,
this.connectionDescriptors,
m_server_port,
this.messagesPublisher);
this.qos2PublishHandler = new Qos2PublishHandler(
m_authorizator,
subscriptions,
m_messagesStore,
m_interceptor,
this.connectionDescriptors,
m_sessionsStore,
m_server_port,
this.messagesPublisher); this.messagesPublisher);
this.qos1PublishHandler = new Qos1PublishHandler(m_authorizator, subscriptions, m_messagesStore, m_interceptor,
this.connectionDescriptors, m_server_port, this.messagesPublisher);
this.qos2PublishHandler = new Qos2PublishHandler(m_authorizator, subscriptions, m_messagesStore, m_interceptor,
this.connectionDescriptors, m_sessionsStore, m_server_port, this.messagesPublisher);
LOG.info("Initializing internal republisher..."); LOG.info("Initializing internal republisher...");
this.internalRepublisher = new InternalRepublisher(messageSender); this.internalRepublisher = new InternalRepublisher(messageSender);
@@ -287,7 +242,7 @@ public class ProtocolProcessor {
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()) { && msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()) {
MqttConnAckMessage badProto = connAck(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION); MqttConnAckMessage badProto = connAck(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION);
LOG.error("The MQTT protocol version is not valid. CId = {}", clientId); LOG.error("MQTT protocol version is not valid. CId={}", clientId);
channel.writeAndFlush(badProto); channel.writeAndFlush(badProto);
channel.close(); channel.close();
return; return;
@@ -305,9 +260,7 @@ public class ProtocolProcessor {
// Generating client id. // Generating client id.
clientId = UUID.randomUUID().toString().replace("-", ""); clientId = UUID.randomUUID().toString().replace("-", "");
LOG.info( LOG.info("Client has connected with a server generated identifier. CId={}, username={}", clientId,
"The client has connected with a server generated identifier. CId = {}, username = {}",
clientId,
payload.userName()); payload.userName());
} }
@@ -316,9 +269,7 @@ public class ProtocolProcessor {
return; return;
} }
ConnectionDescriptor descriptor = new ConnectionDescriptor( ConnectionDescriptor descriptor = new ConnectionDescriptor(clientId, channel,
clientId,
channel,
msg.variableHeader().isCleanSession()); msg.variableHeader().isCleanSession());
ConnectionDescriptor existing = this.connectionDescriptors.addConnection(descriptor); ConnectionDescriptor existing = this.connectionDescriptors.addConnection(descriptor);
if (existing != null) { if (existing != null) {
@@ -328,9 +279,7 @@ public class ProtocolProcessor {
} }
initializeKeepAliveTimeout(channel, msg, clientId); initializeKeepAliveTimeout(channel, msg, clientId);
storeWillMessage(msg, clientId); storeWillMessage(msg, clientId);
if (!sendAck(descriptor, msg, clientId)) { if (!sendAck(descriptor, msg, clientId)) {
channel.close(); channel.close();
return; return;
@@ -348,8 +297,7 @@ public class ProtocolProcessor {
channel.close(); channel.close();
return; return;
} }
final boolean success = descriptor final boolean success = descriptor.assignState(MESSAGES_REPUBLISHED, ESTABLISHED);
.assignState(ConnectionState.MESSAGES_REPUBLISHED, ConnectionState.ESTABLISHED);
if (!success) { if (!success) {
channel.close(); channel.close();
} }
@@ -366,12 +314,8 @@ public class ProtocolProcessor {
} }
private MqttConnAckMessage connAck(MqttConnectReturnCode returnCode, boolean sessionPresent) { private MqttConnAckMessage connAck(MqttConnectReturnCode returnCode, boolean sessionPresent) {
MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE,
MqttMessageType.CONNACK, false, 0);
false,
MqttQoS.AT_MOST_ONCE,
false,
0);
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent); MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader);
} }
@@ -383,26 +327,19 @@ public class ProtocolProcessor {
if (msg.variableHeader().hasPassword()) { if (msg.variableHeader().hasPassword()) {
pwd = msg.payload().password().getBytes(); pwd = msg.payload().password().getBytes();
} else if (!this.allowAnonymous) { } else if (!this.allowAnonymous) {
LOG.error( LOG.error("Client didn't supply any password and MQTT anonymous mode is disabled CId={}", clientId);
"The client didn't supply any password and MQTT anonymous mode is disabled. CId = {}.",
clientId);
failedCredentials(channel); failedCredentials(channel);
return false; return false;
} }
if (!m_authenticator.checkValid(clientId, msg.payload().userName(), pwd)) { if (!m_authenticator.checkValid(clientId, msg.payload().userName(), pwd)) {
LOG.error( LOG.error("Authenticator has rejected the MQTT credentials CId={}, username={}, password={}",
"The authenticator has rejected the MQTT credentials. CId = {}, username = {}, password = {}.", clientId, msg.payload().userName(), pwd);
clientId,
msg.payload().userName(),
pwd);
failedCredentials(channel); failedCredentials(channel);
return false; return false;
} }
NettyUtils.userName(channel, msg.payload().userName()); NettyUtils.userName(channel, msg.payload().userName());
} else if (!this.allowAnonymous) { } else if (!this.allowAnonymous) {
LOG.error( LOG.error("Client didn't supply any credentials and MQTT anonymous mode is disabled. CId={}", clientId);
"The client didn't supply any credentials and MQTT anonymous mode is disabled. CId = {}.",
clientId);
failedCredentials(channel); failedCredentials(channel);
return false; return false;
} }
@@ -411,7 +348,7 @@ public class ProtocolProcessor {
private boolean sendAck(ConnectionDescriptor descriptor, MqttConnectMessage msg, final String clientId) { private boolean sendAck(ConnectionDescriptor descriptor, MqttConnectMessage msg, final String clientId) {
LOG.info("Sending connect ACK. CId={}.", clientId); LOG.info("Sending connect ACK. CId={}.", clientId);
final boolean success = descriptor.assignState(ConnectionState.DISCONNECTED, ConnectionState.SENDACK); final boolean success = descriptor.assignState(DISCONNECTED, SENDACK);
if (!success) { if (!success) {
return false; return false;
} }
@@ -446,32 +383,20 @@ public class ProtocolProcessor {
int idleTime = Math.round(keepAlive * 1.5f); int idleTime = Math.round(keepAlive * 1.5f);
setIdleTime(channel.pipeline(), idleTime); setIdleTime(channel.pipeline(), idleTime);
LOG.info( LOG.debug("The connection has been configured CId={}, keepAlive={}, cleanSession={}, idleTime={}",
"The connection has been configured. CId = {}, keepAlive = {}, cleanSession = {}, idleTime = {}.", clientId, keepAlive, msg.variableHeader().isCleanSession(), idleTime);
clientId,
keepAlive,
msg.variableHeader().isCleanSession(),
idleTime);
} }
private void storeWillMessage(MqttConnectMessage msg, final String clientId) { private void storeWillMessage(MqttConnectMessage msg, final String clientId) {
// Handle will flag // Handle will flag
if (msg.variableHeader().isWillFlag()) { if (msg.variableHeader().isWillFlag()) {
MqttQoS willQos = MqttQoS.valueOf(msg.variableHeader().willQos()); MqttQoS willQos = MqttQoS.valueOf(msg.variableHeader().willQos());
LOG.info( LOG.info("Configuring MQTT last will and testament CId={}, willQos={}, willTopic={}, willRetain={}",
"Configuring MQTT last will and testament. " clientId, willQos, msg.payload().willTopic(), msg.variableHeader().isWillRetain());
+ "CId = {}, willQos = {}, willTopic = {}, willRetain = {}.",
clientId,
willQos,
msg.payload().willTopic(),
msg.variableHeader().isWillRetain());
byte[] willPayload = msg.payload().willMessage().getBytes(); byte[] willPayload = msg.payload().willMessage().getBytes();
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( WillMessage will = new WillMessage(msg.payload().willTopic(), bb, msg.variableHeader().isWillRetain(),
msg.payload().willTopic(),
bb,
msg.variableHeader().isWillRetain(),
willQos); willQos);
m_willStore.put(clientId, will); m_willStore.put(clientId, will);
LOG.info("MQTT last will and testament has been configured. CId={}.", clientId); LOG.info("MQTT last will and testament has been configured. CId={}.", clientId);
@@ -480,7 +405,7 @@ public class ProtocolProcessor {
private ClientSession createOrLoadClientSession(ConnectionDescriptor descriptor, MqttConnectMessage msg, private ClientSession createOrLoadClientSession(ConnectionDescriptor descriptor, MqttConnectMessage msg,
String clientId) { String clientId) {
final boolean success = descriptor.assignState(ConnectionState.SENDACK, ConnectionState.SESSION_CREATED); final boolean success = descriptor.assignState(SENDACK, SESSION_CREATED);
if (!success) { if (!success) {
return null; return null;
} }
@@ -498,8 +423,7 @@ public class ProtocolProcessor {
} }
private boolean republish(ConnectionDescriptor descriptor, MqttConnectMessage msg, ClientSession clientSession) { private boolean republish(ConnectionDescriptor descriptor, MqttConnectMessage msg, ClientSession clientSession) {
final boolean success = descriptor final boolean success = descriptor.assignState(SESSION_CREATED, MESSAGES_REPUBLISHED);
.assignState(ConnectionState.SESSION_CREATED, ConnectionState.MESSAGES_REPUBLISHED);
if (!success) { if (!success) {
return false; return false;
} }
@@ -558,19 +482,15 @@ public class ProtocolProcessor {
ByteBuf payload = msg.payload(); ByteBuf payload = msg.payload();
byte[] payloadContent = readBytesAndRewind(payload); byte[] payloadContent = readBytesAndRewind(payload);
IMessagesStore.StoredMessage stored = new IMessagesStore.StoredMessage( IMessagesStore.StoredMessage stored = new IMessagesStore.StoredMessage(payloadContent,
payloadContent, msg.fixedHeader().qosLevel(), msg.variableHeader().topicName());
msg.fixedHeader().qosLevel(),
msg.variableHeader().topicName());
stored.setRetained(msg.fixedHeader().isRetain()); stored.setRetained(msg.fixedHeader().isRetain());
stored.setMessageID(msg.variableHeader().messageId()); stored.setMessageID(msg.variableHeader().messageId());
return stored; return stored;
} }
private static IMessagesStore.StoredMessage asStoredMessage(WillMessage will) { private static IMessagesStore.StoredMessage asStoredMessage(WillMessage will) {
IMessagesStore.StoredMessage pub = new IMessagesStore.StoredMessage( IMessagesStore.StoredMessage pub = new IMessagesStore.StoredMessage(will.getPayload().array(), will.getQos(),
will.getPayload().array(),
will.getQos(),
will.getTopic()); will.getTopic());
pub.setRetained(will.isRetained()); pub.setRetained(will.isRetained());
return pub; return pub;
@@ -579,12 +499,8 @@ public class ProtocolProcessor {
public void processPublish(Channel channel, MqttPublishMessage msg) { public void processPublish(Channel channel, MqttPublishMessage msg) {
final MqttQoS qos = msg.fixedHeader().qosLevel(); final MqttQoS qos = msg.fixedHeader().qosLevel();
final String clientId = NettyUtils.clientID(channel); final String clientId = NettyUtils.clientID(channel);
LOG.info( LOG.info("Processing PUBLISH message. CId={}, topic={}, messageId={}, qos={}", clientId,
"Processing PUBLISH message. CId = {}, topic = {}, messageId = {}, qos = {}.", msg.variableHeader().topicName(), msg.variableHeader().messageId(), qos);
clientId,
msg.variableHeader().topicName(),
msg.variableHeader().messageId(),
qos);
switch (qos) { switch (qos) {
case AT_MOST_ONCE: case AT_MOST_ONCE:
this.qos0PublishHandler.receivedPublishQos0(channel, msg); this.qos0PublishHandler.receivedPublishQos0(channel, msg);
@@ -765,8 +681,7 @@ public class ProtocolProcessor {
} }
private boolean removeSubscriptions(ConnectionDescriptor descriptor, String clientID) { private boolean removeSubscriptions(ConnectionDescriptor descriptor, String clientID) {
final boolean success = descriptor final boolean success = descriptor.assignState(ESTABLISHED, SUBSCRIPTIONS_REMOVED);
.assignState(ConnectionState.ESTABLISHED, ConnectionState.SUBSCRIPTIONS_REMOVED);
if (!success) { if (!success) {
return false; return false;
} }
@@ -780,8 +695,7 @@ public class ProtocolProcessor {
} }
private boolean dropStoredMessages(ConnectionDescriptor descriptor, String clientID) { private boolean dropStoredMessages(ConnectionDescriptor descriptor, String clientID) {
final boolean success = descriptor final boolean success = descriptor.assignState(SUBSCRIPTIONS_REMOVED, MESSAGES_DROPPED);
.assignState(ConnectionState.SUBSCRIPTIONS_REMOVED, ConnectionState.MESSAGES_DROPPED);
if (!success) { if (!success) {
return false; return false;
} }
@@ -795,8 +709,7 @@ public class ProtocolProcessor {
} }
private boolean cleanWillMessageAndNotifyInterceptor(ConnectionDescriptor descriptor, String clientID) { private boolean cleanWillMessageAndNotifyInterceptor(ConnectionDescriptor descriptor, String clientID) {
final boolean success = descriptor final boolean success = descriptor.assignState(MESSAGES_DROPPED, INTERCEPTORS_NOTIFIED);
.assignState(ConnectionState.MESSAGES_DROPPED, ConnectionState.INTERCEPTORS_NOTIFIED);
if (!success) { if (!success) {
return false; return false;
} }
@@ -846,10 +759,7 @@ public class ProtocolProcessor {
if (!validTopic) { if (!validTopic) {
// close the connection, not valid topicFilter is a protocol violation // close the connection, not valid topicFilter is a protocol violation
channel.close(); channel.close();
LOG.error( LOG.error( "Topic filter is not valid. CId={}, topics={}, badTopicFilter={}", clientID, topics,
"The topic filter is not valid. CId = {}, topics = {}, badTopicFilter = {}.",
clientID,
topics,
topic); topic);
return; return;
} }
@@ -879,22 +789,16 @@ public class ProtocolProcessor {
SubscriptionState currentStatus = this.subscriptionInCourse SubscriptionState currentStatus = this.subscriptionInCourse
.putIfAbsent(executionKey, SubscriptionState.VERIFIED); .putIfAbsent(executionKey, SubscriptionState.VERIFIED);
if (currentStatus != null) { if (currentStatus != null) {
LOG.warn( LOG.warn("Client sent another SUBSCRIBE message while this one was being processed " +
"The client sent another SUBSCRIBE message while this one was being processed. " "CId={}, messageId={}", clientID, messageID);
+ "CId = {}, messageId = {}.",
clientID,
messageID);
return; return;
} }
String username = NettyUtils.userName(channel); String username = NettyUtils.userName(channel);
List<MqttTopicSubscription> ackTopics = doVerify(clientID, username, msg); List<MqttTopicSubscription> ackTopics = doVerify(clientID, username, msg);
MqttSubAckMessage ackMessage = doAckMessageFromValidateFilters(ackTopics, messageID); MqttSubAckMessage ackMessage = doAckMessageFromValidateFilters(ackTopics, messageID);
if (!this.subscriptionInCourse.replace(executionKey, SubscriptionState.VERIFIED, SubscriptionState.STORED)) { if (!this.subscriptionInCourse.replace(executionKey, SubscriptionState.VERIFIED, SubscriptionState.STORED)) {
LOG.warn( LOG.warn("Client sent another SUBSCRIBE message while the topic filters were being verified " +
"The client sent another SUBSCRIBE message while the topic filters were being verified. " "CId={}, messageId={}", clientID, messageID);
+ "CId = {}, messageId = {}.",
clientID,
messageID);
return; return;
} }
@@ -903,7 +807,6 @@ public class ProtocolProcessor {
List<Subscription> newSubscriptions = doStoreSubscription(ackTopics, clientID); List<Subscription> newSubscriptions = doStoreSubscription(ackTopics, clientID);
// save session, persist subscriptions from session // save session, persist subscriptions from session
for (Subscription subscription : newSubscriptions) { for (Subscription subscription : newSubscriptions) {
subscriptions.add(subscription.asClientTopicCouple()); subscriptions.add(subscription.asClientTopicCouple());
} }
@@ -958,32 +861,19 @@ public class ProtocolProcessor {
Topic topic = new Topic(req.topicName()); Topic topic = new Topic(req.topicName());
if (!m_authorizator.canRead(topic, username, clientSession.clientID)) { if (!m_authorizator.canRead(topic, username, clientSession.clientID)) {
// send SUBACK with 0x80, the user hasn't credentials to read the topic // send SUBACK with 0x80, the user hasn't credentials to read the topic
LOG.error( LOG.error("Client does not have read permissions on the topic " +
"The client does not have read permissions on the topic. " "CId={}, username={}, messageId={}, topic={}",
+ "CId = {}, username = {}, messageId = {}, topic = {}.", clientID, username, messageId, topic);
clientID,
username,
messageId,
topic);
ackTopics.add(new MqttTopicSubscription(topic.toString(), FAILURE)); ackTopics.add(new MqttTopicSubscription(topic.toString(), FAILURE));
} else { } else {
MqttQoS qos; MqttQoS qos;
if (topic.isValid()) { if (topic.isValid()) {
LOG.info( LOG.info("Client will be subscribed to the topic " +
"The client will be subscribed to the topic. " "CId={}, username={}, messageId={}, topic={}", clientID, username, messageId, topic);
+ "CId = {}, username = {}, messageId = {}, topic = {}.",
clientID,
username,
messageId,
topic);
qos = req.qualityOfService(); qos = req.qualityOfService();
} else { } else {
LOG.error( LOG.error("Topic filter is not valid CId={}, username={}, messageId={}, topic={}",
"The topic filter is not valid. CId = {}, username = {}, messageId = {}, topic = {}.", clientID, username, messageId, topic);
clientID,
username,
messageId,
topic);
qos = FAILURE; qos = FAILURE;
} }
ackTopics.add(new MqttTopicSubscription(topic.toString(), qos)); ackTopics.add(new MqttTopicSubscription(topic.toString(), qos));
@@ -1007,9 +897,7 @@ public class ProtocolProcessor {
} }
private void publishRetainedMessagesInSession(final Subscription newSubscription, String username) { private void publishRetainedMessagesInSession(final Subscription newSubscription, String username) {
LOG.info( LOG.info("Retrieving retained messages CId={}, topics={}", newSubscription.getClientId(),
"Retrieving retained messages. CId = {}, topics = {}.",
newSubscription.getClientId(),
newSubscription.getTopicFilter()); newSubscription.getTopicFilter());
// scans retained messages to be published to the new subscription // scans retained messages to be published to the new subscription
@@ -1023,11 +911,8 @@ public class ProtocolProcessor {
}); });
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
LOG.info( LOG.info("Publishing retained messages CId={}, topics={}, messagesNo={}",
"Publishing retained messages. CId = {}, topics = {}, messagesNo = {}.", newSubscription.getClientId(), newSubscription.getTopicFilter(), messages.size());
newSubscription.getClientId(),
newSubscription.getTopicFilter(),
messages.size());
} }
ClientSession targetSession = m_sessionsStore.sessionForClient(newSubscription.getClientId()); ClientSession targetSession = m_sessionsStore.sessionForClient(newSubscription.getClientId());
this.internalRepublisher.publishRetained(targetSession, messages); this.internalRepublisher.publishRetained(targetSession, messages);
@@ -1047,12 +932,8 @@ public class ProtocolProcessor {
} else { } else {
// recreate a publish from stored publish in queue // recreate a publish from stored publish in queue
boolean retained = m_messagesStore.getMessageByGuid(msg.getGuid()) != null; boolean retained = m_messagesStore.getMessageByGuid(msg.getGuid()) != null;
MqttPublishMessage pubMsg = createPublishForQos( MqttPublishMessage pubMsg = createPublishForQos( msg.getTopic(), msg.getQos(), msg.getMessage(),
msg.getTopic(), retained, 0);
msg.getQos(),
msg.getMessage(),
retained,
0);
channel.write(pubMsg); channel.write(pubMsg);
} }
} }