From dba0f07c72be047ece4ca82ade4e71bcc38e7cbf Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 23 May 2024 16:54:25 +0200 Subject: [PATCH] Refactor TcpConnectionInitializer TcpConnectionInitializer is *not* a ServerFacade, disconnect it from that interface and eliminate all dead code. While we are at it, make sure to define ServerFacade.run() to make it easy to see the actual implementations. Change-Id: Ied7fc8ccacadf8a27f995ebc9553b88a281f6553 Signed-off-by: Robert Varga (cherry picked from commit acb41d869c8f1e253e18b9a973cb79e4ef6228ec) --- .../protocol/impl/core/ServerFacade.java | 3 +- .../core/SwitchConnectionProviderImpl.java | 5 +- .../impl/core/TcpConnectionInitializer.java | 52 +++---------------- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/ServerFacade.java b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/ServerFacade.java index 6a0fa1ab6c..57333a375e 100644 --- a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/ServerFacade.java +++ b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/ServerFacade.java @@ -13,5 +13,6 @@ package org.opendaylight.openflowjava.protocol.impl.core; * @author mirehak */ public interface ServerFacade extends ShutdownProvider, OnlineProvider, Runnable { - + @Override + void run(); } diff --git a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java index abd3af6eb8..6c12edf992 100755 --- a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java +++ b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java @@ -209,9 +209,8 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C tcpHandler.setChannelInitializer(channelInitializer); tcpHandler.initiateEventLoopGroups(connConfig.getThreadConfiguration(), isEpollEnabled); final var workerGroupFromTcpHandler = tcpHandler.getWorkerGroup(); - connectionInitializer = new TcpConnectionInitializer(workerGroupFromTcpHandler, isEpollEnabled); - connectionInitializer.setChannelInitializer(channelInitializer); - connectionInitializer.run(); + connectionInitializer = new TcpConnectionInitializer(workerGroupFromTcpHandler, channelInitializer, + isEpollEnabled); yield tcpHandler; } case UDP -> { diff --git a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpConnectionInitializer.java b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpConnectionInitializer.java index 3549540889..7272302371 100644 --- a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpConnectionInitializer.java +++ b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpConnectionInitializer.java @@ -9,8 +9,6 @@ package org.opendaylight.openflowjava.protocol.impl.core; import static java.util.Objects.requireNonNull; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.SettableFuture; import io.netty.bootstrap.Bootstrap; import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.EpollSocketChannel; @@ -23,47 +21,17 @@ import org.slf4j.LoggerFactory; * * @author martin.uhlir */ -public class TcpConnectionInitializer implements ServerFacade, ConnectionInitializer { +final class TcpConnectionInitializer implements ConnectionInitializer { private static final Logger LOG = LoggerFactory.getLogger(TcpConnectionInitializer.class); - private final SettableFuture hasRun = SettableFuture.create(); - private final EventLoopGroup workerGroup; - private final boolean isEpollEnabled; + private final Bootstrap bootstrap; - private TcpChannelInitializer channelInitializer; - private Bootstrap bootstrap; - - /** - * Constructor. - * - * @param workerGroup - shared worker group - */ - public TcpConnectionInitializer(final EventLoopGroup workerGroup, final boolean isEpollEnabled) { - this.workerGroup = requireNonNull(workerGroup, "WorkerGroup can't be null"); - this.isEpollEnabled = isEpollEnabled; - } - - @Override - public void run() { - bootstrap = new Bootstrap(); - if (isEpollEnabled) { - bootstrap.group(workerGroup).channel(EpollSocketChannel.class).handler(channelInitializer); - } else { - bootstrap.group(workerGroup).channel(NioSocketChannel.class).handler(channelInitializer); - } - hasRun.set(null); - } - - @Override - public ListenableFuture shutdown() { - final var result = SettableFuture.create(); - workerGroup.shutdownGracefully(); - return result; - } - - @Override - public ListenableFuture getIsOnlineFuture() { - return hasRun; + TcpConnectionInitializer(final EventLoopGroup workerGroup, final TcpChannelInitializer channelInitializer, + final boolean isEpollEnabled) { + bootstrap = new Bootstrap() + .group(requireNonNull(workerGroup, "WorkerGroup cannot be null")) + .handler(channelInitializer) + .channel(isEpollEnabled ? EpollSocketChannel.class : NioSocketChannel.class); } @Override @@ -74,8 +42,4 @@ public class TcpConnectionInitializer implements ServerFacade, ConnectionInitial LOG.error("Unable to initiate connection", e); } } - - public void setChannelInitializer(final TcpChannelInitializer channelInitializer) { - this.channelInitializer = channelInitializer; - } } -- 2.36.6