From e6c43b6deeb1da7b0557e5d59f9265e88c73ad83 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20de=20Talhou=C3=ABt?= Date: Mon, 19 Sep 2016 22:53:34 -0400 Subject: [PATCH] Clean-up netconf-client MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Use lambda or method ref Change-Id: I02c6b7a13d90119de061cca0f552c565f18e4862 Signed-off-by: Alexis de Talhouët --- .../client/NetconfClientDispatcherImpl.java | 44 +++---------------- .../client/SshClientChannelInitializer.java | 8 +--- .../client/TcpClientChannelInitializer.java | 32 +++++--------- 3 files changed, 18 insertions(+), 66 deletions(-) diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java index 8b94b994fa..38635b1ec3 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java @@ -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 createTcpClient(final NetconfClientConfiguration currentConfiguration) { LOG.debug("Creating TCP client with configuration: {}", currentConfiguration); return super.createClient(currentConfiguration.getAddress(), currentConfiguration.getReconnectStrategy(), - new PipelineInitializer() { - - @Override - public void initializeChannel(final SocketChannel ch, final Promise promise) { - initialize(ch, promise); - } - - private void initialize(final SocketChannel ch, final Promise promise) { - new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration), currentConfiguration - .getSessionListener()).initialize(ch, promise); - } - }); + (ch, promise) -> new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration), currentConfiguration + .getSessionListener()).initialize(ch, promise)); } private Future createReconnectingTcpClient(final NetconfReconnectingClientConfiguration currentConfiguration) { @@ -81,28 +69,15 @@ public class NetconfClientDispatcherImpl extends AbstractDispatcher() { - @Override - public void initializeChannel(final SocketChannel ch, final Promise promise) { - init.initialize(ch, promise); - } - }); + currentConfiguration.getReconnectStrategy(), init::initialize); } private Future createSshClient(final NetconfClientConfiguration currentConfiguration) { LOG.debug("Creating SSH client with configuration: {}", currentConfiguration); return super.createClient(currentConfiguration.getAddress(), currentConfiguration.getReconnectStrategy(), - new PipelineInitializer() { - - @Override - public void initializeChannel(final SocketChannel ch, - final Promise 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 createReconnectingSshClient(final NetconfReconnectingClientConfiguration currentConfiguration) { @@ -111,12 +86,7 @@ public class NetconfClientDispatcherImpl extends AbstractDispatcher() { - @Override - public void initializeChannel(final SocketChannel ch, final Promise promise) { - init.initialize(ch, promise); - } - }); + init::initialize); } protected NetconfClientSessionNegotiatorFactory getNegotiatorFactory(final NetconfClientConfiguration cfg) { diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SshClientChannelInitializer.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SshClientChannelInitializer.java index fd335304c0..65a433fe16 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SshClientChannelInitializer.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SshClientChannelInitializer.java @@ -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 { @@ -44,11 +43,6 @@ final class SshClientChannelInitializer extends AbstractChannelInitializer promise) { ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR, - negotiatorFactory.getSessionNegotiator(new SessionListenerFactory() { - @Override - public NetconfClientSessionListener getSessionListener() { - return sessionListener; - } - }, ch, promise)); + negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise)); } } diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/TcpClientChannelInitializer.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/TcpClientChannelInitializer.java index 7558758efe..84f4bf9f32 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/TcpClientChannelInitializer.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/TcpClientChannelInitializer.java @@ -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 { @@ -47,24 +46,18 @@ class TcpClientChannelInitializer extends AbstractChannelInitializer>() { - @Override - public void operationComplete(final Future future) throws Exception { - if (future.isSuccess()) { - connectPromise.setSuccess(); - } + negotiationFutureListener = future -> { + if (future.isSuccess()) { + connectPromise.setSuccess(); } }; - tcpConnectFuture.addListener(new GenericFutureListener>() { - @Override - public void operationComplete(final Future 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 promise) { ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR, - negotiatorFactory.getSessionNegotiator(new SessionListenerFactory() { - @Override - public NetconfClientSessionListener getSessionListener() { - return sessionListener; - } - }, ch, promise)); + negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise)); } } -- 2.36.6