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,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,1L).get(0);
  assertNotNull(trigger);
  assertTrue(this.jobStore.acquireNextTriggers(
      new Date(trigger.getNextFireTime().getTime()).getTime() + 10000,1L).isEmpty());
}
项目: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",this.fJobDetail.getName(),this.fJobDetail.getGroup(),new Date(
          System.currentTimeMillis() + 200000),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,1L)
      .get(0);
  assertNotNull(rTrigger1);
  this.jobStore.releaseAcquiredTrigger(rTrigger1);

  final OperableTrigger rTrigger2 = this.jobStore.acquireNextTriggers(
      new Date(rTrigger1.getNextFireTime().getTime()).getTime() + 10000,1L).get(0);
  assertNotNull(rTrigger2);
  assertTrue(this.jobStore.acquireNextTriggers(
      new Date(rTrigger2.getNextFireTime().getTime()).getTime() + 10000,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",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,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);
}

相关文章

买水果
比较全面的redis工具类
gson 反序列化到多态子类
java 版本的 mb_strwidth
JAVA 反转字符串的最快方法,大概比StringBuffer.reverse()性...
com.google.gson.internal.bind.ArrayTypeAdapter的实例源码...