MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / onTrigger

Method onTrigger

extensions/script/ExecuteScript.cpp:87–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87void ExecuteScript::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
88 const std::shared_ptr<core::ProcessSession> &session) {
89 try {
90 std::shared_ptr<script::ScriptEngine> engine;
91
92 // Use an existing engine, if one is available
93 if (script_engine_q_.try_dequeue(engine)) {
94 logger_->log_debug("Using available %s script engine instance", script_engine_);
95 } else {
96 logger_->log_info("Creating new %s script instance", script_engine_);
97 logger_->log_info("Approximately %d %s script instances created for this processor",
98 script_engine_q_.size_approx(),
99 script_engine_);
100
101 if (script_engine_ == "python") {
102#ifdef PYTHON_SUPPORT
103 engine = createEngine<python::PythonScriptEngine>();
104#else
105 throw std::runtime_error("Python support is disabled in this build.");
106#endif // PYTHON_SUPPORT
107 } else if (script_engine_ == "lua") {
108#ifdef LUA_SUPPORT
109 engine = createEngine<lua::LuaScriptEngine>();
110#else
111 throw std::runtime_error("Lua support is disabled in this build.");
112#endif // LUA_SUPPORT
113 }
114
115 if (engine == nullptr) {
116 throw std::runtime_error("No script engine available");
117 }
118
119 if (!script_body_.empty()) {
120 engine->eval(script_body_);
121 } else if (!script_file_.empty()) {
122 engine->evalFile(script_file_);
123 } else {
124 throw std::runtime_error("Neither Script Body nor Script File is available to execute");
125 }
126 }
127
128 if (script_engine_ == "python") {
129#ifdef PYTHON_SUPPORT
130 triggerEngineProcessor<python::PythonScriptEngine>(engine, context, session);
131#else
132 throw std::runtime_error("Python support is disabled in this build.");
133#endif // PYTHON_SUPPORT
134 } else if (script_engine_ == "lua") {
135#ifdef LUA_SUPPORT
136 triggerEngineProcessor<lua::LuaScriptEngine>(engine, context, session);
137#else
138 throw std::runtime_error("Lua support is disabled in this build.");
139#endif // LUA_SUPPORT
140 }
141
142 // Make engine available for use again
143 if (script_engine_q_.size_approx() < getMaxConcurrentTasks()) {
144 logger_->log_debug("Releasing %s script engine", script_engine_);

Callers

nothing calls this directly

Calls 9

log_debugMethod · 0.80
log_infoMethod · 0.80
log_errorMethod · 0.80
emptyMethod · 0.45
evalMethod · 0.45
evalFileMethod · 0.45
enqueueMethod · 0.45
whatMethod · 0.45
yieldMethod · 0.45

Tested by

no test coverage detected