/**
  * 添加一个定时任务
  *
  * @param jobName 任务名
  * @param jobGroupName 任务组名
  * @param triggerName 触发器名
  * @param triggerGroupName 触发器组名
  * @param job 任务
  * @param cronExpression 时间设置,参考quartz说明文档
  */
 public static void addJob(
     String jobName,
     String jobGroupName,
     String triggerName,
     String triggerGroupName,
     Job job,
     String cronExpression)
     throws SchedulerException, ParseException {
   if (StringUtils.isBlank(jobGroupName)) {
     jobGroupName = JOB_GROUP_NAME;
   }
   if (StringUtils.isBlank(triggerGroupName)) {
     triggerGroupName = TRIGGER_GROUP_NAME;
   }
   Scheduler sched = sf.getScheduler();
   //	       JobDetail jobDetail = new JobDetail(jobName, jobGroupName,
   // job.getClass());//任务名,任务组,任务执行类
   //	       CronTrigger  trigger = new
   // CronTrigger(jobName,triggerGroupName,cronExpression);//触发器名,触发器组,cron表达式
   //	       sched.scheduleJob(jobDetail,trigger);
   // 启动
   if (!sched.isShutdown()) {
     sched.start();
   }
 }
 /**
  * Check if the scheduler is stopped.
  *
  * @throws JobSchedulerException thrown if the scheduler status cannot be checked
  */
 public boolean isStopped() throws JobSchedulerException {
   try {
     return scheduler.isShutdown();
   } catch (SchedulerException e) {
     throw new JobSchedulerException(
         "An exception occurred during checking if the scheduler is stopped", e);
   }
 }
 /** @see org.sakaiproject.api.app.scheduler.SchedulerManager#destroy() */
 public void destroy() {
   try {
     if (!scheduler.isShutdown()) {
       scheduler.shutdown();
     }
   } catch (Throwable t) {
     LOG.error("An error occurred while stopping the scheduler", t);
   }
 }
 /**
  * reschedule the job associated with the given old trigger with the new trigger.
  *
  * @param oldTriggerName - the name of the trigger to remove.
  * @param oldTriggerGroup - the group of the trigger to remove.
  * @param newTrigger - the new Trigger to associate the job with
  */
 @Override
 public void rescheduleAJob(String oldTriggerName, String oldTriggerGroup, Trigger newTrigger) {
   try {
     if (!sched.isShutdown()) {
       sched.rescheduleJob(triggerKey(oldTriggerName, oldTriggerGroup), newTrigger);
     }
   } catch (SchedulerException se) {
     log.error("failed to reschedule the job: {}", se.getMessage());
     log.debug("Exception", se);
   }
 }
Beispiel #5
0
 /** 恢复手工停止的作业. */
 public void resumeManualStopedJob() {
   try {
     if (scheduler.isShutdown()) {
       return;
     }
     scheduler.resumeAll();
     // TODO 恢复stoped=fasle状态
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
   serverService.clearJobStopedStatus();
 }
 /** 恢复手工停止的作业. */
 public void resumeManualStopedJob() {
   try {
     if (scheduler.isShutdown()) {
       return;
     }
     JobRegistry.getInstance().getJobInstance(jobConfiguration.getJobName()).resume();
     scheduler.resumeAll();
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
   serverService.clearJobStopedStatus();
 }
Beispiel #7
0
 /**
  * Description:关闭调度器
  *
  * @return true:关闭成功|false:关闭失败
  * @author lijw
  * @since 2013-5-31
  */
 public boolean shutdown() {
   try {
     if (scheduler.isShutdown()) {
       return true;
     } else {
       scheduler.shutdown();
       return true;
     }
   } catch (SchedulerException e) {
     logger.error("调度器关闭异常:" + e.getMessage());
     return false;
   }
 }
Beispiel #8
0
 /**
  * Description:判断调度器状态
  *
  * @return 0:已关闭|1:已启动|-1:状态异常,可能未初始化
  * @author 李降伟
  * @since 2013-5-31
  */
 public int getState() {
   try {
     if (scheduler.isStarted()) {
       return 1; // 已启动
     } else if (scheduler.isShutdown()) {
       return 0; // 已关闭
     } else {
       return -1; // 未实现化
     }
   } catch (SchedulerException e) {
     logger.error("调度器状态获取异常:" + e.getMessage());
     return -1; // 异常
   }
 }
Beispiel #9
0
  public static void startJob(String jobName, Job job, String time)
      throws SchedulerException, ParseException {
    Scheduler sched = sf.getScheduler();

    JobDetail jobDetail = new JobDetail();
    jobDetail.setName(jobName);
    jobDetail.setGroup(JOB_GROUP_NAME);
    jobDetail.setJobClass(job.getClass());

    CronTrigger trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);
    trigger.setCronExpression(time);
    sched.scheduleJob(jobDetail, trigger);

    if (!sched.isShutdown()) {
      sched.start();
    }
  }
  protected boolean isEnabled(StorageType storageType) throws SchedulerException {

    if (!isEnabled()) {
      return false;
    }

    Scheduler scheduler = getScheduler(storageType);

    try {
      if (scheduler.isShutdown() || scheduler.isInStandbyMode()) {
        return false;
      }
    } catch (org.quartz.SchedulerException se) {
      throw new SchedulerException(se);
    }

    return true;
  }
Beispiel #11
0
  /**
   * 添加一个定时任务
   *
   * @param jobName 任务名
   * @param jobGroupName 任务组名
   * @param triggerName 触发器名
   * @param triggerGroupName 触发器组名
   * @param job 任务
   * @throws SchedulerException
   * @throws ParseException
   */
  public void addJob(
      String jobName,
      String jobGroupName,
      String triggerName,
      String triggerGroupName,
      Job job,
      String scheduletype)
      throws SchedulerException, ParseException {
    Scheduler sched = sf.getScheduler();
    JobDetail jobDetail = new JobDetail(jobName, jobGroupName, job.getClass()); // 任务名,任务组,任务执行类
    jobDetail.getJobDataMap().put(JUST_SCHEDULE_RETURN, justSchedule);
    Trigger trigger = null;
    // 触发器
    if (SCHEDULE_TYPE_TRIGGER_SIMPLE.equals(scheduletype)) {
      trigger = (SimpleTrigger) triggerManager.getSimpleTrigger(triggerName, triggerGroupName);

    } else if (SCHEDULE_TYPE_TRIGGER_CRON.equals(scheduletype)) {
      /* CronTrigger  trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);//触发器名,触发器组
      trigger.setCronExpression(time);//触发器时间设定	*/
      trigger = (CronTrigger) triggerManager.getCronTrigger(triggerName, triggerGroupName);
    }
    sched.scheduleJob(jobDetail, trigger);
    if (!sched.isShutdown()) sched.start();
  }
  @Test
  public void testExecuteBuildNumberMissing() throws Exception {
    expect(mockBarrier.await(20, TimeUnit.SECONDS)).andReturn(true);
    expect(mockBeanFactory.getInstance(currentUser)).andReturn(new MockI18nHelper()).anyTimes();

    // called during validation!
    expect(mockPermissionManager.hasPermission(Permissions.SYSTEM_ADMIN, currentUser))
        .andReturn(true);

    // This is called during the first parse of the XML file.  At this stage nothing should have
    // been created yet!
    final MockGenericValue mockGv = new MockGenericValue("someentity");
    expect(mockOfBizDelegator.makeValue(EasyMock.<String>anyObject())).andReturn(mockGv).anyTimes();
    expect(mockAttachmentPathManager.getDefaultAttachmentPath())
        .andReturn(directories.get(0).getAbsolutePath())
        .anyTimes();
    expect(mockIndexPathManager.getDefaultIndexRootPath())
        .andReturn(directories.get(1).getAbsolutePath())
        .anyTimes();
    expect(
            mockLicenseStringFactory.create(
                EasyMock.<String>anyObject(), EasyMock.<String>anyObject()))
        .andStubReturn("");

    // after the first parse check the build number.
    expect(mockBuildUtilsInfo.getCurrentBuildNumber()).andStubReturn("1");
    expect(mockBuildUtilsInfo.getMinimumUpgradableBuildNumber()).andStubReturn("0");

    // after the first parse we also verify the license is good.
    expect(
            mockJiraLicenseService.validate(
                EasyMock.<I18nHelper>anyObject(), EasyMock.<String>anyObject()))
        .andStubReturn(mockValidationResult);
    expect(mockValidationResult.getLicenseVersion()).andStubReturn(2);
    expect(mockValidationResult.getErrorCollection()).andStubReturn(new SimpleErrorCollection());

    // this gets called during shutdownAndFlushAsyncServices.  After parse and before the import.
    // This shuts down
    // the scheduler
    expect(mockScheduler.isShutdown()).andReturn(false);
    mockScheduler.shutdown();
    mockMailQueue.sendBuffer();
    expect(mockTaskManager.shutdownAndWait(5)).andReturn(true);

    // Expect AO to be cleared.
    backup.clear();

    // Once the import is running one of the first things to do is to clear out the old database
    // values.
    expect(mockOfBizDelegator.getModelReader()).andReturn(mockModelReader);
    expect(mockModelReader.getEntityNames())
        .andReturn(CollectionBuilder.<String>list("Issue", "User"));
    expect(mockModelReader.getModelEntity("Issue")).andReturn(new ModelEntity());
    expect(mockOfBizDelegator.removeByAnd("Issue", Collections.<String, Object>emptyMap()))
        .andReturn(10);
    expect(mockModelReader.getModelEntity("User")).andReturn(new ModelEntity());
    expect(mockOfBizDelegator.removeByAnd("User", Collections.<String, Object>emptyMap()))
        .andReturn(5);

    // then we go through and create all our GVs (already mocked out during the first parse above)

    // once everything's been imported need to refresh the ofbiz sequencer and check for data
    // consistency.
    mockOfBizDelegator.refreshSequencer();
    mockConsistencyChecker.checkDataConsistency();

    // after the consistency check lets do the upgrade
    expect(mockUpgradeManager.doUpgradeIfNeededAndAllowed(null))
        .andReturn(Collections.<String>emptyList());

    // now do a reindex
    mockIndexManager.deactivate();
    expect(mockIndexManager.size()).andReturn(5);
    expect(mockIndexManager.activate((Context) notNull())).andReturn(1L);

    // raise the JiraStartedEvent
    mockPluginEventManager.broadcast(EasyMock.<JiraStartedEvent>anyObject());

    // finally we can restart the scheduler!
    expect(
            mockScheduler.scheduleJob(
                EasyMock.<JobDetail>anyObject(), EasyMock.<Trigger>anyObject()))
        .andReturn(new Date())
        .anyTimes();
    mockScheduler.start();

    final String filePath = getDataFilePath("jira-export-test-no-build-number.xml");
    final DataImportParams params = new DataImportParams.Builder(filePath).build();

    // Finally everything's mocked out.  Run the import!
    executeTest(params, true, DataImportService.ImportError.NONE);

    // create() should have been called on our GVs
    assertTrue(mockGv.isCreated());
    // the world should have been rebuilt!
    assertTrue(((MockDataImportDependencies) mockDependencies).globalRefreshCalled);
  }