bool SchedulingAgent::onTrigger(std::shared_ptr<core::Processor> processor, core::ProcessContext *processContext, core::ProcessSessionFactory *sessionFactory) {
  if (processor->isYield())
    return false;

  // No need to yield, reset yield expiration to 0
  processor->clearYield();

  if (!hasWorkToDo(processor))
    // No work to do, yield
    return true;

  if (hasTooMuchOutGoing(processor))
    // need to apply backpressure
    return true;

  processor->incrementActiveTasks();
  try {
    processor->onTrigger(processContext, sessionFactory);
    processor->decrementActiveTask();
  } catch (Exception &exception) {
    // Normal exception
    logger_->log_debug("Caught Exception %s", exception.what());
    processor->decrementActiveTask();
  } catch (std::exception &exception) {
    logger_->log_debug("Caught Exception %s", exception.what());
    processor->yield(admin_yield_duration_);
    processor->decrementActiveTask();
  } catch (...) {
    logger_->log_debug("Caught Exception during SchedulingAgent::onTrigger");
    processor->yield(admin_yield_duration_);
    processor->decrementActiveTask();
  }

  return false;
}
Exemple #2
0
void
EventLoop::messagePump()
{
    MORDOR_LOG_DEBUG(g_log) << m_messageWindow << " starting message pump";
    while (!hasWorkToDo() && !stopping()) {
        MSG msg;
        BOOL bRet = GetMessageW(&msg, NULL, 0, 0);
        if (bRet < 0)
            MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("GetMessageW");
        if (bRet == 0) {
            stop();
            return;
        }
        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }
    MORDOR_LOG_DEBUG(g_log) << m_messageWindow << " exiting message pump";
}