Fixed inactive channel propagation event through MQTTMessageLogger

This commit is contained in:
andsel
2016-12-28 22:21:33 +01:00
parent 4e2a0dbf28
commit d3116dc685
2 changed files with 9 additions and 7 deletions
@@ -37,12 +37,15 @@ public class MQTTMessageLogger extends ChannelDuplexHandler {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object message) { public void channelRead(ChannelHandlerContext ctx, Object message) {
logMQTTMessage(ctx, (AbstractMessage) message, "C->B"); logMQTTMessage(ctx, message, "C->B");
ctx.fireChannelRead(message); ctx.fireChannelRead(message);
} }
private void logMQTTMessage(ChannelHandlerContext ctx, AbstractMessage message, String direction) { private void logMQTTMessage(ChannelHandlerContext ctx, Object message, String direction) {
AbstractMessage msg = message; if (!(message instanceof AbstractMessage)) {
return;
}
AbstractMessage msg = (AbstractMessage) message;
String clientID = NettyUtils.clientID(ctx.channel()); String clientID = NettyUtils.clientID(ctx.channel());
switch (msg.getMessageType()) { switch (msg.getMessageType()) {
case CONNECT: case CONNECT:
@@ -89,7 +92,7 @@ public class MQTTMessageLogger extends ChannelDuplexHandler {
if (clientID != null && !clientID.isEmpty()) { if (clientID != null && !clientID.isEmpty()) {
LOG.info("Channel closed <{}>", clientID); LOG.info("Channel closed <{}>", clientID);
} }
ctx.fireChannelActive(); ctx.fireChannelInactive();
} }
@Override @Override
@@ -385,12 +385,11 @@ public class ProtocolProcessor {
} }
private void setupAutoFlusher(ChannelPipeline pipeline, int flushIntervalMs) { private void setupAutoFlusher(ChannelPipeline pipeline, int flushIntervalMs) {
AutoFlushHandler autoFlushHandler = new AutoFlushHandler(flushIntervalMs, TimeUnit.MILLISECONDS);
try { try {
pipeline.addAfter("idleEventHandler", "autoFlusher", autoFlushHandler); pipeline.addAfter("idleEventHandler", "autoFlusher", new AutoFlushHandler(flushIntervalMs, TimeUnit.MILLISECONDS));
} catch (NoSuchElementException nseex) { } catch (NoSuchElementException nseex) {
//the idleEventHandler is not present on the pipeline //the idleEventHandler is not present on the pipeline
pipeline.addFirst("autoFlusher", autoFlushHandler); pipeline.addFirst("autoFlusher", new AutoFlushHandler(flushIntervalMs, TimeUnit.MILLISECONDS));
} }
} }