szaszm commented on code in PR #1328:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1328#discussion_r918759741


##########
libminifi/include/core/RepositoryFactory.h:
##########
@@ -49,10 +45,14 @@ std::unique_ptr<core::Repository> createRepository(const 
std::string& configurat
  */
 std::unique_ptr<core::ContentRepository> createContentRepository(const 
std::string& configuration_class_name, bool fail_safe = false, const 
std::string& repo_name = "");
 
-}  // namespace core
-}  // namespace minifi
-}  // namespace nifi
-}  // namespace apache
-}  // namespace org
+/**
+ * Create a threaded repository represented by the configuration class name
+ * @param configuration_class_name configuration class name
+ * @param fail_safe determines whether or not to make the default class if 
configuration_class_name is invalid
+ * @param repo_name name of the repository
+ */
+std::unique_ptr<core::ThreadedRepository> createThreadedRepository(const 
std::string& configuration_class_name, const std::string& repo_name = "");

Review Comment:
   Why keep `createRepository` if everything uses ThreadedRepositories?



##########
libminifi/include/core/ThreadedRepository.h:
##########
@@ -0,0 +1,86 @@
+/**
+ *
+ * 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 <thread>
+
+#include "Repository.h"
+#include "TraceableResource.h"
+
+namespace org::apache::nifi::minifi::core {
+
+class ThreadedRepository : public core::Repository, public 
core::TraceableResource {
+ public:
+  using Repository::Repository;
+
+  ~ThreadedRepository() override {
+    if (running_.load()) {
+      logger_->log_error("Thread of %s should have been stopped in subclass 
before ThreadedRepository's destruction", name_);
+    }
+  }
+
+  // Starts repository monitor thread
+  void start() {
+    if (running_.exchange(true)) {
+      return;
+    }
+    if (purge_period_ <= std::chrono::milliseconds(0)) {
+      return;
+    }
+    getThread() = std::thread(&ThreadedRepository::run, this);

Review Comment:
   I think you can't take the address of a virtual member function and expect 
the derived class implementation to be called. If it works, it's probably a 
compiler extension, not standard. Use a lambda instead.



##########
libminifi/include/core/Repository.h:
##########
@@ -20,89 +20,77 @@
 #ifndef LIBMINIFI_INCLUDE_CORE_REPOSITORY_H_
 #define LIBMINIFI_INCLUDE_CORE_REPOSITORY_H_
 
-#include <memory>
-#include <utility>
 #include <atomic>
 #include <cstdint>
 #include <cstring>
-#include <iostream>
 #include <map>
+#include <memory>
 #include <set>
 #include <string>
-#include <thread>
+#include <utility>
 #include <vector>
+
+#include "Core.h"
+#include "ResourceClaim.h"
+#include "core/Connectable.h"
 #include "core/ContentRepository.h"
+#include "core/Property.h"
 #include "core/SerializableComponent.h"
-#include "properties/Configure.h"
 #include "core/logging/LoggerConfiguration.h"
-#include "core/Property.h"
-#include "ResourceClaim.h"
-#include "utils/TimeUtil.h"
-#include "utils/StringUtils.h"
-#include "Core.h"
-#include "core/Connectable.h"
-#include "core/TraceableResource.h"
+#include "properties/Configure.h"
 #include "utils/BackTrace.h"
+#include "utils/Literals.h"
+#include "utils/StringUtils.h"
+#include "utils/TimeUtil.h"
 
 #ifndef WIN32
 #include <sys/stat.h>
 #endif
 
 namespace org::apache::nifi::minifi::core {
 
-#define REPOSITORY_DIRECTORY "./repo"
-#define MAX_REPOSITORY_STORAGE_SIZE (10*1024*1024)  // 10M
+constexpr auto REPOSITORY_DIRECTORY = "./repo";
+constexpr auto MAX_REPOSITORY_STORAGE_SIZE = 10_MiB;
 constexpr auto MAX_REPOSITORY_ENTRY_LIFE_TIME = std::chrono::minutes(10);
 constexpr auto REPOSITORY_PURGE_PERIOD = std::chrono::milliseconds(2500);
 
-class Repository : public virtual core::SerializableComponent, public 
core::TraceableResource {
+class Repository : public virtual core::SerializableComponent {

Review Comment:
   Does it make sense to instantiate a Repository? If not, I would make it 
abstract. There are plenty of good candidate member functions, like `isNoop`, 
`flush`, `initialize`, `Put`, `MultiPut`, `Delete`, etc.



##########
controller/Controller.h:
##########
@@ -246,15 +247,24 @@ 
std::shared_ptr<org::apache::nifi::minifi::core::controller::ControllerService>
 
   
configuration->get(org::apache::nifi::minifi::Configure::nifi_provenance_repository_class_name,
 prov_repo_class);
   // Create repos for flow record and provenance
-  const std::shared_ptr prov_repo = 
org::apache::nifi::minifi::core::createRepository(prov_repo_class, true, 
"provenance");
+  const std::shared_ptr prov_repo_base = 
org::apache::nifi::minifi::core::createRepository(prov_repo_class, true, 
"provenance");
+  const auto prov_repo = 
std::dynamic_pointer_cast<org::apache::nifi::minifi::core::ThreadedRepository>(prov_repo_base);

Review Comment:
   Why do you use normal `core::createRepository` here, while 
`core::createThreadedRepository` in main?



-- 
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]

Reply via email to