[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-08-31 Thread GitBox


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


##
libminifi/include/core/repository/FileSystemRepository.h:
##
@@ -25,49 +25,39 @@
 #include "../ContentRepository.h"
 #include "properties/Configure.h"
 #include "core/logging/LoggerFactory.h"
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
-namespace core {
-namespace repository {
+
+namespace org::apache::nifi::minifi::core::repository {
 
 /**
  * FileSystemRepository is a content repository that stores data onto the 
local file system.
  */
 class FileSystemRepository : public core::ContentRepository, public 
core::CoreComponent {
  public:
   FileSystemRepository(std::string name = 
getClassName()) // NOLINT
-  : core::CoreComponent(name),
-logger_(logging::LoggerFactory::getLogger()) {
+  : core::CoreComponent(name),
+logger_(logging::LoggerFactory::getLogger()) 
{

Review Comment:
   Done.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-08-03 Thread GitBox


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


##
libminifi/include/core/ThreadedRepository.h:
##
@@ -0,0 +1,106 @@
+/**
+ *
+ * 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 
+#include 
+
+#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_state_.load() != RUNNING_STATE::STOPPED) {
+  logger_->log_error("Thread of %s should have been stopped in subclass 
before ThreadedRepository's destruction", name_);
+}
+  }
+
+  bool initialize(const std::shared_ptr& /*configure*/) override {
+return true;
+  }
+
+  // Starts repository monitor thread
+  bool start() override {
+// if STOPPED, turn to STARTING, otherwise return
+RUNNING_STATE expected{RUNNING_STATE::STOPPED};

Review Comment:
   Done.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-08-01 Thread GitBox


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


##
libminifi/include/core/repository/VolatileContentRepository.h:
##
@@ -68,55 +59,55 @@ class VolatileContentRepository :
   }
   master_list_.clear();
 }
+stop();
   }
 
   /**
* Initialize the volatile content repo
* @param configure configuration
*/
-  virtual bool initialize(const std::shared_ptr );
-
-  /**
-   * Stop any thread associated with the volatile content repository.
-   */
-  virtual void stop();
+  bool initialize(const std::shared_ptr ) override;
 
   /**
* Creates writable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream the consumer 
will write to.
*/
-  virtual std::shared_ptr write(const minifi::ResourceClaim 
, bool append);
+  std::shared_ptr write(const minifi::ResourceClaim , 
bool append) override;
 
   /**
* Creates readable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream from which 
the consumer will read..
*/
-  virtual std::shared_ptr read(const minifi::ResourceClaim 
);
+  std::shared_ptr read(const minifi::ResourceClaim ) 
override;
 
-  virtual bool exists(const minifi::ResourceClaim );
+  bool exists(const minifi::ResourceClaim ) override;
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool close(const minifi::ResourceClaim ) {
+  bool close(const minifi::ResourceClaim ) override {
 return remove(claim);
   }
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool remove(const minifi::ResourceClaim );
+  bool remove(const minifi::ResourceClaim ) override;
+
+ private:
+  void run() override {
+  }
 
- protected:
-  virtual void start();
+  std::thread& getThread() override {
+return thread_;
+  }

Review Comment:
   Done.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-08-01 Thread GitBox


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


##
libminifi/include/core/Repository.h:
##
@@ -218,56 +195,77 @@ class Repository : public virtual 
core::SerializableComponent, public core::Trac
 return Put(key, buffer, bufferSize);
   }
 
-  uint64_t incrementSize(const char* /*fpath*/, const struct stat *sb, int 
/*typeflag*/) {
-return (repo_size_ += sb->st_size);
-  }
-
   virtual void loadComponent(const std::shared_ptr& 
/*content_repo*/) {
   }
 
-  virtual uint64_t getRepoSize();
+  virtual uint64_t getRepoSize() const {
+return repo_size_;
+  }
 
   std::string getDirectory() const {
 return directory_;
   }
 
-  // Prevent default copy constructor and assignment operation
-  // Only support pass by reference or pointer
-  Repository(const Repository ) = delete;
-  Repository =(const Repository ) = delete;
+  // Starts repository monitor thread
+  void start() {
+if (running_.exchange(true)) {
+  return;
+}
+if (purge_period_ <= std::chrono::milliseconds(0)) {
+  return;
+}
+getThread() = std::thread(::run, this);
+
+logger_->log_debug("%s Repository monitor thread start", name_);
+  }
+
+  // Stops repository monitor thread
+  void stop() {
+if (!running_.exchange(false)) {
+  return;
+}
+if (getThread().joinable()) {
+  getThread().join();
+}
+logger_->log_debug("%s Repository monitor thread stop", name_);
+  }

Review Comment:
   Done.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-28 Thread GitBox


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


##
libminifi/include/core/repository/VolatileContentRepository.h:
##
@@ -68,55 +59,55 @@ class VolatileContentRepository :
   }
   master_list_.clear();
 }
+stop();
   }
 
   /**
* Initialize the volatile content repo
* @param configure configuration
*/
-  virtual bool initialize(const std::shared_ptr );
-
-  /**
-   * Stop any thread associated with the volatile content repository.
-   */
-  virtual void stop();
+  bool initialize(const std::shared_ptr ) override;
 
   /**
* Creates writable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream the consumer 
will write to.
*/
-  virtual std::shared_ptr write(const minifi::ResourceClaim 
, bool append);
+  std::shared_ptr write(const minifi::ResourceClaim , 
bool append) override;
 
   /**
* Creates readable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream from which 
the consumer will read..
*/
-  virtual std::shared_ptr read(const minifi::ResourceClaim 
);
+  std::shared_ptr read(const minifi::ResourceClaim ) 
override;
 
-  virtual bool exists(const minifi::ResourceClaim );
+  bool exists(const minifi::ResourceClaim ) override;
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool close(const minifi::ResourceClaim ) {
+  bool close(const minifi::ResourceClaim ) override {
 return remove(claim);
   }
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool remove(const minifi::ResourceClaim );
+  bool remove(const minifi::ResourceClaim ) override;
+
+ private:
+  void run() override {
+  }
 
- protected:
-  virtual void start();
+  std::thread& getThread() override {
+return thread_;
+  }

Review Comment:
   This makes sense, so be 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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-27 Thread GitBox


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


##
libminifi/include/core/repository/VolatileContentRepository.h:
##
@@ -68,55 +59,55 @@ class VolatileContentRepository :
   }
   master_list_.clear();
 }
+stop();
   }
 
   /**
* Initialize the volatile content repo
* @param configure configuration
*/
-  virtual bool initialize(const std::shared_ptr );
-
-  /**
-   * Stop any thread associated with the volatile content repository.
-   */
-  virtual void stop();
+  bool initialize(const std::shared_ptr ) override;
 
   /**
* Creates writable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream the consumer 
will write to.
*/
-  virtual std::shared_ptr write(const minifi::ResourceClaim 
, bool append);
+  std::shared_ptr write(const minifi::ResourceClaim , 
bool append) override;
 
   /**
* Creates readable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream from which 
the consumer will read..
*/
-  virtual std::shared_ptr read(const minifi::ResourceClaim 
);
+  std::shared_ptr read(const minifi::ResourceClaim ) 
override;
 
-  virtual bool exists(const minifi::ResourceClaim );
+  bool exists(const minifi::ResourceClaim ) override;
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool close(const minifi::ResourceClaim ) {
+  bool close(const minifi::ResourceClaim ) override {
 return remove(claim);
   }
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool remove(const minifi::ResourceClaim );
+  bool remove(const minifi::ResourceClaim ) override;
+
+ private:
+  void run() override {
+  }
 
- protected:
-  virtual void start();
+  std::thread& getThread() override {
+return thread_;
+  }

Review Comment:
   It looks like the the threadedness of a repository must be exposed, because 
for example [FlowController uses 
it](https://github.com/adam-markovics/nifi-minifi-cpp/blob/53fbb264cb00fbb4189a2fb1ae7978c6913d3a1c/libminifi/src/FlowController.cpp#L381)
   A threadless repo should not have a `start` method, it would be worse in my 
opinion.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-25 Thread GitBox


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


##
libminifi/include/core/repository/VolatileContentRepository.h:
##
@@ -68,55 +59,55 @@ class VolatileContentRepository :
   }
   master_list_.clear();
 }
+stop();
   }
 
   /**
* Initialize the volatile content repo
* @param configure configuration
*/
-  virtual bool initialize(const std::shared_ptr );
-
-  /**
-   * Stop any thread associated with the volatile content repository.
-   */
-  virtual void stop();
+  bool initialize(const std::shared_ptr ) override;
 
   /**
* Creates writable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream the consumer 
will write to.
*/
-  virtual std::shared_ptr write(const minifi::ResourceClaim 
, bool append);
+  std::shared_ptr write(const minifi::ResourceClaim , 
bool append) override;
 
   /**
* Creates readable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream from which 
the consumer will read..
*/
-  virtual std::shared_ptr read(const minifi::ResourceClaim 
);
+  std::shared_ptr read(const minifi::ResourceClaim ) 
override;
 
-  virtual bool exists(const minifi::ResourceClaim );
+  bool exists(const minifi::ResourceClaim ) override;
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool close(const minifi::ResourceClaim ) {
+  bool close(const minifi::ResourceClaim ) override {
 return remove(claim);
   }
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool remove(const minifi::ResourceClaim );
+  bool remove(const minifi::ResourceClaim ) override;
+
+ private:
+  void run() override {
+  }
 
- protected:
-  virtual void start();
+  std::thread& getThread() override {
+return thread_;
+  }

Review Comment:
   Okay, I will partially revert to previous implementation of having a 
ThreadedRepository, but without exposing it anywhere. If it is possible. If I 
run into something that prevents it, I will update here.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-25 Thread GitBox


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


##
libminifi/include/core/repository/VolatileContentRepository.h:
##
@@ -68,55 +59,55 @@ class VolatileContentRepository :
   }
   master_list_.clear();
 }
+stop();
   }
 
   /**
* Initialize the volatile content repo
* @param configure configuration
*/
-  virtual bool initialize(const std::shared_ptr );
-
-  /**
-   * Stop any thread associated with the volatile content repository.
-   */
-  virtual void stop();
+  bool initialize(const std::shared_ptr ) override;
 
   /**
* Creates writable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream the consumer 
will write to.
*/
-  virtual std::shared_ptr write(const minifi::ResourceClaim 
, bool append);
+  std::shared_ptr write(const minifi::ResourceClaim , 
bool append) override;
 
   /**
* Creates readable stream.
* @param claim resource claim
* @return BaseStream shared pointer that represents the stream from which 
the consumer will read..
*/
-  virtual std::shared_ptr read(const minifi::ResourceClaim 
);
+  std::shared_ptr read(const minifi::ResourceClaim ) 
override;
 
-  virtual bool exists(const minifi::ResourceClaim );
+  bool exists(const minifi::ResourceClaim ) override;
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool close(const minifi::ResourceClaim ) {
+  bool close(const minifi::ResourceClaim ) override {
 return remove(claim);
   }
 
   /**
* Closes the claim.
* @return whether or not the claim is associated with content stored in 
volatile memory.
*/
-  virtual bool remove(const minifi::ResourceClaim );
+  bool remove(const minifi::ResourceClaim ) override;
+
+ private:
+  void run() override {
+  }
 
- protected:
-  virtual void start();
+  std::thread& getThread() override {
+return thread_;
+  }

Review Comment:
   The previous one was like that. You asked to be like this: 
https://github.com/apache/nifi-minifi-cpp/pull/1328#discussion_r923437527



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-19 Thread GitBox


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


##
controller/Controller.h:
##
@@ -246,15 +247,25 @@ 
std::shared_ptr
 
   
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,
+   
"provenance");
+  const auto prov_repo = 
std::dynamic_pointer_cast(prov_repo_base);
+  if (!prov_repo) {
+throw 
org::apache::nifi::minifi::Exception(org::apache::nifi::minifi::REPOSITORY_EXCEPTION,
 "Could not create provenance repository");
+  }
   prov_repo->initialize(configuration);
 
   
configuration->get(org::apache::nifi::minifi::Configure::nifi_flow_repository_class_name,
 flow_repo_class);
 
-  const std::shared_ptr flow_repo = 
org::apache::nifi::minifi::core::createRepository(flow_repo_class, true, 
"flowfile");
+  const std::shared_ptr flow_repo_base = 
org::apache::nifi::minifi::core::createRepository(flow_repo_class, "flowfile");
+  const auto flow_repo = 
std::dynamic_pointer_cast(flow_repo_base);

Review Comment:
   Done.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-19 Thread GitBox


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


##
libminifi/include/core/Repository.h:
##
@@ -20,89 +20,77 @@
 #ifndef LIBMINIFI_INCLUDE_CORE_REPOSITORY_H_
 #define LIBMINIFI_INCLUDE_CORE_REPOSITORY_H_
 
-#include 
-#include 
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
-#include 
+#include 
 #include 
+
+#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 
 #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:
   `ThreadedRepository` is gone, in `Repository` `run` and `getThread` are 
already pure virtual.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-19 Thread GitBox


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


##
libminifi/include/core/RepositoryFactory.h:
##
@@ -49,10 +45,14 @@ std::unique_ptr createRepository(const 
std::string& configurat
  */
 std::unique_ptr 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 createThreadedRepository(const 
std::string& configuration_class_name, const std::string& repo_name = "");

Review Comment:
   They are merged now.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-18 Thread GitBox


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


##
libminifi/include/core/Repository.h:
##
@@ -20,89 +20,77 @@
 #ifndef LIBMINIFI_INCLUDE_CORE_REPOSITORY_H_
 #define LIBMINIFI_INCLUDE_CORE_REPOSITORY_H_
 
-#include 
-#include 
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
-#include 
+#include 
 #include 
+
+#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 
 #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:
   I chose `initialize`



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-18 Thread GitBox


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


##
libminifi/include/core/RepositoryFactory.h:
##
@@ -49,10 +45,14 @@ std::unique_ptr createRepository(const 
std::string& configurat
  */
 std::unique_ptr 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 createThreadedRepository(const 
std::string& configuration_class_name, const std::string& repo_name = "");

Review Comment:
   `core::createRepository` has been deleted



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-18 Thread GitBox


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


##
controller/Controller.h:
##
@@ -246,15 +247,24 @@ 
std::shared_ptr
 
   
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(prov_repo_base);

Review Comment:
   `core::createRepository` is no longer existing



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-07-11 Thread GitBox


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


##
controller/Controller.h:
##
@@ -246,15 +247,24 @@ 
std::shared_ptr
 
   
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::static_pointer_cast(prov_repo_base);

Review Comment:
   Good point! Done.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1328: MINIFICPP-1812 - Clean up Repository threads

2022-05-16 Thread GitBox


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


##
libminifi/src/core/RepositoryFactory.cpp:
##
@@ -96,6 +96,62 @@ std::unique_ptr 
createContentRepository(const std::stri
   throw std::runtime_error("Support for the provided configuration class could 
not be found");
 }
 
+class NoOpThreadedRepository : public core::ThreadedRepository {
+ public:
+  explicit NoOpThreadedRepository(const std::string& repo_name)
+: core::SerializableComponent(repo_name),
+ThreadedRepository(repo_name) {
+  }
+
+  ~NoOpThreadedRepository() override {
+stop();
+  }
+
+ private:
+  void run() override {
+  }
+
+  std::thread& getThread() override {
+return thread_;
+  }
+
+  std::thread thread_;
+};
+
+std::unique_ptr createThreadedRepository(const 
std::string& configuration_class_name, bool fail_safe, const std::string& 
repo_name) {
+  std::string class_name_lc = configuration_class_name;
+  std::transform(class_name_lc.begin(), class_name_lc.end(), 
class_name_lc.begin(), ::tolower);
+  try {
+auto return_obj = 
core::ClassLoader::getDefaultClassLoader().instantiate(class_name_lc,
 class_name_lc);
+if (return_obj) {
+  return_obj->setName(repo_name);
+  return return_obj;
+}
+// if the desired repos don't exist, we can try doing string matches and 
rely on volatile repositories
+if (class_name_lc == "flowfilerepository" || class_name_lc == 
"volatileflowfilerepository") {
+  return_obj = 
instantiate(repo_name);
+} else if (class_name_lc == "provenancerepository" || class_name_lc == 
"volatileprovenancefilerepository") {
+  return_obj = 
instantiate(repo_name);
+} else if (class_name_lc == "nooprepository") {
+  return_obj = std::make_unique(repo_name);
+}
+if (return_obj) {
+  return return_obj;
+}
+if (fail_safe) {
+  return {};
+} else {
+  throw std::runtime_error("Support for the provided configuration class 
could not be found");
+}
+  } catch (const std::runtime_error &) {
+if (fail_safe) {
+  return {};
+}
+  }
+
+  throw std::runtime_error("Support for the provided configuration class could 
not be found");
+}
+
 } /* namespace core */
 } /* namespace minifi */
 } /* namespace nifi */

Review Comment:
   Done.



##
libminifi/src/core/RepositoryFactory.cpp:
##
@@ -96,6 +96,62 @@ std::unique_ptr 
createContentRepository(const std::stri
   throw std::runtime_error("Support for the provided configuration class could 
not be found");
 }
 
+class NoOpThreadedRepository : public core::ThreadedRepository {
+ public:
+  explicit NoOpThreadedRepository(const std::string& repo_name)
+: core::SerializableComponent(repo_name),
+ThreadedRepository(repo_name) {
+  }
+
+  ~NoOpThreadedRepository() override {
+stop();
+  }
+
+ private:
+  void run() override {
+  }
+
+  std::thread& getThread() override {
+return thread_;
+  }
+
+  std::thread thread_;
+};
+
+std::unique_ptr createThreadedRepository(const 
std::string& configuration_class_name, bool fail_safe, const std::string& 
repo_name) {

Review Comment:
   Done.



##
libminifi/src/core/RepositoryFactory.cpp:
##
@@ -96,6 +96,62 @@ std::unique_ptr 
createContentRepository(const std::stri
   throw std::runtime_error("Support for the provided configuration class could 
not be found");
 }
 
+class NoOpThreadedRepository : public core::ThreadedRepository {
+ public:
+  explicit NoOpThreadedRepository(const std::string& repo_name)
+: core::SerializableComponent(repo_name),
+ThreadedRepository(repo_name) {
+  }
+
+  ~NoOpThreadedRepository() override {
+stop();
+  }
+
+ private:
+  void run() override {
+  }
+
+  std::thread& getThread() override {
+return thread_;
+  }
+
+  std::thread thread_;
+};
+
+std::unique_ptr createThreadedRepository(const 
std::string& configuration_class_name, bool fail_safe, const std::string& 
repo_name) {
+  std::string class_name_lc = configuration_class_name;
+  std::transform(class_name_lc.begin(), class_name_lc.end(), 
class_name_lc.begin(), ::tolower);
+  try {
+auto return_obj = 
core::ClassLoader::getDefaultClassLoader().instantiate(class_name_lc,
 class_name_lc);
+if (return_obj) {
+  return_obj->setName(repo_name);
+  return return_obj;
+}
+// if the desired repos don't exist, we can try doing string matches and 
rely on volatile repositories
+if (class_name_lc == "flowfilerepository" || class_name_lc == 
"volatileflowfilerepository") {
+  return_obj = 
instantiate(repo_name);
+} else if (class_name_lc == "provenancerepository" || class_name_lc == 
"volatileprovenancefilerepository") {
+  return_obj = 
instantiate(repo_name);
+} else if (class_name_lc == "nooprepository") {
+  return_obj = std::make_unique(repo_name);
+}
+if (return_obj) {
+  return return_obj;
+}
+if (fail_safe) {
+  return {};
+}