martinzink commented on code in PR #1429: URL: https://github.com/apache/nifi-minifi-cpp/pull/1429#discussion_r995625105
########## libminifi/src/core/ForwardingContentSession.cpp: ########## @@ -0,0 +1,62 @@ +/** + * + * 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 "core/ForwardingContentSession.h" + +#include <memory> + +#include "core/ContentRepository.h" +#include "ResourceClaim.h" +#include "io/BaseStream.h" +#include "Exception.h" + +namespace org::apache::nifi::minifi::core { + +ForwardingContentSession::ForwardingContentSession(std::shared_ptr<ContentRepository> repository) : repository_(std::move(repository)) {} + +std::shared_ptr<ResourceClaim> ForwardingContentSession::create() { + auto claim = std::make_shared<ResourceClaim>(repository_); + created_claims_.insert(claim); + return claim; +} + +std::shared_ptr<io::BaseStream> ForwardingContentSession::write(const std::shared_ptr<ResourceClaim>& resource_id) { + if (created_claims_.find(resource_id) == created_claims_.end()) { Review Comment: ```suggestion if (!created_claims_.contains(resource_id)) { ``` ########## libminifi/src/core/BufferedContentSession.cpp: ########## @@ -16,58 +16,57 @@ * limitations under the License. */ +#include "core/BufferedContentSession.h" #include <memory> #include "core/ContentRepository.h" -#include "core/ContentSession.h" #include "ResourceClaim.h" #include "io/BaseStream.h" #include "Exception.h" #include "utils/gsl.h" Review Comment: I think this `#include "utils/gsl.h"` is unused ########## libminifi/src/core/BufferedContentSession.cpp: ########## @@ -16,58 +16,57 @@ * limitations under the License. */ +#include "core/BufferedContentSession.h" #include <memory> #include "core/ContentRepository.h" -#include "core/ContentSession.h" #include "ResourceClaim.h" #include "io/BaseStream.h" #include "Exception.h" #include "utils/gsl.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { +namespace org::apache::nifi::minifi::core { -ContentSession::ContentSession(std::shared_ptr<ContentRepository> repository) : repository_(std::move(repository)) {} +BufferedContentSession::BufferedContentSession(std::shared_ptr<ContentRepository> repository) : repository_(std::move(repository)) {} -std::shared_ptr<ResourceClaim> ContentSession::create() { +std::shared_ptr<ResourceClaim> BufferedContentSession::create() { std::shared_ptr<ResourceClaim> claim = std::make_shared<ResourceClaim>(repository_); - managedResources_[claim] = std::make_shared<io::BufferStream>(); + managed_resources_[claim] = std::make_shared<io::BufferStream>(); return claim; } -std::shared_ptr<io::BaseStream> ContentSession::write(const std::shared_ptr<ResourceClaim>& resourceId, WriteMode mode) { - auto it = managedResources_.find(resourceId); - if (it == managedResources_.end()) { - if (mode == WriteMode::OVERWRITE) { - throw Exception(REPOSITORY_EXCEPTION, "Can only overwrite owned resource"); - } - auto& extension = extendedResources_[resourceId]; +std::shared_ptr<io::BaseStream> BufferedContentSession::write(const std::shared_ptr<ResourceClaim>& resource_id) { + auto it = managed_resources_.find(resource_id); + if (it == managed_resources_.end()) { + throw Exception(REPOSITORY_EXCEPTION, "Can only overwrite owned resource"); + } + it->second = std::make_shared<io::BufferStream>(); + return it->second; Review Comment: ```suggestion if (!managed_resources_.contains(resource_id)) throw Exception(REPOSITORY_EXCEPTION, "Can only overwrite owned resource"); return managed_resources_.at(resource_id) = std::make_shared<io::BufferStream>(); ``` ########## libminifi/src/core/BufferedContentSession.cpp: ########## @@ -16,58 +16,57 @@ * limitations under the License. */ +#include "core/BufferedContentSession.h" #include <memory> #include "core/ContentRepository.h" -#include "core/ContentSession.h" #include "ResourceClaim.h" #include "io/BaseStream.h" #include "Exception.h" #include "utils/gsl.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { +namespace org::apache::nifi::minifi::core { -ContentSession::ContentSession(std::shared_ptr<ContentRepository> repository) : repository_(std::move(repository)) {} +BufferedContentSession::BufferedContentSession(std::shared_ptr<ContentRepository> repository) : repository_(std::move(repository)) {} -std::shared_ptr<ResourceClaim> ContentSession::create() { +std::shared_ptr<ResourceClaim> BufferedContentSession::create() { std::shared_ptr<ResourceClaim> claim = std::make_shared<ResourceClaim>(repository_); - managedResources_[claim] = std::make_shared<io::BufferStream>(); + managed_resources_[claim] = std::make_shared<io::BufferStream>(); return claim; } -std::shared_ptr<io::BaseStream> ContentSession::write(const std::shared_ptr<ResourceClaim>& resourceId, WriteMode mode) { - auto it = managedResources_.find(resourceId); - if (it == managedResources_.end()) { - if (mode == WriteMode::OVERWRITE) { - throw Exception(REPOSITORY_EXCEPTION, "Can only overwrite owned resource"); - } - auto& extension = extendedResources_[resourceId]; +std::shared_ptr<io::BaseStream> BufferedContentSession::write(const std::shared_ptr<ResourceClaim>& resource_id) { + auto it = managed_resources_.find(resource_id); + if (it == managed_resources_.end()) { + throw Exception(REPOSITORY_EXCEPTION, "Can only overwrite owned resource"); + } + it->second = std::make_shared<io::BufferStream>(); + return it->second; +} + +std::shared_ptr<io::BaseStream> BufferedContentSession::append(const std::shared_ptr<ResourceClaim>& resource_id) { + auto it = managed_resources_.find(resource_id); + if (it == managed_resources_.end()) { + auto& extension = extended_resources_[resource_id]; if (!extension) { extension = std::make_shared<io::BufferStream>(); } return extension; } - if (mode == WriteMode::OVERWRITE) { - it->second = std::make_shared<io::BufferStream>(); - } return it->second; } -std::shared_ptr<io::BaseStream> ContentSession::read(const std::shared_ptr<ResourceClaim>& resourceId) { +std::shared_ptr<io::BaseStream> BufferedContentSession::read(const std::shared_ptr<ResourceClaim>& resource_id) { // TODO(adebreceni): // after the stream refactor is merged we should be able to share the underlying buffer // between multiple InputStreams, moreover create a ConcatInputStream - if (managedResources_.find(resourceId) != managedResources_.end() || extendedResources_.find(resourceId) != extendedResources_.end()) { + if (managed_resources_.find(resource_id) != managed_resources_.end() || extended_resources_.find(resource_id) != extended_resources_.end()) { Review Comment: ```suggestion if (managed_resources_.contains(resource_id) || extended_resources_.contains(resource_id)) { ``` ########## libminifi/src/core/BufferedContentSession.cpp: ########## @@ -16,58 +16,57 @@ * limitations under the License. */ +#include "core/BufferedContentSession.h" #include <memory> #include "core/ContentRepository.h" -#include "core/ContentSession.h" #include "ResourceClaim.h" #include "io/BaseStream.h" #include "Exception.h" #include "utils/gsl.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { +namespace org::apache::nifi::minifi::core { -ContentSession::ContentSession(std::shared_ptr<ContentRepository> repository) : repository_(std::move(repository)) {} +BufferedContentSession::BufferedContentSession(std::shared_ptr<ContentRepository> repository) : repository_(std::move(repository)) {} -std::shared_ptr<ResourceClaim> ContentSession::create() { +std::shared_ptr<ResourceClaim> BufferedContentSession::create() { std::shared_ptr<ResourceClaim> claim = std::make_shared<ResourceClaim>(repository_); - managedResources_[claim] = std::make_shared<io::BufferStream>(); + managed_resources_[claim] = std::make_shared<io::BufferStream>(); return claim; } -std::shared_ptr<io::BaseStream> ContentSession::write(const std::shared_ptr<ResourceClaim>& resourceId, WriteMode mode) { - auto it = managedResources_.find(resourceId); - if (it == managedResources_.end()) { - if (mode == WriteMode::OVERWRITE) { - throw Exception(REPOSITORY_EXCEPTION, "Can only overwrite owned resource"); - } - auto& extension = extendedResources_[resourceId]; +std::shared_ptr<io::BaseStream> BufferedContentSession::write(const std::shared_ptr<ResourceClaim>& resource_id) { + auto it = managed_resources_.find(resource_id); + if (it == managed_resources_.end()) { + throw Exception(REPOSITORY_EXCEPTION, "Can only overwrite owned resource"); + } + it->second = std::make_shared<io::BufferStream>(); + return it->second; +} + +std::shared_ptr<io::BaseStream> BufferedContentSession::append(const std::shared_ptr<ResourceClaim>& resource_id) { + auto it = managed_resources_.find(resource_id); + if (it == managed_resources_.end()) { + auto& extension = extended_resources_[resource_id]; if (!extension) { extension = std::make_shared<io::BufferStream>(); } return extension; } Review Comment: ```suggestion if (managed_resources_.contains(resource_id)) return managed_resources_.at(resource_id); auto& extension = extended_resources_[resource_id]; if (!extension) { extension = std::make_shared<io::BufferStream>(); } return extension; ``` -- 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]
