|
33 | 33 | import com.hivemq.client.internal.mqtt.message.publish.pubrec.MqttPubRec; |
34 | 34 | import com.hivemq.client.internal.mqtt.message.publish.pubrec.MqttPubRecBuilder; |
35 | 35 | import com.hivemq.client.internal.mqtt.message.publish.pubrel.MqttPubRel; |
36 | | -import com.hivemq.client.internal.netty.ContextFuture; |
37 | | -import com.hivemq.client.internal.netty.DefaultContextPromise; |
38 | 36 | import com.hivemq.client.internal.util.collections.IntIndex; |
39 | 37 | import com.hivemq.client.mqtt.MqttVersion; |
40 | 38 | import com.hivemq.client.mqtt.datatypes.MqttQos; |
|
53 | 51 | * @author Silvio Giebl |
54 | 52 | */ |
55 | 53 | @ClientScope |
56 | | -public class MqttIncomingQosHandler extends MqttSessionAwareHandler implements ContextFuture.Listener<MqttPubRec> { |
| 54 | +public class MqttIncomingQosHandler extends MqttSessionAwareHandler { |
57 | 55 |
|
58 | 56 | public static final @NotNull String NAME = "qos.incoming"; |
59 | 57 | private static final @NotNull InternalLogger LOGGER = InternalLoggerFactory.getLogger(MqttIncomingQosHandler.class); |
@@ -246,7 +244,8 @@ void ack(final @NotNull MqttStatefulPublishWithFlows publishWithFlows) { |
246 | 244 | } |
247 | 245 | case EXACTLY_ONCE: { |
248 | 246 | final MqttPubRec pubRec = buildPubRec(new MqttPubRecBuilder(publishWithFlows.publish)); |
249 | | - final Object prevMessage = messages.put(pubRec); |
| 247 | + final Object prevMessage = !pubRec.getReasonCode().isError() ? messages.put(pubRec) : |
| 248 | + messages.remove(pubRec.getPacketIdentifier()); |
250 | 249 | if (ack(prevMessage, publishWithFlows) && (ctx != null)) { |
251 | 250 | writePubRec(ctx, pubRec); |
252 | 251 | } |
@@ -276,20 +275,7 @@ private void writePubAck(final @NotNull ChannelHandlerContext ctx, final @NotNul |
276 | 275 | } |
277 | 276 |
|
278 | 277 | private void writePubRec(final @NotNull ChannelHandlerContext ctx, final @NotNull MqttPubRec pubRec) { |
279 | | - if (pubRec.getReasonCode().isError()) { |
280 | | - ctx.writeAndFlush(pubRec, new DefaultContextPromise<>(ctx.channel(), pubRec)).addListener(this); |
281 | | - } else { |
282 | | - ctx.writeAndFlush(pubRec, ctx.voidPromise()); |
283 | | - } |
284 | | - } |
285 | | - |
286 | | - @Override |
287 | | - public void operationComplete(final @NotNull ContextFuture<? extends MqttPubRec> future) { |
288 | | - if (future.isSuccess()) { |
289 | | - messages.remove(future.getContext().getPacketIdentifier()); |
290 | | - } else { |
291 | | - future.channel().pipeline().fireExceptionCaught(future.cause()); |
292 | | - } |
| 278 | + ctx.writeAndFlush(pubRec, ctx.voidPromise()); |
293 | 279 | } |
294 | 280 |
|
295 | 281 | private void readPubRel(final @NotNull ChannelHandlerContext ctx, final @NotNull MqttPubRel pubRel) { |
|
0 commit comments