martinzink commented on code in PR #2157:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2157#discussion_r3085755412
##########
extensions/grafana-loki/PushGrafanaLoki.h:
##########
@@ -127,7 +127,7 @@ class PushGrafanaLoki : public core::ProcessorImpl {
std::optional<std::chrono::milliseconds> log_line_batch_wait_;
std::chrono::system_clock::time_point start_push_time_;
std::vector<std::shared_ptr<core::FlowFile>> batched_flowfiles_;
- core::StateManager* state_manager_;
+ core::StateManager* state_manager_ = nullptr;
Review Comment:
Could we remove this member and only use the state manager in the ontirgger
and onschedule as a stack variabl?
##########
libminifi/test/libtest/unit/StatefulProcessor.cpp:
##########
@@ -21,23 +21,27 @@
#include "minifi-cpp/Exception.h"
#include "core/Resource.h"
#include "minifi-cpp/core/ProcessContext.h"
+#include "core/ProcessSession.h"
namespace org::apache::nifi::minifi::processors {
void StatefulProcessor::onSchedule(core::ProcessContext& context,
core::ProcessSessionFactory&) {
std::lock_guard<std::mutex> lock(mutex_);
- state_manager_ = context.getStateManager();
- if (state_manager_ == nullptr) {
+ auto temp_state_manager = context.createStateManager();
+ if (temp_state_manager == nullptr) {
throw Exception(PROCESSOR_EXCEPTION, "Failed to get StateManager");
}
+ state_manager_ = temp_state_manager.get();
if (on_schedule_hook_) {
on_schedule_hook_(*state_manager_);
}
+ state_manager_ = nullptr;
}
-void StatefulProcessor::onTrigger(core::ProcessContext&,
core::ProcessSession&) {
+void StatefulProcessor::onTrigger(core::ProcessContext& context,
core::ProcessSession&) {
std::lock_guard<std::mutex> lock(mutex_);
+ state_manager_ = context.getStateManager();
Review Comment:
i know this is test code, but I think it would be clearer if state_manager_
would cease to be a member and only live on the stack during the onschedule and
ontrigger
--
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]