Simplify code using Java 8 features
[netconf.git] / netconf / netconf-ssh / src / main / java / org / opendaylight / netconf / ssh / RemoteNetconfCommand.java
index b5a6355d2990c6c26926b6a3fae1280af89dce85..733d81af1ffc11b7676767ad07e6cade8a1ecc9f 100644 (file)
@@ -16,8 +16,6 @@ import io.netty.channel.ChannelInitializer;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.local.LocalAddress;
 import io.netty.channel.local.LocalChannel;
-import io.netty.util.concurrent.GenericFutureListener;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.InetSocketAddress;
@@ -63,11 +61,13 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:hiddenField")
     public void setIoInputStream(final IoInputStream in) {
         this.in = in;
     }
 
     @Override
+    @SuppressWarnings("checkstyle:hiddenField")
     public void setIoOutputStream(final IoOutputStream out) {
         this.out = out;
     }
@@ -78,11 +78,13 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:hiddenField")
     public void setInputStream(final InputStream in) {
         throw new UnsupportedOperationException("Synchronous IO is unsupported");
     }
 
     @Override
+    @SuppressWarnings("checkstyle:hiddenField")
     public void setOutputStream(final OutputStream out) {
         throw new UnsupportedOperationException("Synchronous IO is unsupported");
 
@@ -95,12 +97,13 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:hiddenField")
     public void setExitCallback(final ExitCallback callback) {
         this.callback = callback;
     }
 
     @Override
-    public void start(final Environment env) throws IOException {
+    public void start(final Environment env) {
         LOG.trace("Establishing internal connection to netconf server for client: {}", getClientAddress());
 
         final Bootstrap clientBootstrap = new Bootstrap();
@@ -108,25 +111,21 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
 
         clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
             @Override
-            public void initChannel(final LocalChannel ch) throws Exception {
+            public void initChannel(final LocalChannel ch) {
                 ch.pipeline()
                         .addLast(new SshProxyClientHandler(in, out, netconfHelloMessageAdditionalHeader, callback));
             }
         });
         clientChannelFuture = clientBootstrap.connect(localAddress);
-        clientChannelFuture.addListener(new GenericFutureListener<ChannelFuture>() {
-
-            @Override
-            public void operationComplete(final ChannelFuture future) throws Exception {
-                if (future.isSuccess()) {
-                    clientChannel = clientChannelFuture.channel();
-                } else {
-                    LOG.warn("Unable to establish internal connection to netconf server for client: {}",
-                            getClientAddress());
-                    Preconditions.checkNotNull(callback, "Exit callback must be set");
-                    callback.onExit(1, "Unable to establish internal connection to netconf server for client: "
-                            + getClientAddress());
-                }
+        clientChannelFuture.addListener(future -> {
+            if (future.isSuccess()) {
+                clientChannel = clientChannelFuture.channel();
+            } else {
+                LOG.warn("Unable to establish internal connection to netconf server for client: {}",
+                        getClientAddress());
+                Preconditions.checkNotNull(callback, "Exit callback must be set");
+                callback.onExit(1, "Unable to establish internal connection to netconf server for client: "
+                        + getClientAddress());
             }
         });
     }
@@ -138,14 +137,10 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
 
         clientChannelFuture.cancel(true);
         if (clientChannel != null) {
-            clientChannel.close().addListener(new GenericFutureListener<ChannelFuture>() {
-
-                @Override
-                public void operationComplete(final ChannelFuture future) throws Exception {
-                    if (future.isSuccess() == false) {
-                        LOG.warn("Unable to release internal connection to netconf server on channel: {}",
-                                clientChannel);
-                    }
+            clientChannel.close().addListener(future -> {
+                if (!future.isSuccess()) {
+                    LOG.warn("Unable to release internal connection to netconf server on channel: {}",
+                            clientChannel);
                 }
             });
         }