bakaid commented on a change in pull request #605: MINIFICPP-550 - Implement 
RocksDB controller service and component st…
URL: https://github.com/apache/nifi-minifi-cpp/pull/605#discussion_r389748596
 
 

 ##########
 File path: extensions/sftp/processors/ListSFTP.cpp
 ##########
 @@ -507,85 +463,87 @@ ListSFTP::ListedEntity::ListedEntity(uint64_t 
timestamp_, uint64_t size_)
     , size(size_) {
 }
 
-bool ListSFTP::persistTrackingTimestampsCache(const std::string& hostname, 
const std::string& username, const std::string& remote_path) {
-  std::ofstream file(tracking_timestamps_state_filename_);
-  if (!file.is_open()) {
-    logger_->log_error("Failed to store state to Tracking Timestamps state 
file \"%s\"", tracking_timestamps_state_filename_.c_str());
+bool ListSFTP::persistTrackingTimestampsCache(const 
std::shared_ptr<core::ProcessContext>& context, const std::string& hostname, 
const std::string& username, const std::string& remote_path) {
+  auto state_manager = context->getStateManager();
+  if (state_manager == nullptr) {
     return false;
   }
-  file << "hostname=" << hostname << "\n";
-  file << "username=" << username << "\n";
-  file << "remote_path=" << remote_path << "\n";
-  file << "listing.timestamp=" << last_listed_latest_entry_timestamp_ << "\n";
-  file << "processed.timestamp=" << last_processed_latest_entry_timestamp_ << 
"\n";
+  std::unordered_map<std::string, std::string> state;
+  state["listing_strategy"] = LISTING_STRATEGY_TRACKING_TIMESTAMPS;
+  state["hostname"] = hostname;
+  state["username"] = username;
+  state["remote_path"] = remote_path;
+  state["listing.timestamp"] = 
std::to_string(last_listed_latest_entry_timestamp_);
+  state["processed.timestamp"] = 
std::to_string(last_processed_latest_entry_timestamp_);
   size_t i = 0;
   for (const auto& identifier : latest_identifiers_processed_) {
-    file << "id." << i << "=" << identifier << "\n";
+    state["id." + std::to_string(i)] = identifier;
     ++i;
   }
+  state_manager->set(state);
+  if (!state_manager->persist()) {
+    return false;
+  }
   return true;
 }
 
-bool ListSFTP::updateFromTrackingTimestampsCache(const std::string& hostname, 
const std::string& username, const std::string& remote_path) {
-  std::ifstream file(tracking_timestamps_state_filename_);
-  if (!file.is_open()) {
-    logger_->log_error("Failed to open Tracking Timestamps state file \"%s\"", 
tracking_timestamps_state_filename_.c_str());
-    return false;
-  }
+bool ListSFTP::updateFromTrackingTimestampsCache(const 
std::shared_ptr<core::ProcessContext>& context, const std::string& hostname, 
const std::string& username, const std::string& remote_path) {
 
 Review comment:
   Agreed, we use it because `onTrigger` already gets it this way and it is 
easier to just pass that to these functions.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to