fgerlits commented on code in PR #1443: URL: https://github.com/apache/nifi-minifi-cpp/pull/1443#discussion_r1072139551
########## extensions/standard-processors/controllers/VolatileMapStateStorage.cpp: ########## @@ -0,0 +1,76 @@ +/** + * 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 "VolatileMapStateStorage.h" +#include "core/PropertyBuilder.h" +#include "core/Resource.h" + +namespace org::apache::nifi::minifi::controllers { + +const core::Property VolatileMapStateStorage::LinkedServices( + core::PropertyBuilder::createProperty("Linked Services") + ->withDescription("Referenced Controller Services") + ->build()); + +VolatileMapStateStorage::VolatileMapStateStorage(const std::string& name, const utils::Identifier& uuid /*= utils::Identifier()*/) + : KeyValueStateStorage(name, uuid) { +} + +VolatileMapStateStorage::VolatileMapStateStorage(const std::string& name, const std::shared_ptr<Configure> &configuration) + : KeyValueStateStorage(name) { + setConfiguration(configuration); +} + +void VolatileMapStateStorage::initialize() { + ControllerService::initialize(); + setSupportedProperties(properties()); +} + +bool VolatileMapStateStorage::set(const std::string& key, const std::string& value) { + std::lock_guard<std::mutex> lock(mutex_); + return storage_.set(key, value); +} + +bool VolatileMapStateStorage::get(const std::string& key, std::string& value) { + std::lock_guard<std::mutex> lock(mutex_); + return storage_.get(key, value); +} + +bool VolatileMapStateStorage::get(std::unordered_map<std::string, std::string>& kvs) { + std::lock_guard<std::mutex> lock(mutex_); + return storage_.get(kvs); +} + +bool VolatileMapStateStorage::remove(const std::string& key) { + std::lock_guard<std::mutex> lock(mutex_); + return storage_.remove(key); +} + +bool VolatileMapStateStorage::clear() { + std::lock_guard<std::mutex> lock(mutex_); + return storage_.clear(); +} + +bool VolatileMapStateStorage::update(const std::string& key, const std::function<bool(bool /*exists*/, std::string& /*value*/)>& update_func) { + std::lock_guard<std::mutex> lock(mutex_); + return storage_.update(key, update_func); +} + +// TODO(fgerlits): old names are kept as aliases for backward compatibility; remove in version 1.0 +REGISTER_RESOURCE_AS(VolatileMapStateStorage, ControllerService, ("UnorderedMapKeyValueStoreService", "VolatileMapStateStorage")); Review Comment: I have removed the TODOs in 59b3d220e0756cffa972f8a8a53345cfeb0ec0f3. I still think we should remove this old baggage as part of the 1.0 release, but we can discuss that when it happens, no need to hold up this PR because of it. -- 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]
