Package org.jbpm.job

Examples of org.jbpm.job.Job


                {
                    final Set<Long> monitoredJobs = new HashSet<Long>() ;
                    final long now = System.currentTimeMillis() ;
                    do
                    {
                        final Job job = jobSession.getFirstDueJob(RETRY_EXECUTOR, monitoredJobs) ;
                        if ((job == null) || (job.getDueDate().getTime() > now))
                        {
                            break ;
                        }
                        monitoredJobs.add(Long.valueOf(job.getId())) ;
                        if (RETRY_EXECUTOR.equals(job.getLockOwner()))
                        {
                            job.setLockOwner(null) ;
                            if (job instanceof Timer)
                            {
                                final Timer timer = (Timer)job ;
                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug("Rescheduling timer " + timer.getId());
                                }
                                jbpmContext.getServices().getSchedulerService().createTimer(timer);
                            }
                            else
                            {
                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug("Rescheduling job " + job.getId());
                                }
                                jbpmContext.getServices().getMessageService().send(job) ;
                            }
                        }
                    }
View Full Code Here


     
      Date treshold = new Date(System.currentTimeMillis()-maxLockTime-lockBufferTime);
      List jobsWithOverdueLockTime = jobSession.findJobsWithOverdueLockTime(treshold);
      Iterator iter = jobsWithOverdueLockTime.iterator();
      while (iter.hasNext()) {
        Job job = (Job) iter.next();
        // unlock
        log.debug("unlocking "+job+ " owned by thread "+job.getLockOwner());
        job.setLockOwner(null);
        job.setLockTime(null);
        jobSession.saveJob(job);
      }

    } finally {
      try {
View Full Code Here

          Collection acquiredJobs = acquireJobs();

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

          } else { // no jobs acquired
            if (isActive) {
View Full Code Here

    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {
      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

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

  public JobSession(Session session) {
    this.session = session;
  }

  public Job getFirstAcquirableJob(String lockOwner) {
    Job job = null;
    try {
      Query query = session.getNamedQuery("JobSession.getFirstAcquirableJob");
      query.setString("lockOwner", lockOwner);
      query.setTimestamp("now", new Date());
      query.setMaxResults(1);
View Full Code Here

    }
    return jobs;
  }

  public Job getFirstDueJob(String lockOwner, Collection jobIdsToIgnore) {
    Job job = null;
    try {
      Query query = null;
      if ( (jobIdsToIgnore==null)
           || (jobIdsToIgnore.isEmpty() )
         ) {
View Full Code Here

      Collection acquiredJobs = acquireJobs();

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

     
View Full Code Here

    log.debug("acquiring jobs for execution...");

      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

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.