Package org.jbpm

Examples of org.jbpm.JbpmContext


      return false;

    /* check whether the transaction is still active before scanning the exception handlers.
     * that way we can load the exception handlers lazily
     * see https://jira.jboss.org/jira/browse/JBPM-1775 */
    JbpmContext jbpmContext = executionContext.getJbpmContext();
    if (jbpmContext != null) {
      Services services = jbpmContext.getServices();
      if (services != null) {
        Service service = services.getPersistenceService();
        if (service instanceof DbPersistenceService) {
          DbPersistenceService persistenceService = (DbPersistenceService) service;
          return persistenceService.isTransactionActive() || persistenceService.getTransaction() == null;
View Full Code Here


    }
  }

  protected void unlockOverdueJobs() {
    List<Job> overdueJobs = null;
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
      Date threshold = new Date(System.currentTimeMillis() - maxLockTime - lockBufferTime);
      JobSession jobSession = jbpmContext.getJobSession();
      overdueJobs = jobSession.findJobsWithOverdueLockTime(threshold);
      for (Job job : overdueJobs) {
        log.debug("unlocking " + job + " owned by thread " + job.getLockOwner());
        job.setLockOwner(null);
        job.setLockTime(null);
      }
    }
    finally {
      try {
        jbpmContext.close();
      }
      catch (JbpmPersistenceException e) {
        // if this is a stale state exception, keep it quiet
        if (DbPersistenceService.isStaleStateException(e)) {
          log.debug("optimistic locking failed, could not unlock overdue jobs: " + overdueJobs);
View Full Code Here

   * on the proper graph object.
   *
   * @param command jBPM engine command to execute
   */
  public Object execute(Command command) {
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
      log.debug("executing " + command);
      return command.execute(jbpmContext);
    }
    catch (RuntimeException e) {
      jbpmContext.setRollbackOnly();
      log.error("failed to execute " + command, e);
      throw e;
    }
    catch (Exception e) {
      jbpmContext.setRollbackOnly();
      log.error("failed to execute " + command, e);
      throw new JbpmException("failed to execute " + command, e);
    }
    finally {
      jbpmContext.close();
    }
  }
View Full Code Here

  }

  protected Collection<Job> acquireJobs() {
    Collection<Job> acquiredJobs = Collections.emptyList();
    synchronized (jobExecutor) {
      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 {
            acquiredJobs = Collections.singletonList(job);
            log.debug("trying to obtain lock on " + job);
          }

          Date lockTime = new Date();
          for (Job acquiredJob : acquiredJobs) {
            acquiredJob.setLockOwner(lockOwner);
            acquiredJob.setLockTime(lockTime);
          }
        }
        else {
          log.debug("no acquirable jobs");
        }
      }
      finally {
        try {
          jbpmContext.close();
          log.debug("obtained lock on jobs: " + acquiredJobs);
        }
        catch (JbpmPersistenceException e) {
          // if this is a stale state exception, keep it quiet
          if (DbPersistenceService.isStaleStateException(e)) {
View Full Code Here

    }
    return acquiredJobs;
  }

  protected void executeJob(Job job) {
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
      JobSession jobSession = jbpmContext.getJobSession();
      job = jobSession.loadJob(job.getId());

      log.debug("executing " + job);
      try {
        if (job.execute(jbpmContext)) {
          jobSession.deleteJob(job);
        }
      }
      catch (Exception e) {
        log.debug("exception while executing " + job, e);
        if (!DbPersistenceService.isPersistenceException(e)) {
          StringWriter memoryWriter = new StringWriter();
          e.printStackTrace(new PrintWriter(memoryWriter));
          job.setException(memoryWriter.toString());
          job.setRetries(job.getRetries() - 1);
        }
        else {
          // allowing a transaction to proceed after a persistence exception is unsafe
          jbpmContext.setRollbackOnly();
        }
      }

      // if this job is locked too long
      long totalLockTimeInMillis = System.currentTimeMillis() - job.getLockTime().getTime();
      if (totalLockTimeInMillis > maxLockTime) {
        jbpmContext.setRollbackOnly();
      }
    }
    finally {
      try {
        jbpmContext.close();
      }
      catch (JbpmPersistenceException e) {
        // if this is a stale state exception, keep it quiet
        if (DbPersistenceService.isStaleStateException(e)) {
          log.debug("optimistic locking failed, could not complete job " + job);
View Full Code Here

    }
  }

  protected Date getNextDueDate() {
    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();
      }
      catch (JbpmPersistenceException e) {
        // if this is a stale state exception, keep it quiet
        if (DbPersistenceService.isStaleStateException(e)) {
          log.debug("optimistic locking failed, could not return next due date: " + nextDueDate);
View Full Code Here

  JobSession jobSession = null;
  JobExecutor jobExecutor = null;
  boolean hasProducedJobs = false;
 
  public DbMessageService() {
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext==null) {
      throw new JbpmException("instantiation of the DbMessageService requires a current JbpmContext");
    }
    jobSession = jbpmContext.getJobSession();
    jobExecutor = jbpmContext.getJbpmConfiguration().getJobExecutor();
  }
View Full Code Here

  protected void setObject(Object value) {
    if (token!=null) token.addLog(new ByteArrayUpdateLog(this, this.value, (ByteArray) value));
    // delete old value, otherwise it will be unreachable
    if (this.value != null) {
      JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
      if (jbpmContext != null) {
        Session session = jbpmContext.getSession();
        if (session != null) session.delete(this.value);
      }     
    }
    // set new value
    this.value = (ByteArray) value;
View Full Code Here

  private static final long serialVersionUID = 1L;

  Session session = null;

  public DbLoggingService() {
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext == null) {
      throw new JbpmException("instantiation of the DbLoggingService requires a current JbpmContext");
    }
    session = jbpmContext.getSession();
  }
View Full Code Here

    }
  }

  void suspendJobs()
  {
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    JobSession jobSession = (jbpmContext != null ? jbpmContext.getJobSession() : null);
    if (jobSession != null)
    {
      jobSession.suspendJobs(this);
    }
  }
View Full Code Here

TOP

Related Classes of org.jbpm.JbpmContext

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.