exceptionfactory commented on code in PR #8969:
URL: https://github.com/apache/nifi/pull/8969#discussion_r1641607016


##########
nifi-extension-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/netty/NettyEventServerFactory.java:
##########
@@ -202,14 +200,15 @@ private void setChannelOptions(final AbstractBootstrap<?, 
?> bootstrap) {
     }
 
     private AbstractBootstrap<?, ?> getBootstrap() {
+        NettyTransports.NettyTransport nettyTransport = 
this.getNettyTransport();

Review Comment:
   Instead of interacting with the `NettyTransport` record, it seems like this 
could be changed to have a `getDatagramChannelClass()` and 
`getServerSocketClass()` method that avoids exposing the record class itself.



##########
nifi-extension-bundles/nifi-extension-utils/nifi-event-transport/src/test/java/org/apache/nifi/event/transport/netty/NettyTransportsTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.event.transport.netty;
+
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.kqueue.KQueue;
+import java.util.List;
+import org.apache.commons.lang3.SystemUtils;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class NettyTransportsTest {
+  @Test
+  public void nioIsAvailable() {
+    assertTrue(NettyTransports.NIO.isAvailable());
+    assertTrue(NettyTransports.AVAILABLE_TRANSPORT_NAMES.contains("nio"));
+  }

Review Comment:
   This class should be changed to use four spaces instead of two spaces for 
indentation.



##########
nifi-extension-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/netty/EventLoopGroupFactory.java:
##########
@@ -35,6 +34,16 @@ class EventLoopGroupFactory {
 
     private int workerThreads;
 
+    private NettyTransports.NettyTransport nettyTransport;
+
+    public EventLoopGroupFactory() {
+        this(NettyTransports.getDefaultNettyTransport());
+    }
+
+    public EventLoopGroupFactory(NettyTransports.NettyTransport 
nettyTransport) {
+        this.nettyTransport = nettyTransport;
+    }

Review Comment:
   I recommend avoiding the addition of the parameterized constructor and 
instead use the availability determination logic in the get default method. 
Callers should not need to select a particular implementation, thus keeping the 
selection details private to this factory class.



##########
nifi-extension-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/netty/NettyTransports.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.event.transport.netty;
+
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollDatagramChannel;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerSocketChannel;
+import io.netty.channel.epoll.EpollSocketChannel;
+import io.netty.channel.kqueue.KQueue;
+import io.netty.channel.kqueue.KQueueDatagramChannel;
+import io.netty.channel.kqueue.KQueueEventLoopGroup;
+import io.netty.channel.kqueue.KQueueServerSocketChannel;
+import io.netty.channel.kqueue.KQueueSocketChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.DatagramChannel;
+import io.netty.channel.socket.ServerSocketChannel;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioDatagramChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import java.lang.reflect.Constructor;
+import java.util.List;
+import java.util.concurrent.ThreadFactory;
+import java.util.stream.Collectors;
+
+
+public class NettyTransports {
+  public record NettyTransport(String name,
+                               boolean isAvailable,
+                               Class<? extends EventLoopGroup> 
eventLoopGroupClass,
+                               Class<? extends ServerSocketChannel> 
serverSocketClass,
+                               Class<? extends SocketChannel> 
socketChannelClass,
+                               Class<? extends DatagramChannel> 
datagramChannelClass) {
+    public EventLoopGroup createEventLoopGroup(int workerThreads, 
ThreadFactory threadFactory) {
+      try {
+        Constructor<? extends EventLoopGroup> c = 
eventLoopGroupClass.getConstructor(Integer.TYPE, ThreadFactory.class);
+        return c.newInstance(workerThreads, threadFactory);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  public static final NettyTransport EPOLL = new NettyTransport("epoll", 
Epoll.isAvailable(),

Review Comment:
   With the approach to keep the selection logic internal to this module, it 
looks like most of the members of this class could have `private` or 
package-level visibility.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to