exceptionfactory commented on a change in pull request #5560:
URL: https://github.com/apache/nifi/pull/5560#discussion_r782549075



##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/configuration/ConnectionTimeout.java
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.configuration;
+
+import java.time.Duration;
+
+public enum ConnectionTimeout {

Review comment:
       Is this class used?  There do not appear to be any other references.

##########
File path: nifi-nar-bundles/nifi-extension-utils/nifi-event-transport/pom.xml
##########
@@ -39,5 +39,21 @@
             <version>1.16.0-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-standard-record-utils</artifactId>
+            <version>1.16.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-record-serialization-service-api</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-record</artifactId>
+            <scope>compile</scope>
+        </dependency>

Review comment:
       What do you think about creating a new `nifi-record-event-transport` 
module with these dependencies?  That would avoid introducing the 
record-oriented dependencies into this module when they are not needed 
elsewhere.  That also avoids introducing unnecessary transitive dependencies in 
modules that already depend on `nifi-event-transport`.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCPRecord.java
##########
@@ -136,11 +141,15 @@ public void testRunOneRecordPerFlowFile() throws 
IOException, InterruptedExcepti
         }
     }
 
-    @Test(timeout = TEST_TIMEOUT)
-    public void testRunMultipleRecordsPerFlowFileLessThanBatchSize() throws 
IOException, InterruptedException {
+    @Test
+    public void testRunMultipleRecordsPerFlowFileLessThanBatchSize() throws 
Exception {
         runner.setProperty(ListenTCPRecord.RECORD_BATCH_SIZE, "5");
 
-        run(1, null);
+        //runner.run(1, false, true);

Review comment:
       Can this commented line be removed?

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/netty/channel/RecordReaderHandler.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.channel;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.timeout.ReadTimeoutException;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.serialization.RecordReaderFactory;
+
+import java.io.BufferedInputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.net.SocketAddress;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Record Reader Handler will create piped input streams for a network based 
record reader, providing a mechanism for processors
+ * like ListenTCPRecord to read data received by a Netty server.
+ */
[email protected]
+public class RecordReaderHandler extends SimpleChannelInboundHandler<ByteBuf> {
+    private final RecordReaderFactory readerFactory;
+    private final BlockingQueue<NetworkRecordReader> recordReaders;
+    private final ComponentLog logger;
+    private PipedOutputStream fromChannel;
+    private PipedInputStream toReader;
+
+    public RecordReaderHandler(final RecordReaderFactory readerFactory, final 
BlockingQueue<NetworkRecordReader> recordReaders, final ComponentLog logger) {
+        this.logger = logger;
+        this.readerFactory = readerFactory;
+        this.recordReaders = recordReaders;
+    }
+
+    @Override
+    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws 
Exception {
+         fromChannel.write(ByteBufUtil.getBytes(msg));
+         fromChannel.flush();
+    }
+
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+        super.channelInactive(ctx);
+        fromChannel.close();
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) throws Exception {
+        final SocketAddress remoteSender = ctx.channel().remoteAddress();
+        fromChannel = new PipedOutputStream();

Review comment:
       Should this be instantiated in the constructor to avoid theoretical 
NullPointerExceptions?

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/netty/channel/NetworkRecordReader.java
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.channel;
+
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.schema.access.SchemaNotFoundException;
+import org.apache.nifi.serialization.MalformedRecordException;
+import org.apache.nifi.serialization.RecordReader;
+import org.apache.nifi.serialization.RecordReaderFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.SocketAddress;
+
+public class NetworkRecordReader implements Closeable {

Review comment:
       The naming of this class is a bit confusing given the other Record 
Reader interfaces and classes.  It seems to equate to a connection or session.  
What do you think about renaming it to `RecordReaderSession`? In light of the 
usage within the ListenTCPRecord processor, it also seems worthwhile to 
consider defining an interface, with this class as the implementation.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenTCPRecord.java
##########
@@ -393,6 +359,7 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
                         // if discarding then bounce to the outer catch block 
which will close the connection and remove the flow file
                         // if keeping then null out the record to break out of 
the loop, which will transfer what we have and close the connection
                         try {
+                            getLogger().debug("Reading next record from 
recordReader");

Review comment:
       It seems like this debug line could generate a lot of output when 
enabled.  Since it does not provide any additional details, is it helpful, or 
should it be removed?

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/netty/NettyEventServerFactory.java
##########
@@ -156,6 +156,7 @@ private void setChannelOptions(final AbstractBootstrap<?, 
?> bootstrap) {
             bootstrap.option(ChannelOption.SO_RCVBUF, socketReceiveBuffer);
             bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new 
FixedRecvByteBufAllocator(socketReceiveBuffer));
         }
+

Review comment:
       Minor detail, but it seems like this change could be reverted.

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-event-transport/src/main/java/org/apache/nifi/event/transport/netty/channel/RecordReaderHandler.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.channel;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.timeout.ReadTimeoutException;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.serialization.RecordReaderFactory;
+
+import java.io.BufferedInputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.net.SocketAddress;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Record Reader Handler will create piped input streams for a network based 
record reader, providing a mechanism for processors
+ * like ListenTCPRecord to read data received by a Netty server.
+ */
[email protected]

Review comment:
       It does not seem like this Handler can be shareable since the streams 
are specific to a particular connection, and the instantiation of this class 
does not appear to use it in a sharable way. It looks like this annotation 
should be removed.




-- 
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