Exemplo n.º 1
0
  public void schedule(TimerEntity timer) {
    Date duedate = timer.getDuedate();
    if (duedate == null) {
      throw new ActivitiException("duedate is null");
    }

    CommandContext commandContext = Context.getCommandContext();

    commandContext.getDbSqlSession().insert(timer);

    // Check if this timer fires before the next time the job executor will check for new timers to
    // fire.
    // This is highly unlikely because normally waitTimeInMillis is 5000 (5 seconds)
    // and timers are usually set further in the future

    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    int waitTimeInMillis = jobExecutor.getWaitTimeInMillis();
    if (duedate.getTime() < (ClockUtil.getCurrentTime().getTime() + waitTimeInMillis)) {
      // then notify the job executor.
      commandContext
          .getTransactionContext()
          .addTransactionListener(
              TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor));
    }
  }
Exemplo n.º 2
0
  public void send(MessageEntity message) {
    CommandContext commandContext = Context.getCommandContext();

    commandContext.getDbSqlSession().insert(message);

    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    commandContext
        .getTransactionContext()
        .addTransactionListener(
            TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor));
  }
Exemplo n.º 3
0
  public Object execute(CommandContext commandContext) {
    if (jobId == null) {
      throw new ActivitiException("jobId is null");
    }

    if (log.isLoggable(Level.FINE)) {
      log.fine("Executing job " + jobId);
    }
    JobEntity job = commandContext.getJobManager().findJobById(jobId);

    if (job == null) {
      throw new ActivitiException("No job found with id '" + jobId + "'");
    }

    JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
    if (jobExecutorContext != null) { // if null, then we are not called by the job executor
      jobExecutorContext.setCurrentJob(job);
    }

    try {
      job.execute(commandContext);
    } catch (RuntimeException exception) {
      // When transaction is rolled back, decrement retries
      CommandExecutor commandExecutor =
          Context.getProcessEngineConfiguration().getCommandExecutorTxRequiresNew();

      commandContext
          .getTransactionContext()
          .addTransactionListener(
              TransactionState.ROLLED_BACK,
              new DecrementJobRetriesListener(commandExecutor, jobId, exception));

      // throw the original exception to indicate the ExecuteJobCmd failed
      throw exception;
    } finally {
      if (jobExecutorContext != null) {
        jobExecutorContext.setCurrentJob(null);
      }
    }
    return null;
  }