martinzink commented on code in PR #2221: URL: https://github.com/apache/nifi-minifi-cpp/pull/2221#discussion_r3842334155
########## extensions/standard-processors/processors/JoinEnrichmentAttributes.h: ########## @@ -0,0 +1,139 @@ +/** + * 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 <memory> +#include <string> + +#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 MapType = std::unordered_map<std::string, std::shared_ptr<core::FlowFile>, utils::string::transparent_string_hash, std::equal_to<>>; Review Comment: 👍 https://github.com/apache/nifi-minifi-cpp/pull/2221/changes/074a90bbed1383dde9af0383bb3c4063456a01cb#diff-328942b134e20b3cc74348741cdfc3d529c1305195f9df4f84d4f6937a143c0aR76 ? -- 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]
