Java 类org.quartz.Trigger.TriggerState 实例源码

项目:quartz-web    文件:QuartzUtils.java   
/**
 * 将TriggerState英文翻译成中文
 * @param triggerState
 * @return
 */
public static String triggerStateEN2CN(TriggerState triggerState){
    if (TriggerState.NORMAL.ordinal() == triggerState.ordinal()) {
        return "正常";
    } else if (TriggerState.PAUSED.ordinal() == triggerState.ordinal()) {
        return "暂停";
    } else if (TriggerState.COMPLETE.ordinal() == triggerState.ordinal()) {
        return "完成";
    } else if (TriggerState.ERROR.ordinal() == triggerState.ordinal()) {
        return "错误";
    } else if (TriggerState.BLOCKED.ordinal() == triggerState.ordinal()) {
        return "阻塞";
    } else {
        return "无";
    }
}
项目:taboola-cronyx    文件:QuartzSchedulerServiceImpl.java   
private static TriggerStatus quartzTriggerStateToTriggerStatus(Trigger quartzTrigger, TriggerState quartzTriggerState) {
    if (quartzTrigger != null && quartzTrigger.getJobDataMap().containsKey(Constants.JOB_EXCEPTION)) {
        return TriggerStatus.ERROR;
    }

    if (quartzTriggerState == null) {
        return null;
    }

    switch (quartzTriggerState) {
        case PAUSED:
            return TriggerStatus.PAUSED;
        case COMPLETE:
            return TriggerStatus.COMPLETE;
        case ERROR:
            return TriggerStatus.ERROR;
        case NORMAL:
        case BLOCKED:
            return TriggerStatus.ACTIVE;
        default:
            return null;
    }
}
项目:mangooio    文件:Scheduler.java   
/**
 * Retrieves a list of all jobs and their current status
 * 
 * @return List of io.mangoo.models.Job objects
 * @throws MangooSchedulerException if an error occurs during access to the Quartz Scheduler
 */
@SuppressWarnings("unchecked")
public List<io.mangoo.models.Job> getAllJobs() throws MangooSchedulerException {
    Objects.requireNonNull(this.quartzScheduler, Required.SCHEDULER.toString());

    List<io.mangoo.models.Job> jobs = new ArrayList<>();
    try {
        for (JobKey jobKey : getAllJobKeys()) {
            List<Trigger> triggers = (List<Trigger>) this.quartzScheduler.getTriggersOfJob(jobKey);
            Trigger trigger = triggers.get(0);  
            TriggerState triggerState = quartzScheduler.getTriggerState(trigger.getKey());
            jobs.add(new io.mangoo.models.Job(TriggerState.PAUSED == triggerState ? false : true, jobKey.getName(), trigger.getDescription(), trigger.getNextFireTime(), trigger.getPreviousFireTime()));
        }
    } catch (SchedulerException e) {
        throw new MangooSchedulerException(e);
    }

    return jobs;
}
项目:mangooio    文件:Scheduler.java   
/**
 * Changes the state of a normally running job from pause to resume or resume to pause
 * 
 * @param jobName The name of the job
 * @throws MangooSchedulerException if an error occurs during access to the quartz scheduler
 */
public void changeState(String jobName) throws MangooSchedulerException {
    Objects.requireNonNull(this.quartzScheduler, Required.SCHEDULER.toString());

    try {
        for (JobKey jobKey : getAllJobKeys()) {
            if (jobKey.getName().equalsIgnoreCase(jobName)) {
                TriggerState triggerState = getTriggerState(jobKey);
                if (TriggerState.NORMAL == triggerState) {
                    this.quartzScheduler.pauseJob(jobKey);                        
                } else {
                    this.quartzScheduler.resumeJob(jobKey);
                }
            }
        }            
    } catch (SchedulerException | MangooSchedulerException e) {
        throw new MangooSchedulerException(e);
    }
}
项目:mangooio    文件:SchedulerTest.java   
@Test
@SuppressWarnings("unchecked")
public void testPauseJob() throws MangooSchedulerException, SchedulerException {
    //given
    JobKey jobKey = scheduler.getJobKey("jobs.InfoJob");

    //when
    scheduler.pauseJob("jobs.InfoJob");

    //then
    List<Trigger> triggers = (List<Trigger>) scheduler.getQuartzScheduler().getTriggersOfJob(jobKey);
    Trigger trigger = triggers.get(0);  
    TriggerState triggerState = scheduler.getQuartzScheduler().getTriggerState(trigger.getKey());

    assertThat(triggerState, equalTo(TriggerState.PAUSED));
}
项目:mangooio    文件:SchedulerTest.java   
@Test
@SuppressWarnings("unchecked")
public void testResumeJob() throws MangooSchedulerException, SchedulerException {
    //given
    JobKey jobKey = scheduler.getJobKey("jobs.InfoJob");

    //when
    scheduler.resumeJob("jobs.InfoJob");

    //then
    List<Trigger> triggers = (List<Trigger>) scheduler.getQuartzScheduler().getTriggersOfJob(jobKey);
    Trigger trigger = triggers.get(0);  
    TriggerState triggerState = scheduler.getQuartzScheduler().getTriggerState(trigger.getKey());

    assertThat(triggerState, equalTo(TriggerState.NORMAL));
}
项目:redis-quartz    文件:RedisJobStore.java   
@Override
public TriggerState getTriggerState(TriggerKey triggerKey)
        throws JobPersistenceException {
    String triggerHashKey = createTriggerHashKey(triggerKey.getGroup(), triggerKey.getName());
     try (Jedis jedis = pool.getResource()) {
        lockPool.acquire();

        if (jedis.zscore(RedisTriggerState.PAUSED.getKey(), triggerHashKey) != null || jedis.zscore(RedisTriggerState.PAUSED_BLOCKED.getKey(), triggerHashKey)!= null)
            return TriggerState.PAUSED;
        else if (jedis.zscore(RedisTriggerState.BLOCKED.getKey(), triggerHashKey) != null)
            return TriggerState.BLOCKED;
        else if (jedis.zscore(RedisTriggerState.WAITING.getKey(), triggerHashKey) != null || jedis.zscore(RedisTriggerState.ACQUIRED.getKey(), triggerHashKey) != null)
            return TriggerState.NORMAL;
        else if (jedis.zscore(RedisTriggerState.COMPLETED.getKey(), triggerHashKey) != null)
            return TriggerState.COMPLETE;
        else if (jedis.zscore(RedisTriggerState.ERROR.getKey(), triggerHashKey) != null)
            return TriggerState.ERROR;
        else
            return TriggerState.NONE;
    } catch (Exception ex) {
        log.error("could not get trigger state: " + triggerHashKey, ex);
        throw new JobPersistenceException(ex.getMessage(), ex.getCause());
    } finally {
        lockPool.release();
    }
}
项目:carbon-commons    文件:AbstractQuartzTaskManager.java   
private TaskState triggerStateToTaskState(TriggerState triggerState) {
    if (triggerState == TriggerState.NONE) {
        return TaskState.NONE;
    } else if (triggerState == TriggerState.PAUSED) {
        return TaskState.PAUSED;
    } else if (triggerState == TriggerState.COMPLETE) {
        return TaskState.FINISHED;
    } else if (triggerState == TriggerState.ERROR) {
        return TaskState.ERROR;
    } else if (triggerState == TriggerState.NORMAL) {
        return TaskState.NORMAL;
    } else if (triggerState == TriggerState.BLOCKED) {
        return TaskState.BLOCKED;
    } else {
        return TaskState.UNKNOWN;
    }
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testRemoveTrigger() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  JobDetail storeJob = storeJob(buildJob("job"));
  Trigger trigger1 = buildTrigger(storeJob);
  TriggerKey triggerKey = trigger1.getKey();
  storeTrigger(trigger1);
  Trigger retrieveTrigger = retrieveTrigger(trigger1.getKey());
  assertThat(retrieveTrigger).isNotNull();
  boolean removeTrigger = jobStore.removeTrigger(triggerKey);
  assertThat(removeTrigger).isTrue();
  retrieveTrigger = retrieveTrigger(trigger1.getKey());
  assertThat(retrieveTrigger).isNull();
  removeTrigger = jobStore.removeTrigger(triggerKey);
  assertThat(removeTrigger).isFalse();

  TriggerState triggerState = jobStore.getTriggerState(triggerKey);
  assertThat(triggerState).isEqualTo(TriggerState.NONE);
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testResumeTrigger() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  Trigger trigger = buildTrigger();
  storeTrigger(trigger);
  TriggerKey triggerKey = trigger.getKey();
  TriggerState triggerState = jobStore.getTriggerState(triggerKey);
  assertThat(triggerState).isEqualTo(TriggerState.NORMAL);
  jobStore.pauseTrigger(triggerKey);
  triggerState = jobStore.getTriggerState(triggerKey);
  assertThat(triggerState).isEqualTo(TriggerState.PAUSED);

  jobStore.resumeTrigger(triggerKey);
  triggerState = jobStore.getTriggerState(triggerKey);
  assertThat(triggerState).isEqualTo(TriggerState.NORMAL);
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testResumeTriggerWithPausedJobs()
    throws ObjectAlreadyExistsException, JobPersistenceException {
  JobDetail job1 = buildJob("job", "group3");
  storeJob(job1);
  Trigger trigger5 = buildTrigger(job1);
  storeTrigger(trigger5);

  assertThat(jobStore.getTriggerState(trigger5.getKey())).isEqualTo(
      TriggerState.NORMAL);
  jobStore.pauseJobs(GroupMatcher.jobGroupEquals("group3"));
  jobStore.resumeTriggers(GroupMatcher.triggerGroupEquals(trigger5.getKey()
      .getGroup()));
  assertThat(jobStore.getTriggerState(trigger5.getKey())).isEqualTo(
      TriggerState.PAUSED);
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testResumeJob() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  JobDetail jobDetail = buildAndStoreJob();
  Trigger trigger = buildTrigger(jobDetail);
  storeTrigger(trigger);
  TriggerState triggerState = jobStore.getTriggerState(trigger.getKey());
  assertThat(triggerState).isEqualTo(TriggerState.NORMAL);

  jobStore.pauseJob(jobDetail.getKey());

  triggerState = jobStore.getTriggerState(trigger.getKey());
  assertThat(triggerState).isEqualTo(TriggerState.PAUSED);

  jobStore.resumeJob(jobDetail.getKey());

  triggerState = jobStore.getTriggerState(trigger.getKey());
  assertThat(triggerState).isEqualTo(TriggerState.NORMAL);
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testPauseAll() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  Trigger trigger = buildAndStoreTrigger();
  Trigger trigger2 = buildTrigger("trigger2", "group2", buildAndStoreJob());
  storeTrigger(trigger2);
  assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo(
      TriggerState.NORMAL);

  jobStore.pauseAll();

  assertThat(jobStore.getPausedTriggerGroups()).containsOnly(
      trigger.getKey().getGroup(), trigger2.getKey().getGroup());

  Trigger trigger3 = buildAndStoreTrigger();

  assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo(
      TriggerState.PAUSED);
  assertThat(jobStore.getTriggerState(trigger2.getKey())).isEqualTo(
      TriggerState.PAUSED);
  assertThat(jobStore.getTriggerState(trigger3.getKey())).isEqualTo(
      TriggerState.PAUSED);
}
项目:iBase4J-Common    文件:SchedulerManager.java   
public List<TaskScheduled> getAllJobDetail() {
    List<TaskScheduled> result = new LinkedList<TaskScheduled>();
    try {
        GroupMatcher<JobKey> matcher = GroupMatcher.jobGroupContains("");
        Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
        for (JobKey jobKey : jobKeys) {
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
            for (Trigger trigger : triggers) {
                TaskScheduled job = new TaskScheduled();
                job.setTaskName(jobKey.getName());
                job.setTaskGroup(jobKey.getGroup());
                TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
                job.setStatus(triggerState.name());
                if (trigger instanceof CronTrigger) {
                    CronTrigger cronTrigger = (CronTrigger)trigger;
                    String cronExpression = cronTrigger.getCronExpression();
                    job.setTaskCron(cronExpression);
                }
                job.setPreviousFireTime(trigger.getPreviousFireTime());
                job.setNextFireTime(trigger.getNextFireTime());
                JobDataMap jobDataMap = trigger.getJobDataMap();
                job.setTaskType(jobDataMap.getString("taskType"));
                job.setTargetSystem(jobDataMap.getString("targetSystem"));
                job.setTargetObject(jobDataMap.getString("targetObject"));
                job.setTargetMethod(jobDataMap.getString("targetMethod"));
                job.setContactName(jobDataMap.getString("contactName"));
                job.setContactEmail(jobDataMap.getString("contactEmail"));
                job.setTaskDesc(jobDetail.getDescription());
                String jobClass = jobDetail.getJobClass().getSimpleName();
                if (jobClass.equals("StatefulJob")) {
                    job.setJobType("statefulJob");
                } else if (jobClass.equals("DefaultJob")) {
                    job.setJobType("job");
                }
                result.add(job);
            }
        }
    } catch (Exception e) {
        logger.error("Try to load All JobDetail cause error : ", e);
    }
    return result;
}
项目:spring-boot-quartz-demo    文件:JobServiceImpl.java   
/**
 * Get the current state of job
 */
public String getJobState(String jobName) {
    System.out.println("JobServiceImpl.getJobState()");

    try {
        String groupKey = "SampleGroup";
        JobKey jobKey = new JobKey(jobName, groupKey);

        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        JobDetail jobDetail = scheduler.getJobDetail(jobKey);

        List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobDetail.getKey());
        if(triggers != null && triggers.size() > 0){
            for (Trigger trigger : triggers) {
                TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());

                if (TriggerState.PAUSED.equals(triggerState)) {
                    return "PAUSED";
                }else if (TriggerState.BLOCKED.equals(triggerState)) {
                    return "BLOCKED";
                }else if (TriggerState.COMPLETE.equals(triggerState)) {
                    return "COMPLETE";
                }else if (TriggerState.ERROR.equals(triggerState)) {
                    return "ERROR";
                }else if (TriggerState.NONE.equals(triggerState)) {
                    return "NONE";
                }else if (TriggerState.NORMAL.equals(triggerState)) {
                    return "SCHEDULED";
                }
            }
        }
    } catch (SchedulerException e) {
        System.out.println("SchedulerException while checking job with name and group exist:"+e.getMessage());
        e.printStackTrace();
    }
    return null;
}
项目:automat    文件:SchedulerManager.java   
public List<TaskScheduled> getAllJobDetail() {
    List<TaskScheduled> result = new LinkedList<TaskScheduled>();
    try {
        GroupMatcher<JobKey> matcher = GroupMatcher.jobGroupContains("");
        Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
        for (JobKey jobKey : jobKeys) {
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
            for (Trigger trigger : triggers) {
                TaskScheduled job = new TaskScheduled();
                job.setTaskName(jobKey.getName());
                job.setTaskGroup(jobKey.getGroup());
                TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
                job.setStatus(triggerState.name());
                if (trigger instanceof CronTrigger) {
                    CronTrigger cronTrigger = (CronTrigger)trigger;
                    String cronExpression = cronTrigger.getCronExpression();
                    job.setTaskCron(cronExpression);
                }
                job.setPreviousFireTime(trigger.getPreviousFireTime());
                job.setNextFireTime(trigger.getNextFireTime());
                JobDataMap jobDataMap = trigger.getJobDataMap();
                job.setTaskType(jobDataMap.getString("taskType"));
                job.setTargetSystem(jobDataMap.getString("targetSystem"));
                job.setTargetObject(jobDataMap.getString("targetObject"));
                job.setTargetMethod(jobDataMap.getString("targetMethod"));
                job.setContactName(jobDataMap.getString("contactName"));
                job.setContactEmail(jobDataMap.getString("contactEmail"));
                job.setTaskDesc(jobDetail.getDescription());
                String jobClass = jobDetail.getJobClass().getSimpleName();
                if (jobClass.equals("StatefulJob")) {
                    job.setJobType("statefulJob");
                } else if (jobClass.equals("DefaultJob")) {
                    job.setJobType("job");
                }
                result.add(job);
            }
        }
    } catch (Exception e) {
        logger.error("Try to load All JobDetail cause error : ", e);
    }
    return result;
}
项目:lams    文件:RAMJobStore.java   
/**
 * <p>
 * Get the current state of the identified <code>{@link Trigger}</code>.
 * </p>
 *
 * @see TriggerState#NORMAL
 * @see TriggerState#PAUSED
 * @see TriggerState#COMPLETE
 * @see TriggerState#ERROR
 * @see TriggerState#BLOCKED
 * @see TriggerState#NONE
 */
public TriggerState getTriggerState(TriggerKey triggerKey) throws JobPersistenceException {
    synchronized(lock) {
        TriggerWrapper tw = triggersByKey.get(triggerKey);

        if (tw == null) {
            return TriggerState.NONE;
        }

        if (tw.state == TriggerWrapper.STATE_COMPLETE) {
            return TriggerState.COMPLETE;
        }

        if (tw.state == TriggerWrapper.STATE_PAUSED) {
            return TriggerState.PAUSED;
        }

        if (tw.state == TriggerWrapper.STATE_PAUSED_BLOCKED) {
            return TriggerState.PAUSED;
        }

        if (tw.state == TriggerWrapper.STATE_BLOCKED) {
            return TriggerState.BLOCKED;
        }

        if (tw.state == TriggerWrapper.STATE_ERROR) {
            return TriggerState.ERROR;
        }

        return TriggerState.NORMAL;
    }
}
项目:lams    文件:RemoteMBeanScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
public TriggerState getTriggerState(TriggerKey triggerKey)
    throws SchedulerException {
    return TriggerState.valueOf((String)invoke(
            "getTriggerState",
            new Object[] { triggerKey.getName(), triggerKey.getGroup() },
            new String[] { String.class.getName(), String.class.getName() }));
}
项目:lams    文件:JobStoreSupport.java   
public TriggerState getTriggerState(Connection conn, TriggerKey key)
    throws JobPersistenceException {
    try {
        String ts = getDelegate().selectTriggerState(conn, key);

        if (ts == null) {
            return TriggerState.NONE;
        }

        if (ts.equals(STATE_DELETED)) {
            return TriggerState.NONE;
        }

        if (ts.equals(STATE_COMPLETE)) {
            return TriggerState.COMPLETE;
        }

        if (ts.equals(STATE_PAUSED)) {
            return TriggerState.PAUSED;
        }

        if (ts.equals(STATE_PAUSED_BLOCKED)) {
            return TriggerState.PAUSED;
        }

        if (ts.equals(STATE_ERROR)) {
            return TriggerState.ERROR;
        }

        if (ts.equals(STATE_BLOCKED)) {
            return TriggerState.BLOCKED;
        }

        return TriggerState.NORMAL;

    } catch (SQLException e) {
        throw new JobPersistenceException(
                "Couldn't determine state of trigger (" + key + "): " + e.getMessage(), e);
    }
}
项目:lams    文件:RemoteScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public TriggerState getTriggerState(TriggerKey triggerKey)
    throws SchedulerException {
    try {
        return getRemoteScheduler().getTriggerState(triggerKey);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:lams    文件:QuartzSchedulerMBeanImpl.java   
public String getTriggerState(String triggerName, String triggerGroupName) throws Exception {
    try {
        TriggerKey triggerKey = triggerKey(triggerName, triggerGroupName);
        TriggerState ts = scheduler.getTriggerState(triggerKey);
        return ts.name();
    } catch (Exception e) {
        throw newPlainException(e);
    }
}
项目:stage-job    文件:XxlJobDynamicScheduler.java   
/**
    * fill job info
    *
    * @param jobInfo
    */
public static void fillJobInfo(XxlJobInfo jobInfo) {
    // TriggerKey : name + group
       String group = String.valueOf(jobInfo.getJobGroup());
       String name = String.valueOf(jobInfo.getId());
       TriggerKey triggerKey = TriggerKey.triggerKey(name, group);

       try {
        Trigger trigger = scheduler.getTrigger(triggerKey);

        TriggerState triggerState = scheduler.getTriggerState(triggerKey);

        // parse params
        if (trigger!=null && trigger instanceof CronTriggerImpl) {
            String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
            jobInfo.setJobCron(cronExpression);
        }

        //JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
           //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
           //String jobClass = jobDetail.getJobClass().getName();

        if (triggerState!=null) {
            jobInfo.setJobStatus(triggerState.name());
        }

    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    }
}
项目:iBase4J    文件:SchedulerManager.java   
public List<TaskScheduled> getAllJobDetail() {
    List<TaskScheduled> result = new LinkedList<TaskScheduled>();
    try {
        GroupMatcher<JobKey> matcher = GroupMatcher.jobGroupContains("");
        Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
        for (JobKey jobKey : jobKeys) {
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
            for (Trigger trigger : triggers) {
                TaskScheduled job = new TaskScheduled();
                job.setTaskName(jobKey.getName());
                job.setTaskGroup(jobKey.getGroup());
                TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
                job.setStatus(triggerState.name());
                if (trigger instanceof CronTrigger) {
                    CronTrigger cronTrigger = (CronTrigger)trigger;
                    String cronExpression = cronTrigger.getCronExpression();
                    job.setTaskCron(cronExpression);
                }
                job.setPreviousFireTime(trigger.getPreviousFireTime());
                job.setNextFireTime(trigger.getNextFireTime());
                JobDataMap jobDataMap = trigger.getJobDataMap();
                job.setTaskType(jobDataMap.getString("taskType"));
                job.setTargetSystem(jobDataMap.getString("targetSystem"));
                job.setTargetObject(jobDataMap.getString("targetObject"));
                job.setTargetMethod(jobDataMap.getString("targetMethod"));
                job.setContactName(jobDataMap.getString("contactName"));
                job.setContactEmail(jobDataMap.getString("contactEmail"));
                job.setTaskDesc(jobDetail.getDescription());
                String jobClass = jobDetail.getJobClass().getSimpleName();
                if (jobClass.equals("StatefulJob")) {
                    job.setJobType("statefulJob");
                } else if (jobClass.equals("DefaultJob")) {
                    job.setJobType("job");
                }
                result.add(job);
            }
        }
    } catch (Exception e) {
        logger.error("Try to load All JobDetail cause error : ", e);
    }
    return result;
}
项目:xxl-job    文件:XxlJobDynamicScheduler.java   
@Deprecated
public static List<Map<String, Object>> getJobList(){
    List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();

    try {
        if (scheduler.getJobGroupNames()==null || scheduler.getJobGroupNames().size()==0) {
            return null;
        }
        String groupName = scheduler.getJobGroupNames().get(0);
        Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
        if (jobKeys!=null && jobKeys.size()>0) {
            for (JobKey jobKey : jobKeys) {
                TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
                Trigger trigger = scheduler.getTrigger(triggerKey);
                JobDetail jobDetail = scheduler.getJobDetail(jobKey);
                TriggerState triggerState = scheduler.getTriggerState(triggerKey);
                Map<String, Object> jobMap = new HashMap<String, Object>();
                jobMap.put("TriggerKey", triggerKey);
                jobMap.put("Trigger", trigger);
                jobMap.put("JobDetail", jobDetail);
                jobMap.put("TriggerState", triggerState);
                jobList.add(jobMap);
            }
        }

    } catch (SchedulerException e) {
        e.printStackTrace();
        return null;
    }
    return jobList;
}
项目:xxl-job    文件:XxlJobDynamicScheduler.java   
public static void fillJobInfo(XxlJobInfo jobInfo) {
    // TriggerKey : name + group
       String group = String.valueOf(jobInfo.getJobGroup());
       String name = String.valueOf(jobInfo.getId());
       TriggerKey triggerKey = TriggerKey.triggerKey(name, group);

       try {
        Trigger trigger = scheduler.getTrigger(triggerKey);

        TriggerState triggerState = scheduler.getTriggerState(triggerKey);

        // parse params
        if (trigger!=null && trigger instanceof CronTriggerImpl) {
            String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
            jobInfo.setJobCron(cronExpression);
        }

        //JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
           //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
           //String jobClass = jobDetail.getJobClass().getName();

        if (triggerState!=null) {
            jobInfo.setJobStatus(triggerState.name());
        }

    } catch (SchedulerException e) {
        e.printStackTrace();
    }
}
项目:JAVA-    文件:SchedulerManager.java   
public List<TaskScheduled> getAllJobDetail() {
    List<TaskScheduled> result = new LinkedList<TaskScheduled>();
    try {
        GroupMatcher<JobKey> matcher = GroupMatcher.jobGroupContains("");
        Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
        for (JobKey jobKey : jobKeys) {
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
            for (Trigger trigger : triggers) {
                TaskScheduled job = new TaskScheduled();
                job.setTaskName(jobKey.getName());
                job.setTaskGroup(jobKey.getGroup());
                TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
                job.setStatus(triggerState.name());
                if (trigger instanceof CronTrigger) {
                    CronTrigger cronTrigger = (CronTrigger)trigger;
                    String cronExpression = cronTrigger.getCronExpression();
                    job.setTaskCron(cronExpression);
                }
                job.setPreviousFireTime(trigger.getPreviousFireTime());
                job.setNextFireTime(trigger.getNextFireTime());
                JobDataMap jobDataMap = trigger.getJobDataMap();
                job.setTaskType(jobDataMap.getString("taskType"));
                job.setTargetSystem(jobDataMap.getString("targetSystem"));
                job.setTargetObject(jobDataMap.getString("targetObject"));
                job.setTargetMethod(jobDataMap.getString("targetMethod"));
                job.setContactName(jobDataMap.getString("contactName"));
                job.setContactEmail(jobDataMap.getString("contactEmail"));
                job.setTaskDesc(jobDetail.getDescription());
                String jobClass = jobDetail.getJobClass().getSimpleName();
                if (jobClass.equals("StatefulJob")) {
                    job.setJobType("statefulJob");
                } else if (jobClass.equals("DefaultJob")) {
                    job.setJobType("job");
                }
                result.add(job);
            }
        }
    } catch (Exception e) {
        logger.error("Try to load All JobDetail cause error : ", e);
    }
    return result;
}
项目:taboola-cronyx    文件:QuartzSchedulerServiceImpl.java   
private TriggerDefinition enhanceTriggerDefinition(TriggerDefinition triggerDefinition) {
    TriggerKey quartzTriggerKey = new TriggerKey(triggerDefinition.getTriggerKey().getName(), triggerDefinition.getTriggerKey().getGroup());
    Trigger quartzTrigger = getQuartzTriggerUnchecked(quartzTriggerKey);
    TriggerState quartzTriggerState = getQuartzTriggerStateUnchecked(quartzTriggerKey);
    TriggerStatus cronyxTriggerStatus = quartzTriggerStateToTriggerStatus(quartzTrigger, quartzTriggerState);

    addJobDefinition(triggerDefinition);
    addPreviousFiringTime(triggerDefinition, quartzTrigger);
    addNextFiringTime(triggerDefinition, quartzTrigger, cronyxTriggerStatus);
    addTriggerStatus(triggerDefinition, cronyxTriggerStatus);
    addPropertiesToAfterTrigger(triggerDefinition);

    return triggerDefinition;
}
项目:taboola-cronyx    文件:QuartzSchedulerServiceImpl.java   
private TriggerState getQuartzTriggerStateUnchecked(TriggerKey quartzKey) {
    try {
        return scheduler.getTriggerState(quartzKey);
    } catch (SchedulerException e) {
        throw new CronyxException(e);
    }
}
项目:ElasticTab-Elasticsearch-to-Excel-Report    文件:ESReportREST.java   
@POST
@Path("updateJobState")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public String updateJobState(Map<String, String> input) {
    String jobName = input.get("jobName");
    String triggerName = input.get("triggerName");
    boolean triggerState = Boolean.valueOf(input.get("triggerState"));
    String index = input.get(Constants.INDEX);

    TriggerState responseTriggerState = null;

    try {
        responseTriggerState = QuartzUtil.updateJobState(jobName, triggerName, triggerState);
    } catch (SchedulerException e) {
        e.printStackTrace();
    }
    if (responseTriggerState == null) {
        return "Unable to retrive the state for the job " + input.get("jobName") + "#" + index;
    }

    if (!triggerState && responseTriggerState.equals(TriggerState.NORMAL)) {
        return "Unable to pause the state for the job " + input.get("jobName") + "#" + index;
    } else if (triggerState && responseTriggerState.equals(TriggerState.PAUSED)) {
        return "Unable to resume the state for the job " + input.get("jobName") + "#" + index;
    } else if (!triggerState && responseTriggerState.equals(TriggerState.PAUSED)) {
        return "Job " + jobName + "#" + index + " paused successfully";
    } else if (triggerState && responseTriggerState.equals(TriggerState.NORMAL)) {
        return "Job " + jobName + "#" + index + " resumed successfully";
    } else {
        return "Unknown State";
    }
}
项目:ElasticTab-Elasticsearch-to-Excel-Report    文件:QuartzUtil.java   
public static TriggerState updateJobState(String jobName, String triggerName, boolean triggerState) throws SchedulerException {
    if (triggerState) {
        scheduler.resumeTrigger(new TriggerKey(triggerName, quartzClientProperties.getProperty("group")));
    } else {
        scheduler.pauseTrigger(new TriggerKey(triggerName, quartzClientProperties.getProperty("group")));
    }
    return scheduler.getTriggerState(new TriggerKey(triggerName, quartzClientProperties.getProperty("group")));
}
项目:nexus-public    文件:JobStoreImpl.java   
@Override
public TriggerState getTriggerState(final TriggerKey triggerKey) throws JobPersistenceException {
  return execute(db -> {
    TriggerEntity entity = triggerEntityAdapter.readByKey(db, triggerKey);
    if (entity == null) {
      return TriggerState.NONE;
    }

    // convert entity state to trigger state
    switch (entity.getState()) {
      case COMPLETE:
        return TriggerState.COMPLETE;

      case PAUSED:
      case PAUSED_BLOCKED:
        return TriggerState.PAUSED;

      case BLOCKED:
        return TriggerState.BLOCKED;

      case ERROR:
        return TriggerState.ERROR;

      default:
        return TriggerState.NORMAL;
    }
  });
}
项目:nexus-public    文件:JobStoreImplTest.java   
@Test
public void testTriggerStates() throws Exception {
  JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("job1", "jobGroup1").storeDurably(true).build();
  this.jobStore.storeJob(jobDetail, false);

  OperableTrigger trigger =
      new SimpleTriggerImpl("trigger1", "triggerGroup1", jobDetail.getKey().getName(), jobDetail.getKey().getGroup(),
          new Date(System.currentTimeMillis() + 100000), new Date(System.currentTimeMillis() + 200000), 2, 2000);
  trigger.computeFirstFireTime(null);
  assertEquals(TriggerState.NONE, this.jobStore.getTriggerState(trigger.getKey()));
  this.jobStore.storeTrigger(trigger, false);
  assertEquals(TriggerState.NORMAL, this.jobStore.getTriggerState(trigger.getKey()));

  this.jobStore.pauseTrigger(trigger.getKey());
  assertEquals(TriggerState.PAUSED, this.jobStore.getTriggerState(trigger.getKey()));

  this.jobStore.resumeTrigger(trigger.getKey());
  assertEquals(TriggerState.NORMAL, this.jobStore.getTriggerState(trigger.getKey()));

  trigger = this.jobStore.acquireNextTriggers(
      new Date(trigger.getNextFireTime().getTime()).getTime() + 10000, 1, 1L).get(0);
  assertNotNull(trigger);
  this.jobStore.releaseAcquiredTrigger(trigger);
  trigger = this.jobStore.acquireNextTriggers(
      new Date(trigger.getNextFireTime().getTime()).getTime() + 10000, 1, 1L).get(0);
  assertNotNull(trigger);
  assertTrue(this.jobStore.acquireNextTriggers(
      new Date(trigger.getNextFireTime().getTime()).getTime() + 10000, 1, 1L).isEmpty());
}
项目:ElasticTab-Elasticsearch-to-Excel-Report    文件:ESReportREST.java   
@POST
@Path("updateJobState")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public String updateJobState(Map<String, String> input) {
    String jobName = input.get("jobName");
    String triggerName = input.get("triggerName");
    boolean triggerState = Boolean.valueOf(input.get("triggerState"));
    String index = input.get(Constants.INDEX);

    TriggerState responseTriggerState = null;

    try {
        responseTriggerState = QuartzUtil.updateJobState(jobName, triggerName, triggerState);
    } catch (SchedulerException e) {
        e.printStackTrace();
    }
    if (responseTriggerState == null) {
        return "Unable to retrive the state for the job " + input.get("jobName") + "#" + index;
    }

    if (!triggerState && responseTriggerState.equals(TriggerState.NORMAL)) {
        return "Unable to pause the state for the job " + input.get("jobName") + "#" + index;
    } else if (triggerState && responseTriggerState.equals(TriggerState.PAUSED)) {
        return "Unable to resume the state for the job " + input.get("jobName") + "#" + index;
    } else if (!triggerState && responseTriggerState.equals(TriggerState.PAUSED)) {
        return "Job " + jobName + "#" + index + " paused successfully";
    } else if (triggerState && responseTriggerState.equals(TriggerState.NORMAL)) {
        return "Job " + jobName + "#" + index + " resumed successfully";
    } else {
        return "Unknown State";
    }
}
项目:ElasticTab-Elasticsearch-to-Excel-Report    文件:QuartzUtil.java   
public static TriggerState updateJobState(String jobName, String triggerName, boolean triggerState) throws SchedulerException {
    if (triggerState) {
        scheduler.resumeTrigger(new TriggerKey(triggerName, quartzClientProperties.getProperty("group")));
    } else {
        scheduler.pauseTrigger(new TriggerKey(triggerName, quartzClientProperties.getProperty("group")));
    }
    return scheduler.getTriggerState(new TriggerKey(triggerName, quartzClientProperties.getProperty("group")));
}
项目:mangooio    文件:Scheduler.java   
@SuppressWarnings("unchecked")
private TriggerState getTriggerState(JobKey jobKey) throws SchedulerException {
    Objects.requireNonNull(this.quartzScheduler, Required.SCHEDULER.toString());

    List<Trigger> triggers = (List<Trigger>) this.quartzScheduler.getTriggersOfJob(jobKey);
    Trigger trigger = triggers.get(0);  

    return this.quartzScheduler.getTriggerState(trigger.getKey());
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test()
public void testTriggerStates() throws Exception {
  this.jobStore.storeJob(fJobDetail, false);

  final OperableTrigger trigger = new SimpleTriggerImpl("trigger1",
      "triggerGroup1", this.fJobDetail.getName(), this.fJobDetail.getGroup(),
      new Date(System.currentTimeMillis() + 100000), new Date(
          System.currentTimeMillis() + 200000), 2, 2000);
  trigger.computeFirstFireTime(null);

  assertEquals(Trigger.TriggerState.NONE,
      this.jobStore.getTriggerState(trigger.getKey()));

  this.jobStore.storeTrigger(trigger, false);
  assertEquals(Trigger.TriggerState.NORMAL,
      this.jobStore.getTriggerState(trigger.getKey()));

  this.jobStore.pauseTrigger(trigger.getKey());
  assertEquals(Trigger.TriggerState.PAUSED,
      this.jobStore.getTriggerState(trigger.getKey()));

  this.jobStore.resumeTrigger(trigger.getKey());
  assertEquals(Trigger.TriggerState.NORMAL,
      this.jobStore.getTriggerState(trigger.getKey()));

  final OperableTrigger rTrigger1 = this.jobStore.acquireNextTriggers(
      new Date(trigger.getNextFireTime().getTime()).getTime() + 10000, 1, 1L)
      .get(0);
  assertNotNull(rTrigger1);
  this.jobStore.releaseAcquiredTrigger(rTrigger1);

  final OperableTrigger rTrigger2 = this.jobStore.acquireNextTriggers(
      new Date(rTrigger1.getNextFireTime().getTime()).getTime() + 10000, 1,
      1L).get(0);
  assertNotNull(rTrigger2);
  assertTrue(this.jobStore.acquireNextTriggers(
      new Date(rTrigger2.getNextFireTime().getTime()).getTime() + 10000, 1,
      1L).isEmpty());
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testPauseTrigger() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  Trigger trigger = buildTrigger();
  storeTrigger(trigger);
  TriggerKey triggerKey = trigger.getKey();
  TriggerState triggerState = jobStore.getTriggerState(triggerKey);
  assertThat(triggerState).isEqualTo(TriggerState.NORMAL);
  jobStore.pauseTrigger(triggerKey);
  triggerState = jobStore.getTriggerState(triggerKey);
  assertThat(triggerState).isEqualTo(TriggerState.PAUSED);
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testPauseTriggers() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  Trigger trigger = buildAndStoreTrigger();
  Trigger trigger1 = buildAndStoreTrigger();
  Trigger trigger2 = buildTrigger("trigger2", "group2", buildAndStoreJob());
  storeTrigger(trigger2);
  assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo(
      TriggerState.NORMAL);
  assertThat(jobStore.getTriggerState(trigger1.getKey())).isEqualTo(
      TriggerState.NORMAL);

  Collection<String> pauseTriggers = jobStore.pauseTriggers(GroupMatcher
      .triggerGroupEquals(trigger.getKey().getGroup()));

  assertThat(pauseTriggers).containsOnly(trigger.getKey().getGroup());
  assertThat(jobStore.getPausedTriggerGroups()).containsOnly(
      trigger.getKey().getGroup());

  Trigger trigger3 = buildAndStoreTrigger();

  assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo(
      TriggerState.PAUSED);
  assertThat(jobStore.getTriggerState(trigger1.getKey())).isEqualTo(
      TriggerState.PAUSED);
  assertThat(jobStore.getTriggerState(trigger2.getKey())).isEqualTo(
      TriggerState.NORMAL);
  assertThat(jobStore.getTriggerState(trigger3.getKey())).isEqualTo(
      TriggerState.PAUSED);
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testPauseJob() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  JobDetail jobDetail = buildAndStoreJob();
  Trigger trigger = buildTrigger(jobDetail);
  storeTrigger(trigger);
  TriggerState triggerState = jobStore.getTriggerState(trigger.getKey());
  assertThat(triggerState).isEqualTo(TriggerState.NORMAL);

  jobStore.pauseJob(jobDetail.getKey());

  triggerState = jobStore.getTriggerState(trigger.getKey());
  assertThat(triggerState).isEqualTo(TriggerState.PAUSED);
}
项目:quartz-hazelcast-jobstore    文件:TestHazelcastJobStore.java   
@Test
public void testResumeAll() throws ObjectAlreadyExistsException,
    JobPersistenceException {
  Trigger trigger = buildAndStoreTrigger();
  Trigger trigger2 = buildTrigger("trigger2", "group2", buildAndStoreJob());
  storeTrigger(trigger2);
  assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo(
      TriggerState.NORMAL);

  jobStore.pauseAll();

  assertThat(jobStore.getPausedTriggerGroups()).containsOnly(
      trigger.getKey().getGroup(), trigger2.getKey().getGroup());

  Trigger trigger3 = buildAndStoreTrigger();

  assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo(
      TriggerState.PAUSED);
  assertThat(jobStore.getTriggerState(trigger2.getKey())).isEqualTo(
      TriggerState.PAUSED);
  assertThat(jobStore.getTriggerState(trigger3.getKey())).isEqualTo(
      TriggerState.PAUSED);

  jobStore.resumeAll();
  assertThat(jobStore.getTriggerState(trigger.getKey())).isEqualTo(
      TriggerState.NORMAL);
  assertThat(jobStore.getTriggerState(trigger2.getKey())).isEqualTo(
      TriggerState.NORMAL);
  assertThat(jobStore.getTriggerState(trigger3.getKey())).isEqualTo(
      TriggerState.NORMAL);
}