You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/10/06 14:31:26 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1188: MINIFICPP-1651: Added DefragTextFlowFiles processor

adamdebreceni commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r723339074



##########
File path: extensions/standard-processors/processors/DefragTextFlowFiles.cpp
##########
@@ -0,0 +1,336 @@
+/**
+ * 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.
+ */
+
+#include "DefragTextFlowFiles.h"
+
+#include <vector>
+
+#include "core/Resource.h"
+#include "serialization/PayloadSerializer.h"
+#include "utils/TextFragmentUtils.h"
+
+
+namespace org::apache::nifi::minifi::processors {
+
+core::Relationship DefragTextFlowFiles::Success("success", "Flowfiles that have no fragmented messages in them");
+core::Relationship DefragTextFlowFiles::Original("original", "The FlowFiles that were used to create the defragmented flowfiles");
+core::Relationship DefragTextFlowFiles::Failure("failure", "Flowfiles that failed the defragmentation process");
+core::Relationship DefragTextFlowFiles::Self("__self__", "Marks the FlowFile to be owned by this processor");
+
+core::Property DefragTextFlowFiles::Pattern(
+    core::PropertyBuilder::createProperty("Pattern")
+        ->withDescription("A regular expression to match at the start or end of messages.")
+        ->withDefaultValue("")->isRequired(true)->build());
+
+core::Property DefragTextFlowFiles::PatternLoc(
+    core::PropertyBuilder::createProperty("Pattern Location")->withDescription("Where to look for the pattern.")
+        ->withAllowableValues(PatternLocation::values())
+        ->withDefaultValue(toString(PatternLocation::START_OF_MESSAGE))->build());
+
+
+core::Property DefragTextFlowFiles::MaxBufferSize(
+    core::PropertyBuilder::createProperty("Max Buffer Size")
+        ->withDescription("The maximum buffer size, if the buffer exceeds this, it will be transferred to failure. Expected format is <size> <data unit>")
+        ->withType(core::StandardValidators::get().DATA_SIZE_VALIDATOR)->build());
+
+core::Property DefragTextFlowFiles::MaxBufferAge(
+    core::PropertyBuilder::createProperty("Max Buffer Age")->
+        withDescription("The maximum age of a buffer after which the buffer will be transferred to failure. Expected format is <duration> <time unit>")->build());
+
+void DefragTextFlowFiles::initialize() {
+  std::lock_guard<std::mutex> defrag_lock(defrag_mutex_);
+
+  setSupportedRelationships({Success, Original, Failure});
+  setSupportedProperties({Pattern, PatternLoc, MaxBufferAge, MaxBufferSize});
+}
+
+void DefragTextFlowFiles::onSchedule(core::ProcessContext* context, core::ProcessSessionFactory*) {
+  std::lock_guard<std::mutex> defrag_lock(defrag_mutex_);
+
+  std::string max_buffer_age_str;
+  if (context->getProperty(MaxBufferAge.getName(), max_buffer_age_str)) {
+    core::TimeUnit unit;
+    uint64_t max_buffer_age;
+    if (core::Property::StringToTime(max_buffer_age_str, max_buffer_age, unit) && core::Property::ConvertTimeUnitToMS(max_buffer_age, unit, max_buffer_age)) {
+      buffer_.setMaxAge(max_buffer_age);
+      logger_->log_trace("The Buffer maximum age is configured to be %d", max_buffer_age);

Review comment:
       we could add the unit here and to the buffer max size log as well




-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org