Enable checkstyle on yang-data-codec-gson
[yangtools.git] / websocket / websocket-client / src / main / java / org / opendaylight / yangtools / websocket / client / WebSocketIClient.java
index 1a16487b7483a579f47e612f008dfbd413078f79..e113fb63784d0152dedda7c992e22cfe98c320b5 100644 (file)
@@ -7,11 +7,13 @@
  */
 package org.opendaylight.yangtools.websocket.client;
 
+import com.google.common.base.Preconditions;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoop;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
@@ -20,45 +22,38 @@ import io.netty.handler.codec.http.HttpClientCodec;
 import io.netty.handler.codec.http.HttpObjectAggregator;
 import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
 import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
 import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
 import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
 import io.netty.handler.codec.http.websocketx.WebSocketVersion;
-
 import java.net.URI;
-
 import org.opendaylight.yangtools.websocket.client.callback.ClientMessageCallback;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of web socket client that supports WS and HTTP protocols.
+ *
+ * @deprecated This code is deprecated without replacement.
  */
+@Deprecated
 public class WebSocketIClient {
-
-    private final URI uri;
-    private Bootstrap bootstrap = new Bootstrap();;
+    private final EventLoopGroup group = new NioEventLoopGroup();
+    private final Bootstrap bootstrap = new Bootstrap();
     private final WebSocketClientHandler clientHandler;
-    private static final Logger logger = LoggerFactory
-            .getLogger(WebSocketIClient.class);
+    private final URI uri;
     private Channel clientChannel;
-    private final EventLoopGroup group = new NioEventLoopGroup();
 
     /**
      * Creates new web socket client
-     * 
+     *
      * @param uri
      *            URI
      * @param clientMessageCallback
      *            ClientMessageCallback
      */
-    public WebSocketIClient(URI uri, ClientMessageCallback clientMessageCallback) {
-        this.uri = uri;
+    public WebSocketIClient(final URI uri, final ClientMessageCallback clientMessageCallback) {
+        this.uri = Preconditions.checkNotNull(uri);
         clientHandler = new WebSocketClientHandler(
-                WebSocketClientHandshakerFactory.newHandshaker(uri,
-                        WebSocketVersion.V13, null, false, null),
-                clientMessageCallback); // last null could be replaced with
-                                        // DefaultHttpHeaders
+                WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, null),
+                clientMessageCallback); // last null could be replaced with DefaultHttpHeaders
         initialize();
     }
 
@@ -77,7 +72,7 @@ public class WebSocketIClient {
         bootstrap.group(group).channel(NioSocketChannel.class)
                 .handler(new ChannelInitializer<SocketChannel>() {
                     @Override
-                    public void initChannel(SocketChannel ch) throws Exception {
+                    public void initChannel(final SocketChannel ch) {
                         ChannelPipeline pipeline = ch.pipeline();
                         pipeline.addLast("http-codec", new HttpClientCodec());
                         pipeline.addLast("aggregator",
@@ -98,33 +93,33 @@ public class WebSocketIClient {
     }
 
     /**
-     * Writes a String message via {@link ChannelOutboundInvoker} through the
-     * {@link ChannelPipeline} and request to actual {@link #flush()} to flush
+     * Writes a String message through the
+     * {@link ChannelPipeline} and request to actual {@link Channel#flush()} to flush
      * all pending data to the actual transport.
-     * 
+     *
      * @param message
      *            a message to write
      */
-    public void writeAndFlush(String message) {
+    public void writeAndFlush(final String message) {
         clientChannel.writeAndFlush(new TextWebSocketFrame(message));
     }
 
     /**
-     * Writes a Object message via {@link ChannelOutboundInvoker} through the
-     * {@link ChannelPipeline} and request to actual {@link #flush()} to flush
+     * Writes a Object message through the
+     * {@link ChannelPipeline} and request to actual {@link Channel#flush()} to flush
      * all pending data to the actual transport.
-     * 
+     *
      * @param message
      *            a message to write
      */
-    public void writeAndFlush(Object message) {
+    public void writeAndFlush(final Object message) {
         clientChannel.writeAndFlush(message);
     }
 
     /**
-     * Writes {@link PingWebSocketFrame} via {@link ChannelOutboundInvoker}
+     * Writes {@link PingWebSocketFrame}
      * through the {@link ChannelPipeline} and request to actual
-     * {@link #flush()} to flush all pending data to the actual transport.
+     * {@link Channel#flush()} to flush all pending data to the actual transport.
      */
     public void ping() {
         clientChannel.writeAndFlush(new PingWebSocketFrame(Unpooled