public void sendPublishRetainedWithPacketId(Topic topic, MqttQoS qos, ByteBuf payload) { final int packetId = nextPacketId(); MqttPublishMessage publishMsg = retainedPublishWithMessageId(topic.toString(), qos, payload, packetId); sendPublish(publishMsg); }
private void drainQueueToConnection() { // consume the queue while (!canSkipQueue()) { final SessionRegistry.EnqueuedMessage msg = sessionQueue.remove(); inflightSlots.decrementAndGet(); int sendPacketId = mqttConnection.nextPacketId(); inflightWindow.put(sendPacketId, msg); if (msg instanceof SessionRegistry.PubRelMarker) { MqttMessage pubRel = MQTTConnection.pubrel(sendPacketId); mqttConnection.sendIfWritableElseDrop(pubRel); } else { final SessionRegistry.PublishedMessage msgPub = (SessionRegistry.PublishedMessage) msg; MqttPublishMessage publishMsg = MQTTConnection.notRetainedPublishWithMessageId(msgPub.topic.toString(), msgPub.publishingQos, msgPub.payload, sendPacketId); mqttConnection.sendPublish(publishMsg); } } }
private void sendPublishQos2(Topic topic, MqttQoS qos, ByteBuf payload) { if (canSkipQueue()) { inflightSlots.decrementAndGet(); int packetId = mqttConnection.nextPacketId(); inflightWindow.put(packetId, new SessionRegistry.PublishedMessage(topic, qos, payload)); inflightTimeouts.add(new InFlightPacket(packetId, FLIGHT_BEFORE_RESEND_MS)); MqttPublishMessage publishMsg = MQTTConnection.notRetainedPublishWithMessageId(topic.toString(), qos, payload, packetId); mqttConnection.sendPublish(publishMsg); drainQueueToConnection(); } else { final SessionRegistry.PublishedMessage msg = new SessionRegistry.PublishedMessage(topic, qos, payload); sessionQueue.add(msg); } }
private void sendPublishQos1(Topic topic, MqttQoS qos, ByteBuf payload) { if (!connected() && isClean()) { //pushing messages to disconnected not clean session return; } if (canSkipQueue()) { inflightSlots.decrementAndGet(); int packetId = mqttConnection.nextPacketId(); inflightWindow.put(packetId, new SessionRegistry.PublishedMessage(topic, qos, payload)); inflightTimeouts.add(new InFlightPacket(packetId, FLIGHT_BEFORE_RESEND_MS)); MqttPublishMessage publishMsg = MQTTConnection.notRetainedPublishWithMessageId(topic.toString(), qos, payload, packetId); mqttConnection.sendPublish(publishMsg); // TODO drainQueueToConnection();? } else { final SessionRegistry.PublishedMessage msg = new SessionRegistry.PublishedMessage(topic, qos, payload); sessionQueue.add(msg); } }