Java 类org.quartz.JobKey 实例源码

项目:lams    文件:ListenerManagerImpl.java   
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);
    }
}
项目:springboot-quartz    文件:ScheduleJobService.java   
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(); 
    }  
}
项目:kettle_support_kettle8.0    文件:QuartzScheduleServiceImpl.java   
/**
 * 执行单个定时任务
 * 
 * @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();
}
项目:lams    文件:ListenerManagerImpl.java   
public void addJobListener(JobListener jobListener, Matcher<JobKey> matcher) {
    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(matcher != null)
            matchersL.add(matcher);
        else
            matchersL.add(EverythingMatcher.allJobs());

        globalJobListenersMatchers.put(jobListener.getName(), matchersL);
    }
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <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);
}
项目:lams    文件:JobStoreSupport.java   
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;
                    }
                });
    }
项目:lams    文件:JobStoreSupport.java   
/**
 * <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;
            }
        });
}
项目:spring-boot-quartz-demo    文件:JobServiceImpl.java   
/**
 * 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;
    }
}
项目:uflo    文件:SchedulerServiceImpl.java   
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);
    }
}
项目:lams    文件:StdJDBCDelegate.java   
/**
 * <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);
    }

}
项目:lams    文件:ListenerManagerImpl.java   
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;
    }
}
项目:lams    文件:StdJDBCDelegate.java   
/**
 * <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);
    }
}
项目:lams    文件:DefaultClusteredJobStore.java   
/**
 * <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;
}
项目:webside    文件:ScheduleJobServiceImpl.java   
@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;
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <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;
}
项目:kettle_support_kettle8.0    文件:QuartzScheduleServiceImpl.java   
/**
 * 查询单个定时任务
 * 
 * @param entity
 * @return Map
 * @throws SchedulerException
 */
@Override
public Object select(T entity) throws SchedulerException {
    String[] keyArray = entity.getId().split("\\.");
    JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(keyArray[1],
            keyArray[0]));
    String params = JSONArray.fromObject(jobDetail.getJobDataMap())
            .toString();
    Trigger trigger = scheduler.getTrigger(TriggerKey.triggerKey(
            keyArray[1], keyArray[0]));
    Map<String, Object> map = new HashMap<String, Object>();
    if (trigger instanceof SimpleTrigger) {
        map.put("triggerType", simpleTrigger);
    } else {
        map.put("triggerType", cronTrigger);
    }
    for (Object key : jobDetail.getJobDataMap().keySet()) {
        if (Constant.KETTLE_REPO.equals(key.toString())) {
            map.put(Constant.KETTLE_REPO, jobDetail.getJobDataMap().get(key)
                    .toString());
        }
    }
    map.put("params", params);
    map.put("jobDetail", jobDetail);
    map.put("trigger", trigger);
    return map;
}
项目:taboola-cronyx    文件:QuartzSchedulerServiceImpl.java   
@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);
    }
}
项目:lams    文件:JobStoreSupport.java   
protected boolean removeJob(Connection conn, final JobKey jobKey)
    throws JobPersistenceException {

    try {
        List<TriggerKey> jobTriggers = getDelegate().selectTriggerKeysForJob(conn, jobKey);
        for (TriggerKey jobTrigger: jobTriggers) {
            deleteTriggerAndChildren(conn, jobTrigger);
        }

        return deleteJobAndChildren(conn, jobKey);
    } catch (SQLException e) {
        throw new JobPersistenceException("Couldn't remove job: "
                + e.getMessage(), e);
    }
}
项目:lams    文件:ListenerManagerImpl.java   
public boolean setJobListenerMatchers(String listenerName, List<Matcher<JobKey>> matchers)  {
    if(matchers == null)
        throw new IllegalArgumentException("Non-null value not acceptable.");

    synchronized (globalJobListeners) {
        List<Matcher<JobKey>> oldMatchers = globalJobListenersMatchers.get(listenerName);
        if(oldMatchers == null)
            return false;
        globalJobListenersMatchers.put(listenerName, matchers);
        return true;
    }
}
项目: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;
}
项目:lams    文件:RAMJobStore.java   
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the
 * given group - by pausing all of their <code>Trigger</code>s.
 * </p>
 *
 *
 * <p>
 * The JobStore should "remember" that the group is paused, and impose the
 * pause on any new jobs that are added to the group while the group is
 * paused.
 * </p>
 */
public List<String> pauseJobs(GroupMatcher<JobKey> matcher) {
    List<String> pausedGroups = new LinkedList<String>();
    synchronized (lock) {

        StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator();
        switch (operator) {
            case EQUALS:
                if (pausedJobGroups.add(matcher.getCompareToValue())) {
                    pausedGroups.add(matcher.getCompareToValue());
                }
                break;
            default :
                for (String group : jobsByGroup.keySet()) {
                    if(operator.evaluate(group, matcher.getCompareToValue())) {
                        if (pausedJobGroups.add(group)) {
                            pausedGroups.add(group);
                        }
                    }
                }
        }

        for (String groupName : pausedGroups) {
            for (JobKey jobKey: getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                List<OperableTrigger> triggersOfJob = getTriggersForJob(jobKey);
                for (OperableTrigger trigger: triggersOfJob) {
                    pauseTrigger(trigger.getKey());
                }
            }
        }
    }

    return pausedGroups;
}
项目:lams    文件:RemoteScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public boolean deleteJob(JobKey jobKey)
    throws SchedulerException {
    try {
        return getRemoteScheduler()
                .deleteJob(jobKey);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:webside    文件:ScheduleJobServiceImpl.java   
@Transactional
@Override
public boolean interruptJob(JobKey jobKey) {
    try
    {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        scheduler.getSchedulerInstanceId();
        return scheduler.interrupt(jobKey);
    } catch (SchedulerException e) {
        throw new ServiceException(e);
    }
}
项目:spring-boot-quartz-demo    文件:SimpleJob.java   
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    JobKey key = jobExecutionContext.getJobDetail().getKey();
    System.out.println("Simple Job started with key :" + key.getName() + ", Group :"+key.getGroup() + " , Thread Name :"+Thread.currentThread().getName());

    System.out.println("======================================");
    System.out.println("Accessing annotation example: "+jobService.getAllJobs());
    List<Map<String, Object>> list = jobService.getAllJobs();
    System.out.println("Job list :"+list);
    System.out.println("======================================");

    //*********** For retrieving stored key-value pairs ***********/
    JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
    String myValue = dataMap.getString("myKey");
    System.out.println("Value:" + myValue);

    //*********** For retrieving stored object, It will try to deserialize the bytes Object. ***********/
    /*
    SchedulerContext schedulerContext = null;
       try {
           schedulerContext = jobExecutionContext.getScheduler().getContext();
       } catch (SchedulerException e1) {
           e1.printStackTrace();
       }
       YourClass yourClassObject = (YourClass) schedulerContext.get("storedObjectKey");
     */

    while(toStopFlag){
        try {
            System.out.println("Test Job Running... Thread Name :"+Thread.currentThread().getName());
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.out.println("Thread: "+ Thread.currentThread().getName() +" stopped.");
}
项目:lams    文件:RAMJobStore.java   
protected ArrayList<TriggerWrapper> getTriggerWrappersForJob(JobKey jobKey) {
    ArrayList<TriggerWrapper> trigList = new ArrayList<TriggerWrapper>();

    synchronized (lock) {
        for (TriggerWrapper trigger : triggers) {
            if (trigger.jobKey.equals(jobKey)) {
                trigList.add(trigger);
            }
        }
    }

    return trigList;
}
项目:lams    文件:RemoteMBeanScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
@SuppressWarnings("unchecked")
public Set<JobKey> getJobKeys(GroupMatcher<JobKey> matcher) throws SchedulerException {
    if (matcher.getCompareWithOperator().equals(StringMatcher.StringOperatorName.EQUALS)) {
        List<JobKey> keys = (List<JobKey>)invoke(
                "getJobNames",
                new Object[] { matcher.getCompareToValue() },
                new String[] { String.class.getName() });

        return new HashSet<JobKey>(keys);
    } else {
        throw new SchedulerException("Only equals matcher are supported for looking up JobKeys");
    }
}
项目:lams    文件:RemoteScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public List<? extends Trigger> getTriggersOfJob(JobKey jobKey)
    throws SchedulerException {
    try {
        return getRemoteScheduler().getTriggersOfJob(jobKey);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目: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;
}
项目:automat    文件:SchedulerManager.java   
public void delJob(TaskScheduled scheduleJob) {
    try {
        JobKey jobKey = JobKey.jobKey(scheduleJob.getTaskName(), scheduleJob.getTaskGroup());
        TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getTaskName(), scheduleJob.getTaskGroup());
        scheduler.pauseTrigger(triggerKey);// 停止触发器
        scheduler.unscheduleJob(triggerKey);// 移除触发器
        scheduler.deleteJob(jobKey);// 删除任务
    } catch (Exception e) {
        logger.error("Try to resume Job cause error : ", e);
        throw new BusinessException(e);
    }
}
项目:elastic-job-cloud    文件:TransientProducerScheduler.java   
synchronized void register(final CloudJobConfiguration jobConfig) {
    String cron = jobConfig.getTypeConfig().getCoreConfig().getCron();
    JobKey jobKey = buildJobKey(cron);
    repository.put(jobKey, jobConfig.getJobName());
    try {
        if (!scheduler.checkExists(jobKey)) {
            scheduler.scheduleJob(buildJobDetail(jobKey), buildTrigger(jobKey.getName()));
        }
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
}
项目:webside    文件:ScheduleJobServiceImpl.java   
@Transactional
@Override
public boolean resumeJob(JobKey jobKey) {
    try {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        scheduler.resumeJob(jobKey);
        return Boolean.TRUE;
    } catch (SchedulerException e) {
        throw new ServiceException(e);
    }
}
项目:elastic-job-cloud    文件:ProducerJobTest.java   
@Test
public void assertExecute() throws JobExecutionException {
    when(jobExecutionContext.getJobDetail()).thenReturn(JobBuilder.newJob(TransientProducerScheduler.ProducerJob.class).withIdentity("0/30 * * * * ?").build());
    repository.put(JobKey.jobKey("0/30 * * * * ?"), "test_job");
    producerJob.execute(jobExecutionContext);
    verify(readyService).addTransient("test_job");
    repository.remove("test_job");
}
项目:lams    文件:RemoteScheduler.java   
/**
 * @see org.quartz.Scheduler#interrupt(JobKey)
 */
public boolean interrupt(JobKey jobKey) throws UnableToInterruptJobException  {
    try {
        return getRemoteScheduler().interrupt(jobKey);
    } catch (RemoteException re) {
        throw new UnableToInterruptJobException(invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re));
    } catch (SchedulerException se) {
        throw new UnableToInterruptJobException(se);
    }
}
项目:webside    文件:ScheduleJobServiceImpl.java   
@Override
public ScheduleJobEntity getScheduleJobEntity(ScheduleJobEntity job){
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
JobKey jobKey = JobKey.jobKey(job.getJobName(), job.getJobGroup());
TriggerKey triggerKey = job.getTriggerKey();
Trigger trigger = scheduler.getTrigger(triggerKey);
this.wrapScheduleJob(job, scheduler, jobKey, trigger);
} catch (SchedulerException e) {
    logger.error("获取job失败", e);
    throw new ServiceException("获取job失败", e);
}
return job;
}
项目: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 JobDetail getJobDetail(JobKey jobKey) throws SchedulerException {
    try {
        return JobDetailSupport.newJobDetail((CompositeData)invoke(
                "getJobDetail",
                new Object[] { jobKey.getName(), jobKey.getGroup() },
                new String[] { String.class.getName(), String.class.getName() }));
    } catch (ClassNotFoundException e) {
        throw new SchedulerException("Unable to resolve job class", e);
    }
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Get the names of all the <code>{@link org.quartz.Job}s</code> in the
 * matching groups.
 * </p>
 */
public Set<JobKey> getJobKeys(GroupMatcher<JobKey> matcher)
    throws SchedulerException {
    validateState();

    if(matcher == null) {
        matcher = GroupMatcher.groupEquals(Scheduler.DEFAULT_GROUP);
    }

    return resources.getJobStore().getJobKeys(matcher);
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public Collection<String> pauseJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException {
  try {
    return realJobStore.pauseJobs(matcher);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Pausing jobs failed due to client rejoin", e);
  }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public boolean removeJob(JobKey jobKey) throws JobPersistenceException {
  try {
    return realJobStore.removeJob(jobKey);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Removing job failed due to client rejoin", e);
  }
}
项目:uflo    文件:SchedulerServiceImpl.java   
public void addReminderJob(TaskReminder reminder,ProcessInstance processInstance,Task task) {
    try {
        AbstractTrigger<? extends Trigger> trigger=null;
        if(reminder.getType().equals(ReminderType.Once)){
            SimpleTriggerImpl simpleTrigger=new SimpleTriggerImpl();
            simpleTrigger.setRepeatCount(0);
            trigger=simpleTrigger;
            long executeTime=reminder.getStartDate().getTime()+10000;
            long now=(new Date()).getTime();
            if(executeTime<=now){
                return;
            }
        }else{
            CronTriggerImpl cronTrigger=new CronTriggerImpl();
            cronTrigger.setCronExpression(reminder.getCron());
            trigger=cronTrigger;
        }
        trigger.setName("trigger_"+reminder.getId());
        trigger.setStartTime(reminder.getStartDate());
        ReminderJobDetail jobDetail=new ReminderJobDetail();
        jobDetail.setJobClass(ReminderJob.class);
        ReminderHandler handler=(ReminderHandler)applicationContext.getBean(reminder.getReminderHandlerBean());
        jobDetail.setReminderHandlerBean(handler);
        if(task==null){
            task=taskService.getTask(reminder.getTaskId());             
        }
        jobDetail.setTask(task);
        jobDetail.setProcessInstance(processService.getProcessInstanceById(task.getProcessInstanceId()));
        jobDetail.setKey(new JobKey(JOB_NAME_PREFIX+reminder.getId(),JOB_GROUP_PREFIX));
        Calendar calendar=getCalendar(reminder,processInstance,task);
        if(calendar!=null){
            String calendarName=REMINDER_CALENDAR_PREFIX+reminder.getId();
            scheduler.addCalendar(calendarName, calendar,false, false);
            trigger.setCalendarName(calendarName);
        }
        scheduler.scheduleJob(jobDetail, trigger);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }   
}
项目: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 void resumeJob(JobKey jobKey)
    throws SchedulerException {
    invoke(
        "resumeJob", 
        new Object[] { jobKey.getName(), jobKey.getGroup() },
        new String[] { String.class.getName(), String.class.getName() });
}