[ https://issues.apache.org/jira/browse/MINIFICPP-654?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16667507#comment-16667507 ]
ASF GitHub Bot commented on MINIFICPP-654: ------------------------------------------ Github user phrocker commented on a diff in the pull request: https://github.com/apache/nifi-minifi-cpp/pull/429#discussion_r229021535 --- Diff: libminifi/include/capi/Plan.h --- @@ -46,11 +48,50 @@ #include "capi/cstructs.h" #include "capi/api.h" +enum FailureStrategy { AS_IS, ROLLBACK }; + +bool intToFailureStragey(int in, FailureStrategy *out); + +using callback_type = std::function<void(flow_file_record*)>; +using content_repo_sptr = std::shared_ptr<core::ContentRepository>; + +namespace { + + void failureStrategyAsIs(core::ProcessSession *session, callback_type user_callback, content_repo_sptr cr_ptr) { + auto ff = session->get(); + if (ff == nullptr) { + return; + } + + auto claim = ff->getResourceClaim(); + + if (claim != nullptr && user_callback != nullptr) { + claim->increaseFlowFileRecordOwnedCount(); + // create a flow file. + auto path = claim->getContentFullPath(); + auto ffr = create_ff_object_na(path.c_str(), path.length(), ff->getSize()); + ffr->attributes = ff->getAttributesPtr(); + ffr->ffp = ff.get(); + auto content_repo_ptr = static_cast<std::shared_ptr<minifi::core::ContentRepository>*>(ffr->crp); + *content_repo_ptr = cr_ptr; + user_callback(ffr); + } + session->remove(ff); + } + + void failureStrategyRollback(core::ProcessSession *session, callback_type user_callback, content_repo_sptr cr_ptr) { + session->rollback(); + failureStrategyAsIs(session, user_callback, cr_ptr); + } +} + +static const std::map<FailureStrategy, const std::function<void(core::ProcessSession*, callback_type, content_repo_sptr)>> FailureStrategies = + { { FailureStrategy::AS_IS, failureStrategyAsIs }, {FailureStrategy::ROLLBACK, failureStrategyRollback } }; class ExecutionPlan { public: - explicit ExecutionPlan(std::shared_ptr<core::ContentRepository> content_repo, std::shared_ptr<core::Repository> flow_repo, std::shared_ptr<core::Repository> prov_repo); + explicit ExecutionPlan(content_repo_sptr content_repo, std::shared_ptr<core::Repository> flow_repo, std::shared_ptr<core::Repository> prov_repo); --- End diff -- ^ Seems harder to read. Not sure if it helps but we have our linter set to 200 line characters ( to match Apache NiFi ), so we're not that tight on line space. > C API: failure callback improvements > ------------------------------------ > > Key: MINIFICPP-654 > URL: https://issues.apache.org/jira/browse/MINIFICPP-654 > Project: NiFi MiNiFi C++ > Issue Type: Improvement > Reporter: Arpad Boda > Assignee: Arpad Boda > Priority: Minor > Fix For: 0.6.0 > > > Improvements and further discussion of failure callbacks. -- This message was sent by Atlassian JIRA (v7.6.3#76005)