Simplify code using Java 8 features
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / AbstractNetconfSessionNegotiator.java
index 4135896b34d28361a4a9fd6f19d6e09864fccdcc..d9c15ae03578052a079bc157d44d2e7e9dcb6e1e 100644 (file)
@@ -19,7 +19,6 @@ import io.netty.handler.ssl.SslHandler;
 import io.netty.util.Timeout;
 import io.netty.util.Timer;
 import io.netty.util.TimerTask;
-import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.Promise;
 import java.util.concurrent.TimeUnit;
@@ -84,14 +83,10 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
         } else {
             final Optional<SslHandler> sslHandler = getSslHandler(channel);
             if (sslHandler.isPresent()) {
-                Future<Channel> future = sslHandler.get().handshakeFuture();
-                future.addListener(new GenericFutureListener<Future<? super Channel>>() {
-                    @Override
-                    public void operationComplete(final Future<? super Channel> future) {
-                        Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful");
-                        LOG.debug("Ssl handshake complete");
-                        start();
-                    }
+                sslHandler.get().handshakeFuture().addListener(future -> {
+                    Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful");
+                    LOG.debug("Ssl handshake complete");
+                    start();
                 });
             } else {
                 start();
@@ -106,7 +101,7 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
 
     private static Optional<SslHandler> getSslHandler(final Channel channel) {
         final SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
-        return sslHandler == null ? Optional.<SslHandler>absent() : Optional.of(sslHandler);
+        return sslHandler == null ? Optional.absent() : Optional.of(sslHandler);
     }
 
     public P getSessionPreferences() {
@@ -139,14 +134,11 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
                             LOG.warn("Netconf session was not established after {}", connectionTimeoutMillis);
                             changeState(State.FAILED);
 
-                            channel.close().addListener(new GenericFutureListener<ChannelFuture>() {
-                                @Override
-                                public void operationComplete(final ChannelFuture future) throws Exception {
-                                    if (future.isSuccess()) {
-                                        LOG.debug("Channel {} closed: success", future.channel());
-                                    } else {
-                                        LOG.warn("Channel {} closed: fail", future.channel());
-                                    }
+                            channel.close().addListener((GenericFutureListener<ChannelFuture>) future -> {
+                                if (future.isSuccess()) {
+                                    LOG.debug("Channel {} closed: success", future.channel());
+                                } else {
+                                    LOG.warn("Channel {} closed: fail", future.channel());
                                 }
                             });
                         }