broker/NettyMQTTHandler: code formatter used

This commit is contained in:
Andreas Mager
2017-02-01 17:13:38 +01:00
parent 798fe1e171
commit 539427ddd2
@@ -13,6 +13,7 @@
* *
* You may elect to redistribute this code under either of these licenses. * You may elect to redistribute this code under either of these licenses.
*/ */
package io.moquette.server.netty; package io.moquette.server.netty;
import io.moquette.spi.impl.ProtocolProcessor; import io.moquette.spi.impl.ProtocolProcessor;
@@ -22,10 +23,8 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
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 static io.netty.handler.codec.mqtt.MqttQoS.AT_MOST_ONCE; import static io.netty.handler.codec.mqtt.MqttQoS.AT_MOST_ONCE;
/** /**
* *
* @author andrea * @author andrea
@@ -75,14 +74,19 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter {
m_processor.processPubAck(ctx.channel(), (MqttPubAckMessage) msg); m_processor.processPubAck(ctx.channel(), (MqttPubAckMessage) msg);
break; break;
case PINGREQ: case PINGREQ:
MqttFixedHeader pingHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, AT_MOST_ONCE, false, 0); MqttFixedHeader pingHeader = new MqttFixedHeader(
MqttMessageType.PINGRESP,
false,
AT_MOST_ONCE,
false,
0);
MqttMessage pingResp = new MqttMessage(pingHeader); MqttMessage pingResp = new MqttMessage(pingHeader);
ctx.writeAndFlush(pingResp); ctx.writeAndFlush(pingResp);
break; break;
} }
} catch (Throwable ex) { } catch (Throwable ex) {
LOG.error("Exception was caught while processing MQTT message, " + ex.getCause(), ex); LOG.error("Exception was caught while processing MQTT message, " + ex.getCause(), ex);
ctx.fireExceptionCaught(ex); ctx.fireExceptionCaught(ex);
} }
} }
@@ -90,7 +94,7 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter {
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
String clientID = NettyUtils.clientID(ctx.channel()); String clientID = NettyUtils.clientID(ctx.channel());
if (clientID != null && !clientID.isEmpty()) { if (clientID != null && !clientID.isEmpty()) {
LOG.info("Notifying connection lost event. MqttClientId = {}.", clientID); LOG.info("Notifying connection lost event. MqttClientId = {}.", clientID);
m_processor.processConnectionLost(clientID, ctx.channel()); m_processor.processConnectionLost(clientID, ctx.channel());
} }
ctx.close(); ctx.close();
@@ -98,9 +102,12 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
LOG.error( LOG.error(
"An unexpected exception was caught while processing MQTT message. Closing Netty channel. MqttClientId = {}, cause = {}, errorMessage = {}.", "An unexpected exception was caught while processing MQTT message. "
NettyUtils.clientID(ctx.channel()), cause.getCause(), cause.getMessage()); + "Closing Netty channel. MqttClientId = {}, cause = {}, errorMessage = {}.",
NettyUtils.clientID(ctx.channel()),
cause.getCause(),
cause.getMessage());
ctx.close(); ctx.close();
} }