2014-06-11 23:40:19 +02:00
|
|
|
/*
|
2017-03-19 22:01:23 +01:00
|
|
|
* Copyright (c) 2012-2017 The original author or authors
|
2014-06-11 23:40:19 +02:00
|
|
|
* ------------------------------------------------------
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
|
* and Apache License v2.0 which accompanies this distribution.
|
|
|
|
|
*
|
|
|
|
|
* The Eclipse Public License is available at
|
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
*
|
|
|
|
|
* The Apache License v2.0 is available at
|
|
|
|
|
* http://www.opensource.org/licenses/apache2.0.php
|
|
|
|
|
*
|
|
|
|
|
* You may elect to redistribute this code under either of these licenses.
|
|
|
|
|
*/
|
2017-02-01 16:33:42 +01:00
|
|
|
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.testclient;
|
2014-01-11 13:19:12 +01:00
|
|
|
|
2017-01-28 10:06:30 +01:00
|
|
|
import io.moquette.server.netty.NettyMQTTHandler;
|
2014-01-11 13:19:12 +01:00
|
|
|
import io.netty.channel.ChannelHandler;
|
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
2017-01-28 10:06:30 +01:00
|
|
|
import io.netty.handler.codec.mqtt.MqttMessage;
|
2014-01-11 13:19:12 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
2018-04-25 19:39:12 +02:00
|
|
|
import static io.netty.channel.ChannelFutureListener.CLOSE_ON_FAILURE;
|
|
|
|
|
|
2014-01-11 13:19:12 +01:00
|
|
|
@ChannelHandler.Sharable
|
|
|
|
|
class ClientNettyMQTTHandler extends ChannelInboundHandlerAdapter {
|
2017-02-01 16:33:42 +01:00
|
|
|
|
2014-01-11 13:19:12 +01:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(NettyMQTTHandler.class);
|
|
|
|
|
private Client m_client;
|
2017-02-01 16:33:42 +01:00
|
|
|
|
2014-01-11 13:19:12 +01:00
|
|
|
@Override
|
|
|
|
|
public void channelRead(ChannelHandlerContext ctx, Object message) {
|
2017-01-28 10:06:30 +01:00
|
|
|
MqttMessage msg = (MqttMessage) message;
|
|
|
|
|
LOG.info("Received a message of type {}", msg.fixedHeader().messageType());
|
2014-01-11 13:19:12 +01:00
|
|
|
m_client.messageReceived(msg);
|
|
|
|
|
}
|
2017-02-01 16:33:42 +01:00
|
|
|
|
2014-01-11 13:19:12 +01:00
|
|
|
@Override
|
2018-04-25 19:39:12 +02:00
|
|
|
public void channelInactive(ChannelHandlerContext ctx) {
|
2014-01-11 13:19:12 +01:00
|
|
|
m_client.setConnectionLost(true);
|
2018-04-25 19:39:12 +02:00
|
|
|
ctx.close().addListener(CLOSE_ON_FAILURE);
|
2014-01-11 13:19:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setClient(Client client) {
|
|
|
|
|
m_client = client;
|
|
|
|
|
}
|
2017-02-01 16:33:42 +01:00
|
|
|
|
2014-01-11 13:19:12 +01:00
|
|
|
}
|