Java Code Examples for org.quartz.Trigger.TriggerState#NORMAL

The following examples show how to use org.quartz.Trigger.TriggerState#NORMAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractQuartzTaskManager.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 2
Source File: Scheduler.java    From mangooio with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
            boolean active = TriggerState.NORMAL == triggerState;
            jobs.add(new io.mangoo.models.Job(active, jobKey.getName(), trigger.getDescription(), trigger.getNextFireTime(), trigger.getPreviousFireTime()));
        }
    } catch (SchedulerException e) {
        throw new MangooSchedulerException(e);
    }
    
    return jobs;
}
 
Example 3
Source File: Scheduler.java    From mangooio with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 4
Source File: RedisJobStore.java    From redis-quartz with MIT License 6 votes vote down vote up
@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();
	}
}
 
Example 5
Source File: AbstractQuartzTaskManager.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 6
Source File: RAMJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <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;
    }
}
 
Example 7
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}