@Override
 public void channelRead(ChannelHandlerContext ctx, Object message) {
   AbstractMessage msg = (AbstractMessage) message;
   LOG.info("Received a message of type {}", Utils.msgType2String(msg.getMessageType()));
   try {
     switch (msg.getMessageType()) {
       case CONNECT:
         m_processor.processConnect(ctx.channel(), (ConnectMessage) msg);
         break;
       case SUBSCRIBE:
         m_processor.processSubscribe(ctx.channel(), (SubscribeMessage) msg);
         break;
       case UNSUBSCRIBE:
         m_processor.processUnsubscribe(ctx.channel(), (UnsubscribeMessage) msg);
         break;
       case PUBLISH:
         m_processor.processPublish(ctx.channel(), (PublishMessage) msg);
         break;
       case PUBREC:
         m_processor.processPubRec(ctx.channel(), (PubRecMessage) msg);
         break;
       case PUBCOMP:
         m_processor.processPubComp(ctx.channel(), (PubCompMessage) msg);
         break;
       case PUBREL:
         m_processor.processPubRel(ctx.channel(), (PubRelMessage) msg);
         break;
       case DISCONNECT:
         m_processor.processDisconnect(ctx.channel());
         break;
       case PUBACK:
         m_processor.processPubAck(ctx.channel(), (PubAckMessage) msg);
         break;
       case PINGREQ:
         PingRespMessage pingResp = new PingRespMessage();
         ctx.writeAndFlush(pingResp);
         break;
     }
   } catch (Exception ex) {
     LOG.error("Bad error in processing the message", ex);
   }
 }
 @Override
 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
   String clientID = NettyUtils.clientID(ctx.channel());
   if (clientID != null && !clientID.isEmpty()) {
     // if the channel was of a correctly connected client, inform messaging
     // else it was of a not completed CONNECT message or sessionStolen
     boolean stolen = false;
     Boolean stolenAttr = NettyUtils.sessionStolen(ctx.channel());
     if (stolenAttr != null && stolenAttr == Boolean.TRUE) {
       stolen = true;
     }
     m_processor.processConnectionLost(clientID, stolen, ctx.channel());
   }
   ctx.close();
 }