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

Method onTrigger

extensions/standard-processors/processors/GetFile.cpp:159–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159void GetFile::onTrigger(core::ProcessContext* /*context*/, core::ProcessSession *session) {
160 // Perform directory list
161
162 metrics_->iterations_++;
163
164 const bool isDirEmptyBeforePoll = isListingEmpty();
165 logger_->log_debug("Is listing empty before polling directory %i", isDirEmptyBeforePoll);
166 if (isDirEmptyBeforePoll) {
167 if (request_.pollInterval == 0 || (utils::timeutils::getTimeMillis() - last_listing_time_) > request_.pollInterval) {
168 performListing(request_);
169 last_listing_time_.store(utils::timeutils::getTimeMillis());
170 }
171 }
172
173 const bool isDirEmptyAfterPoll = isListingEmpty();
174 logger_->log_debug("Is listing empty after polling directory %i", isDirEmptyAfterPoll);
175
176 if (!isDirEmptyAfterPoll) {
177 try {
178 std::queue<std::string> list;
179 pollListing(list, request_);
180 while (!list.empty()) {
181 std::string fileName = list.front();
182 list.pop();
183 logger_->log_info("GetFile process %s", fileName);
184 auto flowFile = session->create();
185 if (flowFile == nullptr)
186 return;
187 std::size_t found = fileName.find_last_of("/\\");
188 std::string path = fileName.substr(0, found);
189 std::string name = fileName.substr(found + 1);
190 flowFile->setAttribute(core::SpecialFlowAttribute::FILENAME, name);
191 flowFile->setAttribute(core::SpecialFlowAttribute::PATH, path);
192 flowFile->addAttribute(core::SpecialFlowAttribute::ABSOLUTE_PATH, fileName);
193 session->import(fileName, flowFile, request_.keepSourceFile);
194 session->transfer(flowFile, Success);
195 }
196 } catch (std::exception &exception) {
197 logger_->log_debug("GetFile Caught Exception %s", exception.what());
198 throw;
199 } catch (...) {
200 throw;
201 }
202 }
203}
204
205bool GetFile::isListingEmpty() {
206 std::lock_guard<std::mutex> lock(mutex_);

Callers

nothing calls this directly

Calls 11

getTimeMillisFunction · 0.85
log_debugMethod · 0.80
log_infoMethod · 0.80
importMethod · 0.80
emptyMethod · 0.45
popMethod · 0.45
createMethod · 0.45
setAttributeMethod · 0.45
addAttributeMethod · 0.45
transferMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected