martinzink commented on code in PR #2221: URL: https://github.com/apache/nifi-minifi-cpp/pull/2221#discussion_r4313162516
########## extensions/standard-processors/processors/JoinEnrichmentAttributes.h: ########## @@ -0,0 +1,147 @@ +/** + * 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. + */ + +#pragma once + +#include <array> +#include <chrono> +#include <deque> +#include <functional> +#include <memory> +#include <optional> +#include <string> +#include <unordered_map> +#include <utility> +#include <vector> + +#include "core/FlowFileStore.h" +#include "core/ProcessorImpl.h" +#include "core/PropertyDefinitionBuilder.h" +#include "minifi-cpp/core/PropertyDefinition.h" +#include "utils/Enum.h" +#include "utils/RegexUtils.h" + +namespace org::apache::nifi::minifi::standard { + +namespace join_enrichment_attributes { +class TimeOutTracker { + public: + explicit TimeOutTracker(std::chrono::steady_clock::duration timeout) : time_out_(timeout) { + } + TimeOutTracker(const TimeOutTracker&) = delete; + TimeOutTracker& operator=(const TimeOutTracker&) = delete; + TimeOutTracker(TimeOutTracker&&) = delete; + TimeOutTracker& operator=(TimeOutTracker&&) = delete; + ~TimeOutTracker() = default; + + void track(std::string id, std::chrono::steady_clock::time_point timestamp) { + queue_.emplace_back(timestamp, std::move(id)); + } + + std::vector<std::string> getTimedOutFlowFiles(std::chrono::steady_clock::time_point current_time) { + std::vector<std::string> result; + // Even with 0 time_out_, we won't return just added FlowFiles + while (!queue_.empty() && queue_.front().timestamp + time_out_ < current_time) { + result.push_back(std::move(queue_.front().group_name)); + queue_.pop_front(); + } + return result; + } + + private: + struct TimeStampedGroup { + std::chrono::steady_clock::time_point timestamp; + std::string group_name; + }; + + std::chrono::steady_clock::duration time_out_; + std::deque<TimeStampedGroup> queue_; +}; +} // namespace join_enrichment_attributes + +using StoredFlowFileMap = std::unordered_map<std::string, std::shared_ptr<core::FlowFile>, utils::string::transparent_string_hash, std::equal_to<>>; + +class JoinEnrichmentAttributes : public core::ProcessorImpl { + public: + using ProcessorImpl::ProcessorImpl; + + EXTENSIONAPI static constexpr const char* Description = + "Rejoins the forked FlowFiles coming from ForkEnrichment processor, the resulting FlowFile will have the Original's content and all attributes " + "from both of them (prioritizing Enrichment's)."; + + EXTENSIONAPI static constexpr auto Invalid = core::RelationshipDefinition{"invalid", + "Any FlowFiles without the requisite attributes will be routed here"}; + EXTENSIONAPI static constexpr auto Joined = core::RelationshipDefinition{"joined", + "The resultant FlowFile with Records joined together from both the original and enrichment FlowFiles will be routed to this relationship"}; Review Comment: https://github.com/apache/nifi-minifi-cpp/pull/2221/changes/4edec1d88de5d73eab1989dcf007b4bfeb898d2b#diff-dee0424f7be326b97e7709829ad2746673fc90baef0b884061c3462e7d175ab9R10010 -- 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]
