Merge "Clean-up netconf-client"
authorTomas Cere <tcere@cisco.com>
Mon, 24 Oct 2016 13:01:42 +0000 (13:01 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 24 Oct 2016 13:01:42 +0000 (13:01 +0000)
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SshClientChannelInitializer.java
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/TcpClientChannelInitializer.java

index 8b94b994fa622225dbe748a4a68b0398e00f0a6e..38635b1ec350bd071a83b92e759e488105c09179 100644 (file)
@@ -9,10 +9,8 @@
 package org.opendaylight.netconf.client;
 
 import io.netty.channel.EventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
 import io.netty.util.Timer;
 import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.Promise;
 import java.io.Closeable;
 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
@@ -61,18 +59,8 @@ public class NetconfClientDispatcherImpl extends AbstractDispatcher<NetconfClien
     private Future<NetconfClientSession> createTcpClient(final NetconfClientConfiguration currentConfiguration) {
         LOG.debug("Creating TCP client with configuration: {}", currentConfiguration);
         return super.createClient(currentConfiguration.getAddress(), currentConfiguration.getReconnectStrategy(),
-                new PipelineInitializer<NetconfClientSession>() {
-
-                    @Override
-                    public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
-                        initialize(ch, promise);
-                    }
-
-                    private void initialize(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
-                        new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration), currentConfiguration
-                                .getSessionListener()).initialize(ch, promise);
-                    }
-                });
+                (ch, promise) -> new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration), currentConfiguration
+                                .getSessionListener()).initialize(ch, promise));
     }
 
     private Future<Void> createReconnectingTcpClient(final NetconfReconnectingClientConfiguration currentConfiguration) {
@@ -81,28 +69,15 @@ public class NetconfClientDispatcherImpl extends AbstractDispatcher<NetconfClien
                 currentConfiguration.getSessionListener());
 
         return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration.getConnectStrategyFactory(),
-                currentConfiguration.getReconnectStrategy(), new PipelineInitializer<NetconfClientSession>() {
-                    @Override
-                    public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
-                        init.initialize(ch, promise);
-                    }
-                });
+                currentConfiguration.getReconnectStrategy(), init::initialize);
     }
 
     private Future<NetconfClientSession> createSshClient(final NetconfClientConfiguration currentConfiguration) {
         LOG.debug("Creating SSH client with configuration: {}", currentConfiguration);
         return super.createClient(currentConfiguration.getAddress(), currentConfiguration.getReconnectStrategy(),
-                new PipelineInitializer<NetconfClientSession>() {
-
-                    @Override
-                    public void initializeChannel(final SocketChannel ch,
-                                                  final Promise<NetconfClientSession> sessionPromise) {
-                        new SshClientChannelInitializer(currentConfiguration.getAuthHandler(),
-                                getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener())
-                                .initialize(ch, sessionPromise);
-                    }
-
-                });
+                (ch, sessionPromise) -> new SshClientChannelInitializer(currentConfiguration.getAuthHandler(),
+                        getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener())
+                        .initialize(ch, sessionPromise));
     }
 
     private Future<Void> createReconnectingSshClient(final NetconfReconnectingClientConfiguration currentConfiguration) {
@@ -111,12 +86,7 @@ public class NetconfClientDispatcherImpl extends AbstractDispatcher<NetconfClien
                 getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener());
 
         return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration.getConnectStrategyFactory(), currentConfiguration.getReconnectStrategy(),
-                new PipelineInitializer<NetconfClientSession>() {
-                    @Override
-                    public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
-                        init.initialize(ch, promise);
-                    }
-                });
+                init::initialize);
     }
 
     protected NetconfClientSessionNegotiatorFactory getNegotiatorFactory(final NetconfClientConfiguration cfg) {
index fd335304c0f1cee5d1b3345d0488c19cc8db49f6..65a433fe16d03dce4a4b024cbf0a98526e5631eb 100644 (file)
@@ -13,7 +13,6 @@ import java.io.IOException;
 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
-import org.opendaylight.protocol.framework.SessionListenerFactory;
 
 final class SshClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
 
@@ -44,11 +43,6 @@ final class SshClientChannelInitializer extends AbstractChannelInitializer<Netco
     protected void initializeSessionNegotiator(final Channel ch,
                                                final Promise<NetconfClientSession> promise) {
         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER,  AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
-                negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
-                    @Override
-                    public NetconfClientSessionListener getSessionListener() {
-                        return sessionListener;
-                    }
-                }, ch, promise));
+                negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise));
     }
 }
index 7558758efebecccbfe82990905860ed1e236faa8..84f4bf9f3238c54a91f75cb500ce0c1f79756222 100644 (file)
@@ -17,7 +17,6 @@ import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.Promise;
 import java.net.SocketAddress;
 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
-import org.opendaylight.protocol.framework.SessionListenerFactory;
 
 class TcpClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
 
@@ -47,24 +46,18 @@ class TcpClientChannelInitializer extends AbstractChannelInitializer<NetconfClie
                 connectPromise = channelPromise;
                 ChannelPromise tcpConnectFuture = new DefaultChannelPromise(ch);
 
-                negotiationFutureListener = new GenericFutureListener<Future<NetconfClientSession>>() {
-                    @Override
-                    public void operationComplete(final Future<NetconfClientSession> future) throws Exception {
-                        if (future.isSuccess()) {
-                            connectPromise.setSuccess();
-                        }
+                negotiationFutureListener = future -> {
+                    if (future.isSuccess()) {
+                        connectPromise.setSuccess();
                     }
                 };
 
-                tcpConnectFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
-                    @Override
-                    public void operationComplete(final Future<? super Void> future) throws Exception {
-                        if(future.isSuccess()) {
-                            //complete connection promise with netconf negotiation future
-                            negotiationFuture.addListener(negotiationFutureListener);
-                        } else {
-                            connectPromise.setFailure(future.cause());
-                        }
+                tcpConnectFuture.addListener(future -> {
+                    if(future.isSuccess()) {
+                        //complete connection promise with netconf negotiation future
+                        negotiationFuture.addListener(negotiationFutureListener);
+                    } else {
+                        connectPromise.setFailure(future.cause());
                     }
                 });
                 ctx.connect(remoteAddress, localAddress, tcpConnectFuture);
@@ -98,11 +91,6 @@ class TcpClientChannelInitializer extends AbstractChannelInitializer<NetconfClie
     @Override
     protected void initializeSessionNegotiator(final Channel ch, final Promise<NetconfClientSession> promise) {
         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
-                negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
-                    @Override
-                    public NetconfClientSessionListener getSessionListener() {
-                        return sessionListener;
-                    }
-                }, ch, promise));
+                negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise));
     }
 }