| 157 | } |
| 158 | |
| 159 | void 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 | |
| 205 | bool GetFile::isListingEmpty() { |
| 206 | std::lock_guard<std::mutex> lock(mutex_); |
nothing calls this directly
no test coverage detected