Refactor TcpConnectionInitializer 31/111831/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 23 May 2024 14:54:25 +0000 (16:54 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 23 May 2024 14:58:03 +0000 (16:58 +0200)
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 <robert.varga@pantheon.tech>
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/ServerFacade.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpConnectionInitializer.java

index 6a0fa1ab6c35a23e25ce9e416b1e454c4f7db179..57333a375e25cc26e418464642b4c24719d6850c 100644 (file)
@@ -13,5 +13,6 @@ package org.opendaylight.openflowjava.protocol.impl.core;
  * @author mirehak
  */
 public interface ServerFacade extends ShutdownProvider, OnlineProvider, Runnable {
-
+    @Override
+    void run();
 }
index abd3af6eb8b14d5e3c3718a22a11b458f6997178..6c12edf9922aa48b4316550a3abc51f097d92431 100755 (executable)
@@ -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 -> {
index 35495408890cfd2c0d64a1dfa1f549811b588bb3..7272302371b568bb1a8e408610f8d5eebd347178 100644 (file)
@@ -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<Void> 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<Boolean> shutdown() {
-        final var result = SettableFuture.<Boolean>create();
-        workerGroup.shutdownGracefully();
-        return result;
-    }
-
-    @Override
-    public ListenableFuture<Void> 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;
-    }
 }