Package org.jbpm.job

Examples of org.jbpm.job.Job


  }

  public Object execute(JbpmContext jbpmContext) throws Exception {
    JobSession jobSession = jbpmContext.getJobSession();
    log.debug("loading job "+jobId);
    Job job = jobSession.loadJob(jobId);
    log.debug("executing job "+jobId);
    if (!job.execute(jbpmContext)) {
      log.warn("job "+jobId+" was not supposed to be deleted");
    }
    jobSession.deleteJob(job);
    return null;
  }
View Full Code Here


      if (!acquiredJobs.isEmpty())
      {
        Iterator iter = acquiredJobs.iterator();
        while (iter.hasNext())
        {
          Job job = (Job)iter.next();
          executeJob(job);
        }
      }

      // Job job = jbpmContext.getJobSession().getFirstAcquirableJob("");
View Full Code Here

    try
    {
      JobSession jobSession = jbpmContext.getJobSession();
      log.debug("querying for acquirable job...");
      Job job = jobSession.getFirstAcquirableJob(getName());
      if (job != null)
      {
        if (job.isExclusive())
        {
          log.debug("exclusive acquirable job found (" + job + "). querying for other exclusive jobs to lock them all in one tx...");
          List otherExclusiveJobs = jobSession.findExclusiveJobs(getName(), job.getProcessInstance());
          jobsToLock.addAll(otherExclusiveJobs);
          log.debug("trying to obtain a process-instance exclusive locks for '" + otherExclusiveJobs + "'");
        }
        else
        {
          log.debug("trying to obtain a lock for '" + job + "'");
          jobsToLock.add(job);
        }

        Iterator iter = jobsToLock.iterator();
        while (iter.hasNext())
        {
          job = (Job)iter.next();
          job.setLockOwner(getName());
          job.setLockTime(new Date());
          // jbpmContext.getSession().update(job);
        }

        // HACKY HACK : this is a workaround for a hibernate problem that is fixed in hibernate 3.2.1
        if (job instanceof Timer)
View Full Code Here

  protected Date getNextDueDate()
  {
    Date nextDueDate = null;
    JobSession jobSession = jbpmContext.getJobSession();
    Job job = jobSession.getFirstDueJob(getName(), new ArrayList());
    if (job != null)
    {
      nextDueDate = job.getDueDate();
    }
    return nextDueDate;
  }
View Full Code Here

      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      try {
        log.debug("querying for acquirable job...");
        String lockOwner = getName();
        JobSession jobSession = jbpmContext.getJobSession();
        Job job = jobSession.getFirstAcquirableJob(lockOwner);

        if (job != null) {
          if (job.isExclusive()) {
            ProcessInstance processInstance = job.getProcessInstance();
            log.debug("loaded exclusive " + job + ", finding exclusive jobs for " + processInstance);
            acquiredJobs = jobSession.findExclusiveJobs(lockOwner, processInstance);
            log.debug("trying to obtain locks on " + acquiredJobs + " for " + processInstance);
          }
          else {
View Full Code Here

    Date nextDueDate = null;
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
      JobSession jobSession = jbpmContext.getJobSession();
      Collection<Long> jobIdsToIgnore = jobExecutor.getMonitoredJobIds();
      Job job = jobSession.getFirstDueJob(getName(), jobIdsToIgnore);
      if (job != null) {
        nextDueDate = job.getDueDate();
        jobExecutor.addMonitoredJobId(getName(), job.getId());
      }
    }
    finally {
      try {
        jbpmContext.close();
View Full Code Here

            if (idValue instanceof Long) {
                id = ((Long)idValue).longValue();
            } else {
                id = Long.valueOf(idValue.toString()).longValue();
            }
            final Job job;
            job = context.getJbpmContext().getJobSession().getJob(id);
            if (job == null) {
                context.setError("Error loading job instance", "No job instance was found with an ID of " + id);
                return;
            }
View Full Code Here

                {
                    final Long jobId = (Long) jobDataMap.get(TIMER_ID) ;
                    if (jobId != null)
                    {
                        final JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext() ;
                        Job job = null ;
                        try
                        {
                            job = jbpmContext.getJobSession().loadJob(jobId) ;
                            if (job != null)
                            {
                                jbpmContext.getServices().getMessageService().send(job) ;
                                if (LOGGER.isDebugEnabled())
                                {
                                    LOGGER.debug("Firing job " + jobId) ;
                                }
                                return ;
                            }
                        }
                        catch (final RuntimeException re)
                        {
                            final Integer maxRefireCount = (Integer) jobDataMap.get(MAX_REFIRE_COUNT) ;
                            if ((maxRefireCount != null) && (maxRefireCount > context.getRefireCount()))
                            {
                                final JobExecutionException jobEx = new JobExecutionException(re, true);
                                jobEx.setErrorCode(JobExecutionException.ERR_JOB_EXECUTION_THREW_EXCEPTION);
                                throw jobEx ;
                            }
                            else
                            {
                                if (job != null)
                                {
                                    // zero the retries to remove from the list of outstanding jobs.
                                    job.setRetries(0) ;
                                }
                                throw re ;
                            }
                        }
                        finally
View Full Code Here

   * Execute the command.
   * @param jbpmContext The jBPM context associated with the execution.
   * @throws Exception for errors during execution.
   */
  public Object execute(JbpmContext jbpmContext) throws Exception {
    Job job = acquireJob(jbpmContext);
    if (JobUtil.isDeleted(job)) {
      if (log.isDebugEnabled()) {
        log.debug("job " + jobId + " was deleted");
      }
      return null;
    }
    if (job.isSuspended()) {
      if (log.isDebugEnabled()) {
        log.debug(job + " is suspended");
      }
      RetryExecutor.handleSuspendedJob(job) ;
      return null ;
    }
    if (redelivered) {
        if (job.getRetries() > 0) {
            job.setRetries(job.getRetries() - 1);
            if (log.isDebugEnabled()) {
              log.debug("Rescheduling job " + job.getId());
            }
            job.setLockOwner(null) ;
            jbpmContext.getServices().getMessageService().send(job) ;
        } else {
            log.error("Job retry count exceeded for job " + job.getId());
        }
        return null ;
    }
    executeJob(job, jbpmContext);
    return job;
View Full Code Here

    executeJob(job, jbpmContext);
    return job;
  }

  private Job acquireJob(JbpmContext jbpmContext) {
    Job job = jbpmContext.getJobSession().loadJob(jobId);

    // register process instance for automatic save
    // see https://jira.jboss.org/jira/browse/JBPM-1015
    ProcessInstance processInstance = job.getProcessInstance();
    jbpmContext.addAutoSaveProcessInstance(processInstance);

    // if job is exclusive, lock process instance
    if (job.isExclusive()) {
        jbpmContext.getGraphSession().lockProcessInstance(processInstance);
    }

    // mark job as locked to prevent other parts of the engine from deleting it
    job.setLockOwner(toString());
    return job;
  }
View Full Code Here

TOP

Related Classes of org.jbpm.job.Job

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.