本文整理汇总了Java中org.quartz.Trigger.TriggerState类的典型用法代码示例。如果您正苦于以下问题:Java TriggerState类的具体用法?Java TriggerState怎么用?Java TriggerState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TriggerState类属于org.quartz.Trigger包,在下文中一共展示了TriggerState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: triggerStateEN2CN
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
/**
* 将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 "无";
}
}
示例2: quartzTriggerStateToTriggerStatus
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
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;
}
}
示例3: getAllJobs
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
/**
* 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;
}
示例4: changeState
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
/**
* 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);
}
}
示例5: testPauseJob
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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));
}
示例6: testResumeJob
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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));
}
示例7: getTriggerState
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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();
}
}
示例8: triggerStateToTaskState
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
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;
}
}
示例9: testRemoveTrigger
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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);
}
示例10: testResumeTrigger
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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);
}
示例11: testResumeTriggerWithPausedJobs
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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);
}
示例12: testResumeJob
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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);
}
示例13: testPauseAll
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
@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);
}
示例14: getAllJobDetail
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
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;
}
示例15: getJobState
import org.quartz.Trigger.TriggerState; //导入依赖的package包/类
/**
* 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;
}