本文整理匯總了Java中org.quartz.JobKey類的典型用法代碼示例。如果您正苦於以下問題:Java JobKey類的具體用法?Java JobKey怎麽用?Java JobKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JobKey類屬於org.quartz包,在下文中一共展示了JobKey類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addJobListener
import org.quartz.JobKey; //導入依賴的package包/類
public void addJobListener(JobListener jobListener, List<Matcher<JobKey>> matchers) {
if (jobListener.getName() == null || jobListener.getName().length() == 0) {
throw new IllegalArgumentException(
"JobListener name cannot be empty.");
}
synchronized (globalJobListeners) {
globalJobListeners.put(jobListener.getName(), jobListener);
LinkedList<Matcher<JobKey>> matchersL = new LinkedList<Matcher<JobKey>>();
if(matchers != null && matchers.size() > 0)
matchersL.addAll(matchers);
else
matchersL.add(EverythingMatcher.allJobs());
globalJobListenersMatchers.put(jobListener.getName(), matchersL);
}
}
示例2: wrapScheduleJob
import org.quartz.JobKey; //導入依賴的package包/類
private void wrapScheduleJob(ScheduleJob scheduleJob,Scheduler scheduler,JobKey jobKey,Trigger trigger){
try {
scheduleJob.setJobName(jobKey.getName());
scheduleJob.setJobGroup(jobKey.getGroup());
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
ScheduleJob job = (ScheduleJob)jobDetail.getJobDataMap().get("scheduleJob");
scheduleJob.setDesc(job.getDesc());
scheduleJob.setJobId(job.getJobId());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
scheduleJob.setJobStatus(triggerState.name());
if(trigger instanceof CronTrigger){
CronTrigger cronTrigger = (CronTrigger)trigger;
String cronExpression = cronTrigger.getCronExpression();
scheduleJob.setCronExpression(cronExpression);
}
} catch (SchedulerException e) {
e.printStackTrace();
}
}
示例3: execute
import org.quartz.JobKey; //導入依賴的package包/類
/**
* 執行單個定時任務
*
* @param strVal
* @return String
* @throws SchedulerException
*/
@Override
public String execute(String strVal) throws SchedulerException {
JobKey key = null;
try {
String[] jobKey = strVal.split("\\.");
if (jobKey.length > 0) {
key = JobKey.jobKey(jobKey[1], jobKey[0]);
Trigger trigger = newTrigger()
.withIdentity(jobKey[1] + UUID.randomUUID().toString(),
jobKey[0]).withPriority(100).forJob(key)
.build();
scheduler.scheduleJob(trigger);
}
} catch (SchedulerException e) {
e.printStackTrace();
}
return key.toString();
}
示例4: triggerJob
import org.quartz.JobKey; //導入依賴的package包/類
/**
* <p>
* Trigger the identified <code>{@link org.quartz.Job}</code> (execute it
* now) - with a non-volatile trigger.
* </p>
*/
@SuppressWarnings("deprecation")
public void triggerJob(JobKey jobKey, JobDataMap data) throws SchedulerException {
validateState();
OperableTrigger trig = (OperableTrigger) newTrigger().withIdentity(newTriggerId(), Scheduler.DEFAULT_GROUP).forJob(jobKey).build();
trig.computeFirstFireTime(null);
if(data != null) {
trig.setJobDataMap(data);
}
boolean collision = true;
while (collision) {
try {
resources.getJobStore().storeTrigger(trig, false);
collision = false;
} catch (ObjectAlreadyExistsException oaee) {
trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP));
}
}
notifySchedulerThread(trig.getNextFireTime().getTime());
notifySchedulerListenersSchduled(trig);
}
示例5: removeJobs
import org.quartz.JobKey; //導入依賴的package包/類
public boolean removeJobs(final List<JobKey> jobKeys) throws JobPersistenceException {
return (Boolean) executeInLock(
LOCK_TRIGGER_ACCESS,
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
boolean allFound = true;
// FUTURE_TODO: make this more efficient with a true bulk operation...
for (JobKey jobKey : jobKeys)
allFound = removeJob(conn, jobKey) && allFound;
return allFound ? Boolean.TRUE : Boolean.FALSE;
}
});
}
示例6: resumeJobs
import org.quartz.JobKey; //導入依賴的package包/類
/**
* <p>
* Resume (un-pause) all of the <code>{@link org.quartz.Job}s</code> in
* the given group.
* </p>
*
* <p>
* If any of the <code>Job</code> s had <code>Trigger</code> s that
* missed one or more fire-times, then the <code>Trigger</code>'s
* misfire instruction will be applied.
* </p>
*
* @see #pauseJobs(org.quartz.impl.matchers.GroupMatcher)
*/
@SuppressWarnings("unchecked")
public Set<String> resumeJobs(final GroupMatcher<JobKey> matcher)
throws JobPersistenceException {
return (Set<String>) executeInLock(
LOCK_TRIGGER_ACCESS,
new TransactionCallback() {
public Set<String> execute(Connection conn) throws JobPersistenceException {
Set<JobKey> jobKeys = getJobNames(conn, matcher);
Set<String> groupNames = new HashSet<String>();
for (JobKey jobKey: jobKeys) {
List<OperableTrigger> triggers = getTriggersForJob(conn, jobKey);
for (OperableTrigger trigger: triggers) {
resumeTrigger(conn, trigger.getKey());
}
groupNames.add(jobKey.getGroup());
}
return groupNames;
}
});
}
示例7: deleteJob
import org.quartz.JobKey; //導入依賴的package包/類
/**
* Delete the identified Job from the Scheduler - and any associated Triggers.
*/
@Override
public boolean deleteJob(String jobName) {
System.out.println("Request received for deleting job.");
String jobKey = jobName;
String groupKey = "SampleGroup";
JobKey jkey = new JobKey(jobKey, groupKey);
System.out.println("Parameters received for deleting job : jobKey :"+jobKey);
try {
boolean status = schedulerFactoryBean.getScheduler().deleteJob(jkey);
System.out.println("Job with jobKey :"+jobKey+ " deleted with status :"+status);
return status;
} catch (SchedulerException e) {
System.out.println("SchedulerException while deleting job with key :"+jobKey + " message :"+e.getMessage());
e.printStackTrace();
return false;
}
}
示例8: initScanReminderJob
import org.quartz.JobKey; //導入依賴的package包/類
private void initScanReminderJob(){
CronTriggerImpl trigger=new CronTriggerImpl();
trigger.setName("UfloScanReminderTrigger");
trigger.setKey(new TriggerKey("UfloScanReminderTrigger"));
try {
trigger.setCronExpression(SCAN_REMINDER_CRON);
ScanReminderJob job=new ScanReminderJob();
ScanReminderJobDetail detail=new ScanReminderJobDetail();
detail.setSchedulerService(this);
detail.setTaskService(taskService);
detail.setReminderTaskList(reminderTaskList);
detail.setJobClass(job.getClass());
detail.setKey(new JobKey("UfloScanReminderJob"));
scheduler.scheduleJob(detail, trigger);
} catch (Exception e1) {
throw new RuntimeException(e1);
}
}
示例9: jobExists
import org.quartz.JobKey; //導入依賴的package包/類
/**
* <p>
* Check whether or not the given job exists.
* </p>
*
* @param conn
* the DB Connection
* @return true if the job exists, false otherwise
*/
public boolean jobExists(Connection conn, JobKey jobKey)
throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_JOB_EXISTENCE));
ps.setString(1, jobKey.getName());
ps.setString(2, jobKey.getGroup());
rs = ps.executeQuery();
if (rs.next()) {
return true;
} else {
return false;
}
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
示例10: addJobListenerMatcher
import org.quartz.JobKey; //導入依賴的package包/類
public boolean addJobListenerMatcher(String listenerName, Matcher<JobKey> matcher) {
if(matcher == null)
throw new IllegalArgumentException("Null value not acceptable.");
synchronized (globalJobListeners) {
List<Matcher<JobKey>> matchers = globalJobListenersMatchers.get(listenerName);
if(matchers == null)
return false;
matchers.add(matcher);
return true;
}
}
示例11: selectTriggerKeysForJob
import org.quartz.JobKey; //導入依賴的package包/類
/**
* <p>
* Get the names of all of the triggers associated with the given job.
* </p>
*
* @param conn
* the DB Connection
* @return an array of <code>{@link
* org.quartz.utils.Key}</code> objects
*/
public List<TriggerKey> selectTriggerKeysForJob(Connection conn, JobKey jobKey) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_TRIGGERS_FOR_JOB));
ps.setString(1, jobKey.getName());
ps.setString(2, jobKey.getGroup());
rs = ps.executeQuery();
LinkedList<TriggerKey> list = new LinkedList<TriggerKey>();
while (rs.next()) {
String trigName = rs.getString(COL_TRIGGER_NAME);
String trigGroup = rs.getString(COL_TRIGGER_GROUP);
list.add(triggerKey(trigName, trigGroup));
}
return list;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
示例12: resumeJobs
import org.quartz.JobKey; //導入依賴的package包/類
/**
* <p>
* Resume (un-pause) all of the <code>{@link org.quartz.JobDetail}s</code> in the given group.
* </p>
* <p>
* If any of the <code>Job</code> s had <code>Trigger</code> s that missed one or more fire-times, then the
* <code>Trigger</code>'s misfire instruction will be applied.
* </p>
*/
@Override
public Collection<String> resumeJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException {
Collection<String> groups = new HashSet<String>();
lock();
try {
Set<JobKey> jobKeys = getJobKeys(matcher);
for (JobKey jobKey : jobKeys) {
if (groups.add(jobKey.getGroup())) {
jobFacade.removePausedJobGroup(jobKey.getGroup());
}
for (OperableTrigger trigger : getTriggersForJob(jobKey)) {
resumeTrigger(trigger.getKey());
}
}
} finally {
unlock();
}
return groups;
}
示例13: getTriggers
import org.quartz.JobKey; //導入依賴的package包/類
@Override
public List<ScheduleJobEntity> getTriggers(ScheduleJobEntity job){
List<ScheduleJobEntity> scheduleJobList = new ArrayList<ScheduleJobEntity>();
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
JobKey jobKey = JobKey.jobKey(job.getJobName(), job.getJobGroup());
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
for (Trigger jobTrigger : triggers) {
ScheduleJobEntity scheduleJob = new ScheduleJobEntity();
this.wrapScheduleJob(scheduleJob, scheduler, jobKey, jobTrigger);
scheduleJobList.add(scheduleJob);
}
} catch (SchedulerException e) {
logger.error("jobName: "+job.getJobName()+" jobGroup: "+job.getJobGroup()+" 獲取trigger異常:",e);
throw new ServiceException("獲取job失敗", e);
}
return scheduleJobList;
}
示例14: deleteJob
import org.quartz.JobKey; //導入依賴的package包/類
/**
* <p>
* Delete the identified <code>Job</code> from the Scheduler - and any
* associated <code>Trigger</code>s.
* </p>
*
* @return true if the Job was found and deleted.
* @throws SchedulerException
* if there is an internal Scheduler error.
*/
public boolean deleteJob(JobKey jobKey) throws SchedulerException {
validateState();
boolean result = false;
List<? extends Trigger> triggers = getTriggersOfJob(jobKey);
for (Trigger trigger : triggers) {
if (!unscheduleJob(trigger.getKey())) {
StringBuilder sb = new StringBuilder().append(
"Unable to unschedule trigger [").append(
trigger.getKey()).append("] while deleting job [")
.append(jobKey).append(
"]");
throw new SchedulerException(sb.toString());
}
result = true;
}
result = resources.getJobStore().removeJob(jobKey) || result;
if (result) {
notifySchedulerThread(0L);
notifySchedulerListenersJobDeleted(jobKey);
}
return result;
}
示例15: resumeJob
import org.quartz.JobKey; //導入依賴的package包/類
@Override
public void resumeJob(NameAndGroup jobKey) {
JobKey quartzKey = new JobKey(jobKey.getName(), jobKey.getGroup());
try {
scheduler.resumeJob(quartzKey);
} catch (SchedulerException e) {
throw new SchedulingException(e);
}
}