broker/MessagesPublisher: code formatter used
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
package io.moquette.spi.impl;
|
package io.moquette.spi.impl;
|
||||||
|
|
||||||
import io.moquette.server.ConnectionDescriptorStore;
|
import io.moquette.server.ConnectionDescriptorStore;
|
||||||
@@ -10,9 +11,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.handler.codec.mqtt.*;
|
import io.netty.handler.codec.mqtt.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.moquette.spi.impl.ProtocolProcessor.lowerQosToTheSubscriptionDesired;
|
import static io.moquette.spi.impl.ProtocolProcessor.lowerQosToTheSubscriptionDesired;
|
||||||
|
|
||||||
class MessagesPublisher {
|
class MessagesPublisher {
|
||||||
@@ -24,7 +23,7 @@ class MessagesPublisher {
|
|||||||
private final PersistentQueueMessageSender messageSender;
|
private final PersistentQueueMessageSender messageSender;
|
||||||
|
|
||||||
public MessagesPublisher(ConnectionDescriptorStore connectionDescriptors, ISessionsStore sessionsStore,
|
public MessagesPublisher(ConnectionDescriptorStore connectionDescriptors, ISessionsStore sessionsStore,
|
||||||
IMessagesStore messagesStore, PersistentQueueMessageSender messageSender) {
|
IMessagesStore messagesStore, PersistentQueueMessageSender messageSender) {
|
||||||
this.connectionDescriptors = connectionDescriptors;
|
this.connectionDescriptors = connectionDescriptors;
|
||||||
this.m_sessionsStore = sessionsStore;
|
this.m_sessionsStore = sessionsStore;
|
||||||
this.m_messagesStore = messagesStore;
|
this.m_messagesStore = messagesStore;
|
||||||
@@ -35,7 +34,8 @@ class MessagesPublisher {
|
|||||||
return notRetainedPublishWithMessageId(topic, qos, message, 0);
|
return notRetainedPublishWithMessageId(topic, qos, message, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MqttPublishMessage notRetainedPublishWithMessageId(String topic, MqttQoS qos, ByteBuf message, int messageId) {
|
private static MqttPublishMessage notRetainedPublishWithMessageId(String topic, MqttQoS qos, ByteBuf message,
|
||||||
|
int messageId) {
|
||||||
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, qos, false, 0);
|
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, qos, false, 0);
|
||||||
MqttPublishVariableHeader varHeader = new MqttPublishVariableHeader(topic, messageId);
|
MqttPublishVariableHeader varHeader = new MqttPublishVariableHeader(topic, messageId);
|
||||||
return new MqttPublishMessage(fixedHeader, varHeader, message);
|
return new MqttPublishMessage(fixedHeader, varHeader, message);
|
||||||
@@ -46,8 +46,8 @@ class MessagesPublisher {
|
|||||||
final MqttQoS publishingQos = pubMsg.getQos();
|
final MqttQoS publishingQos = pubMsg.getQos();
|
||||||
final ByteBuf origMessage = pubMsg.getMessage();
|
final ByteBuf origMessage = pubMsg.getMessage();
|
||||||
|
|
||||||
//if QoS 1 or 2 store the message
|
// if QoS 1 or 2 store the message
|
||||||
//TODO perhaps this block is not needed.
|
// TODO perhaps this block is not needed.
|
||||||
MessageGUID guid = null;
|
MessageGUID guid = null;
|
||||||
if (publishingQos != MqttQoS.AT_MOST_ONCE) {
|
if (publishingQos != MqttQoS.AT_MOST_ONCE) {
|
||||||
guid = m_messagesStore.storePublishForFuture(pubMsg);
|
guid = m_messagesStore.storePublishForFuture(pubMsg);
|
||||||
@@ -59,25 +59,34 @@ class MessagesPublisher {
|
|||||||
|
|
||||||
boolean targetIsActive = this.connectionDescriptors.isConnected(sub.getClientId());
|
boolean targetIsActive = this.connectionDescriptors.isConnected(sub.getClientId());
|
||||||
|
|
||||||
//we need to retain because duplicate only copy r/w indexes and don't retain() causing refCnt = 0
|
// we need to retain because duplicate only copy r/w indexes and don't retain() causing
|
||||||
|
// refCnt = 0
|
||||||
ByteBuf message = origMessage.retainedDuplicate();
|
ByteBuf message = origMessage.retainedDuplicate();
|
||||||
if (targetIsActive) {
|
if (targetIsActive) {
|
||||||
LOG.debug("Sending PUBLISH message to active subscriber. MessageId={}, CId={}, topicFilter={}, qos={}",
|
LOG.debug(
|
||||||
pubMsg.getMessageID(), sub.getClientId(), sub.getTopicFilter(), qos);
|
"Sending PUBLISH message to active subscriber. MessageId={}, CId={}, topicFilter={}, qos={}",
|
||||||
|
pubMsg.getMessageID(),
|
||||||
|
sub.getClientId(),
|
||||||
|
sub.getTopicFilter(),
|
||||||
|
qos);
|
||||||
MqttPublishMessage publishMsg = notRetainedPublish(topic, qos, message);
|
MqttPublishMessage publishMsg = notRetainedPublish(topic, qos, message);
|
||||||
if (qos != MqttQoS.AT_MOST_ONCE) {
|
if (qos != MqttQoS.AT_MOST_ONCE) {
|
||||||
//QoS 1 or 2
|
// QoS 1 or 2
|
||||||
int messageId = targetSession.nextPacketId();
|
int messageId = targetSession.nextPacketId();
|
||||||
targetSession.inFlightAckWaiting(guid, messageId);
|
targetSession.inFlightAckWaiting(guid, messageId);
|
||||||
//set the PacketIdentifier only for QoS > 0
|
// set the PacketIdentifier only for QoS > 0
|
||||||
publishMsg = notRetainedPublishWithMessageId(topic, qos, message, messageId);
|
publishMsg = notRetainedPublishWithMessageId(topic, qos, message, messageId);
|
||||||
}
|
}
|
||||||
this.messageSender.sendPublish(targetSession, publishMsg);
|
this.messageSender.sendPublish(targetSession, publishMsg);
|
||||||
} else {
|
} else {
|
||||||
if (!targetSession.isCleanSession()) {
|
if (!targetSession.isCleanSession()) {
|
||||||
LOG.debug("Storing pending PUBLISH inactive message. MessageId={}, CId={}, topicFilter={}, qos={}",
|
LOG.debug(
|
||||||
pubMsg.getMessageID(), sub.getClientId(), sub.getTopicFilter(), qos);
|
"Storing pending PUBLISH inactive message. MessageId={}, CId={}, topicFilter={}, qos={}",
|
||||||
//store the message in targetSession queue to deliver
|
pubMsg.getMessageID(),
|
||||||
|
sub.getClientId(),
|
||||||
|
sub.getTopicFilter(),
|
||||||
|
qos);
|
||||||
|
// store the message in targetSession queue to deliver
|
||||||
targetSession.enqueue(pubMsg);
|
targetSession.enqueue(pubMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user