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



##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/relp/frame/RELPMessageChannelHandler.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.processors.standard.relp.frame;
+
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import org.apache.nifi.processors.standard.relp.event.RELPMessage;
+import org.apache.nifi.processors.standard.relp.response.RELPChannelResponse;
+import org.apache.nifi.processors.standard.relp.response.RELPResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.Charset;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Decode data received into a RELPMessage
+ */
[email protected]
+public class RELPMessageChannelHandler extends 
SimpleChannelInboundHandler<RELPMessage> {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RELPMessageChannelHandler.class);
+    private final BlockingQueue<RELPMessage> events;
+    private final RELPEncoder encoder;
+
+    public RELPMessageChannelHandler(BlockingQueue<RELPMessage> events, final 
Charset charset) {
+        this.events = events;
+        this.encoder = new RELPEncoder(charset);
+    }
+
+    @Override
+    protected void channelRead0(ChannelHandlerContext ctx, RELPMessage msg) {
+        LOGGER.debug("RELP Message Received Length [{}] Remote Address [{}] ", 
msg.getMessage().length, msg.getSender());
+        if (events.offer(msg)) {
+            LOGGER.debug("Added RELP message to event queue");

Review comment:
       Recommend including the sender in the log for tracking:
   ```suggestion
               LOGGER.debug("Event Queued: RELP Message Sender [{}] Transaction 
Number [{}]", msg.getSender(), msg.getTxnr());
   ```

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/relp/frame/RELPMessageChannelHandler.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.processors.standard.relp.frame;
+
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import org.apache.nifi.processors.standard.relp.event.RELPMessage;
+import org.apache.nifi.processors.standard.relp.response.RELPChannelResponse;
+import org.apache.nifi.processors.standard.relp.response.RELPResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.Charset;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Decode data received into a RELPMessage
+ */
[email protected]
+public class RELPMessageChannelHandler extends 
SimpleChannelInboundHandler<RELPMessage> {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RELPMessageChannelHandler.class);
+    private final BlockingQueue<RELPMessage> events;
+    private final RELPEncoder encoder;
+
+    public RELPMessageChannelHandler(BlockingQueue<RELPMessage> events, final 
Charset charset) {
+        this.events = events;
+        this.encoder = new RELPEncoder(charset);
+    }
+
+    @Override
+    protected void channelRead0(ChannelHandlerContext ctx, RELPMessage msg) {
+        LOGGER.debug("RELP Message Received Length [{}] Remote Address [{}] ", 
msg.getMessage().length, msg.getSender());
+        if (events.offer(msg)) {
+            LOGGER.debug("Added RELP message to event queue");
+            ctx.writeAndFlush(Unpooled.wrappedBuffer(new 
RELPChannelResponse(encoder, RELPResponse.ok(msg.getTxnr())).toByteArray()));
+        } else {
+            LOGGER.debug("Failed to add RELP message to event queue because 
queue was full");

Review comment:
       ```suggestion
               LOGGER.debug("Event Queue Full: Failed RELP Message Sender [{}] 
Transaction Number [{}]", msg.getSender(), msg.getTxnr());
   ```

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenRELP.java
##########
@@ -209,15 +254,79 @@ protected void respond(final RELPEvent event, final 
RELPResponse relpResponse) {
         return attributes;
     }
 
-    @Override
-    protected String getTransitUri(FlowFileEventBatch batch) {
-        final String sender = batch.getEvents().get(0).getSender();
+    protected String getTransitUri(FlowFileNettyEventBatch batch) {
+        final List<RELPNettyEvent> events = batch.getEvents();
+        final String sender = events.get(0).getSender();
         final String senderHost = sender.startsWith("/") && sender.length() > 
1 ? sender.substring(1) : sender;
         final String transitUri = new 
StringBuilder().append("relp").append("://").append(senderHost).append(":")
                 .append(port).toString();
         return transitUri;
     }
 
+    @Override
+    public void onTrigger(ProcessContext context, ProcessSession session) 
throws ProcessException {
+        EventBatcher eventBatcher = new 
EventBatcher<RELPNettyEvent>(getLogger(), events, errorEvents) {
+            @Override
+            protected String getBatchKey(RELPNettyEvent event) {
+                return getRELPBatchKey(event);
+            }
+        };
+
+        final int batchSize = 
context.getProperty(AbstractListenEventBatchingProcessor.MAX_BATCH_SIZE).asInteger();
+        Map<String, FlowFileNettyEventBatch> batches = 
eventBatcher.getBatches(session, batchSize, messageDemarcatorBytes);
+
+        final List<RELPNettyEvent> eventsAwaitingResponse = new ArrayList<>();
+        getEventsAwaitingResponse(session, batches, eventsAwaitingResponse);
+        respondToEvents(session, eventsAwaitingResponse);
+    }
+
+    private void getEventsAwaitingResponse(final ProcessSession session, final 
Map<String, FlowFileNettyEventBatch> batches, final List<RELPNettyEvent> 
allEvents) {
+        for (Map.Entry<String, FlowFileNettyEventBatch> entry : 
batches.entrySet()) {
+            FlowFile flowFile = entry.getValue().getFlowFile();
+            final List<RELPNettyEvent> events = entry.getValue().getEvents();
+
+            if (flowFile.getSize() == 0L || events.size() == 0) {
+                session.remove(flowFile);
+                getLogger().debug("No data written to FlowFile from batch {}; 
removing FlowFile", new Object[] {entry.getKey()});

Review comment:
       It looks like the `Object[]` still needs to be removed.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenRELP.java
##########
@@ -127,67 +188,31 @@ public void onScheduled(ProcessContext context) throws 
IOException {
         return results;
     }
 
-    @Override
-    protected ChannelDispatcher createDispatcher(final ProcessContext context, 
final BlockingQueue<RELPEvent> events) throws IOException {
-        final EventFactory<RELPEvent> eventFactory = new RELPEventFactory();
-        final ChannelHandlerFactory<RELPEvent,AsyncChannelDispatcher> 
handlerFactory = new RELPSocketChannelHandlerFactory<>();
-
-        final int maxConnections = 
context.getProperty(MAX_CONNECTIONS).asInteger();
-        final int bufferSize = 
context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
-        final Charset charSet = 
Charset.forName(context.getProperty(CHARSET).getValue());
-
-        // initialize the buffer pool based on max number of connections and 
the buffer size
-        final ByteBufferSource byteBufferSource = new 
ByteBufferPool(maxConnections, bufferSize);
-
-        // if an SSLContextService was provided then create an SSLContext to 
pass down to the dispatcher
-        SSLContext sslContext = null;
-        ClientAuth clientAuth = null;
-
-        final SSLContextService sslContextService = 
context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
-        if (sslContextService != null) {
-            final String clientAuthValue = 
context.getProperty(CLIENT_AUTH).getValue();
-            sslContext = sslContextService.createContext();
-            clientAuth = ClientAuth.valueOf(clientAuthValue);
+    private void initializeRelpServer() {
+        final NettyEventServerFactory eventFactory = 
getNettyEventServerFactory();
+        eventFactory.setSocketReceiveBuffer(bufferSize);
+        if (sslContext != null) {
+            eventFactory.setSslContext(sslContext);
+        }
+        try {
+            eventServer = eventFactory.getEventServer();
+        } catch (EventException e) {
+            getLogger().debug("Failed to bind to [{}:{}].", 
hostname.getHostAddress(), port);

Review comment:
       Should this be changed to a warning or error message? Also recommend 
removing the trailing period and adding the exception to the log:
   ```suggestion
               getLogger().error("Failed to bind to [{}:{}]", 
hostname.getHostAddress(), port, e);
   ```

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenRELP.java
##########
@@ -209,15 +254,79 @@ protected void respond(final RELPEvent event, final 
RELPResponse relpResponse) {
         return attributes;
     }
 
-    @Override
-    protected String getTransitUri(FlowFileEventBatch batch) {
-        final String sender = batch.getEvents().get(0).getSender();
+    protected String getTransitUri(FlowFileNettyEventBatch batch) {
+        final List<RELPNettyEvent> events = batch.getEvents();
+        final String sender = events.get(0).getSender();
         final String senderHost = sender.startsWith("/") && sender.length() > 
1 ? sender.substring(1) : sender;
         final String transitUri = new 
StringBuilder().append("relp").append("://").append(senderHost).append(":")
                 .append(port).toString();
         return transitUri;
     }
 
+    @Override
+    public void onTrigger(ProcessContext context, ProcessSession session) 
throws ProcessException {
+        EventBatcher eventBatcher = new 
EventBatcher<RELPNettyEvent>(getLogger(), events, errorEvents) {
+            @Override
+            protected String getBatchKey(RELPNettyEvent event) {
+                return getRELPBatchKey(event);
+            }
+        };
+
+        final int batchSize = 
context.getProperty(AbstractListenEventBatchingProcessor.MAX_BATCH_SIZE).asInteger();
+        Map<String, FlowFileNettyEventBatch> batches = 
eventBatcher.getBatches(session, batchSize, messageDemarcatorBytes);
+
+        final List<RELPNettyEvent> eventsAwaitingResponse = new ArrayList<>();
+        getEventsAwaitingResponse(session, batches, eventsAwaitingResponse);
+        respondToEvents(session, eventsAwaitingResponse);
+    }
+
+    private void getEventsAwaitingResponse(final ProcessSession session, final 
Map<String, FlowFileNettyEventBatch> batches, final List<RELPNettyEvent> 
allEvents) {
+        for (Map.Entry<String, FlowFileNettyEventBatch> entry : 
batches.entrySet()) {
+            FlowFile flowFile = entry.getValue().getFlowFile();
+            final List<RELPNettyEvent> events = entry.getValue().getEvents();
+
+            if (flowFile.getSize() == 0L || events.size() == 0) {
+                session.remove(flowFile);
+                getLogger().debug("No data written to FlowFile from batch {}; 
removing FlowFile", new Object[] {entry.getKey()});
+                continue;
+            }
+
+            final Map<String,String> attributes = 
getAttributes(entry.getValue());
+            flowFile = session.putAllAttributes(flowFile, attributes);
+
+            getLogger().debug("Transferring {} to success", new Object[] 
{flowFile});

Review comment:
       It looks like the `Object[]` still needs to 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