Fixed checkStyle and ErrorProne warns
This commit is contained in:
@@ -25,9 +25,13 @@ import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.netty.channel.ChannelFutureListener.CLOSE_ON_FAILURE;
|
||||
import static io.netty.channel.ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE;
|
||||
|
||||
/**
|
||||
* Class used just to send and receive MQTT messages without any protocol login in action, just use
|
||||
* the encoder/decoder part.
|
||||
@@ -52,6 +56,7 @@ public class Client {
|
||||
this(host, BrokerConstants.PORT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("FutureReturnValueIgnored")
|
||||
public Client(String host, int port) {
|
||||
handler.setClient(this);
|
||||
workerGroup = new NioEventLoopGroup();
|
||||
@@ -157,7 +162,7 @@ public class Client {
|
||||
}
|
||||
|
||||
public void sendMessage(MqttMessage msg) {
|
||||
m_channel.writeAndFlush(msg);
|
||||
m_channel.writeAndFlush(msg).addListener(FIRE_EXCEPTION_ON_FAILURE);
|
||||
}
|
||||
|
||||
public MqttMessage lastReceivedMessage() {
|
||||
@@ -179,9 +184,10 @@ public class Client {
|
||||
return m_connectionLost;
|
||||
}
|
||||
|
||||
@SuppressWarnings("FutureReturnValueIgnored")
|
||||
public void close() throws InterruptedException {
|
||||
// Wait until the connection is closed.
|
||||
m_channel.closeFuture().sync();
|
||||
m_channel.closeFuture().sync().addListener(CLOSE_ON_FAILURE);
|
||||
if (workerGroup == null) {
|
||||
throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized");
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import io.netty.handler.codec.mqtt.MqttMessage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.netty.channel.ChannelFutureListener.CLOSE_ON_FAILURE;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
class ClientNettyMQTTHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@@ -38,9 +40,9 @@ class ClientNettyMQTTHandler extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
m_client.setConnectionLost(true);
|
||||
ctx.close(/* false */);
|
||||
ctx.close().addListener(CLOSE_ON_FAILURE);
|
||||
}
|
||||
|
||||
void setClient(Client client) {
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.netty.channel.ChannelFutureListener.CLOSE_ON_FAILURE;
|
||||
|
||||
/**
|
||||
* This class is used to have a fluent interface to interact with a server. Inspired by
|
||||
* org.kaazing.robot
|
||||
@@ -55,10 +57,9 @@ public final class RawClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
// m_client.setConnectionLost(true);
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
disconnectLatch.countDown();
|
||||
ctx.close(/* false */);
|
||||
ctx.close().addListener(CLOSE_ON_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +73,7 @@ public final class RawClient {
|
||||
private CountDownLatch disconnectLatch;
|
||||
private final Semaphore readableBytesSem;
|
||||
|
||||
@SuppressWarnings("FutureReturnValueIgnored")
|
||||
private RawClient(String host, int port) {
|
||||
handler = new RawMessageHandler();
|
||||
heapBuffer = Unpooled.buffer(128);
|
||||
@@ -120,14 +122,14 @@ public final class RawClient {
|
||||
for (int b : bytes) {
|
||||
buff.writeByte((byte) b);
|
||||
}
|
||||
m_channel.write(buff);
|
||||
m_channel.write(buff).addListener(CLOSE_ON_FAILURE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RawClient writeWithSize(String str) {
|
||||
ByteBuf buff = Unpooled.buffer(str.length() + 2);
|
||||
buff.writeBytes(Utils.encodeString(str));
|
||||
m_channel.write(buff);
|
||||
m_channel.write(buff).addListener(CLOSE_ON_FAILURE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -145,7 +147,7 @@ public final class RawClient {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
out.writeBytes(raw);
|
||||
m_channel.write(out);
|
||||
m_channel.write(out).addListener(CLOSE_ON_FAILURE);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user