[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1443: MINIFICPP-1972 - Refactor State Manager code

2022-11-02 Thread GitBox


adamdebreceni commented on code in PR #1443:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1443#discussion_r1011973399


##
libminifi/include/core/ProcessContext.h:
##
@@ -246,14 +238,14 @@ class ProcessContext : public 
controller::ControllerServiceLookup, public core::
   return initialized_;
   }
 
-  static constexpr char const* DefaultStateManagerProviderName = 
"defaultstatemanagerprovider";
+  static constexpr char const* DefaultStateStorageName = "defaultstatestorage";

Review Comment:
   won't this affect backwards compatibility? 



-- 
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] adamdebreceni commented on a diff in pull request #1443: MINIFICPP-1972 - Refactor State Manager code

2022-11-02 Thread GitBox


adamdebreceni commented on code in PR #1443:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1443#discussion_r1011962230


##
libminifi/src/controllers/keyvalue/KeyValueStateStorage.cpp:
##
@@ -0,0 +1,105 @@
+/**
+ * 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 
+
+#include "Exception.h"
+#include "controllers/keyvalue/KeyValueStateManager.h"
+#include "controllers/keyvalue/KeyValueStateStorage.h"
+
+#include "rapidjson/rapidjson.h"
+#include "rapidjson/document.h"
+#include "rapidjson/stringbuffer.h"
+#include "rapidjson/writer.h"
+
+#undef GetObject  // windows.h #defines GetObject = GetObjectA or GetObjectW, 
which conflicts with rapidjson
+
+namespace org::apache::nifi::minifi::controllers {
+
+std::string KeyValueStateStorage::serialize(const core::StateManager::State& 
kvs) {
+  rapidjson::Document doc(rapidjson::kObjectType);
+  rapidjson::Document::AllocatorType &alloc = doc.GetAllocator();
+  for (const auto &kv : kvs) {
+doc.AddMember(rapidjson::StringRef(kv.first.c_str(), kv.first.size()),
+  rapidjson::StringRef(kv.second.c_str(), kv.second.size()), 
alloc);
+  }
+
+  rapidjson::StringBuffer buffer;
+  rapidjson::Writer writer(buffer);
+  doc.Accept(writer);
+
+  return buffer.GetString();
+}
+
+core::StateManager::State KeyValueStateStorage::deserialize(const std::string& 
serialized) {
+  rapidjson::StringStream stream(serialized.c_str());
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.ParseStream(stream);

Review Comment:
   there is a `Parse` method that takes `const char*`



-- 
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] adamdebreceni commented on a diff in pull request #1443: MINIFICPP-1972 - Refactor State Manager code

2022-11-02 Thread GitBox


adamdebreceni commented on code in PR #1443:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1443#discussion_r1011920262


##
libminifi/include/core/StateManager.h:
##
@@ -0,0 +1,67 @@
+/**
+ * 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 "Core.h"
+
+#include 
+#include 
+#include 
+#include 
+
+namespace org::apache::nifi::minifi::core {
+
+/**
+ * Stores state for one component.
+ * Supported operations: get(), set(), clear(), persist().
+ * Behavior can transactional. Use beginTransaction() to enter a transaction 
and commit() or rollback() to conclude it.

Review Comment:
   ```suggestion
* Behavior can be transactional. Use beginTransaction() to enter a 
transaction and commit() or rollback() to conclude 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