Java 类org.quartz.Trigger 实例源码

项目:nest-spider    文件:CommonSpiderService.java   
public ResultBundle<Map<String, Triple<SpiderInfo, JobKey, Trigger>>> listAllJobs() {
    Map<String, Triple<SpiderInfo, JobKey, Trigger>> result = new HashMap<>();
    for(JobKey key:manager.listAll(QUARTZ_JOB_GROUP_NAME)) {
        Pair<JobDetail, Trigger> pair = manager.findInfo(key);
        SpiderInfo info = (SpiderInfo)pair.getLeft().getJobDataMap().get("spiderInfo");
        result.put(info.getId(), Triple.of(info, key, pair.getRight()));
    }
    return builder.bundle(null, () -> result);
}
项目:lams    文件:LoggingJobHistoryPlugin.java   
/** 
 * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
 */
public void jobExecutionVetoed(JobExecutionContext context) {

    if (!getLog().isInfoEnabled()) {
        return;
    } 

    Trigger trigger = context.getTrigger();

    Object[] args = {
        context.getJobDetail().getKey().getName(),
        context.getJobDetail().getKey().getGroup(), new java.util.Date(),
        trigger.getKey().getName(), trigger.getKey().getGroup(),
        trigger.getPreviousFireTime(), trigger.getNextFireTime(),
        Integer.valueOf(context.getRefireCount())
    };

    getLog().info(MessageFormat.format(getJobWasVetoedMessage(), args));
}
项目: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(); 
    }  
}
项目:lams    文件:TriggerSupport.java   
public static CompositeData toCompositeData(Trigger trigger) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        trigger.getKey().getName(),
                        trigger.getKey().getGroup(),
                        trigger.getJobKey().getName(),
                        trigger.getJobKey().getGroup(),
                        trigger.getDescription(),
                        JobDataMapSupport.toTabularData(trigger
                                .getJobDataMap()),
                        trigger.getCalendarName(),
                        ((OperableTrigger)trigger).getFireInstanceId(),
                        trigger.getMisfireInstruction(),
                        trigger.getPriority(), trigger.getStartTime(),
                        trigger.getEndTime(), trigger.getNextFireTime(),
                        trigger.getPreviousFireTime(),
                        trigger.getFinalFireTime() });
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
项目:asura    文件:JobStoreSupport.java   
private void doUpdateOfMisfiredTrigger(Connection conn, SchedulingContext ctxt, Trigger trig, boolean forceState, String newStateIfNotComplete, boolean recovering) throws JobPersistenceException {
    Calendar cal = null;
    if (trig.getCalendarName() != null) {
        cal = retrieveCalendar(conn, ctxt, trig.getCalendarName());
    }

    schedSignaler.notifyTriggerListenersMisfired(trig);

    trig.updateAfterMisfire(cal);

    if (trig.getNextFireTime() == null) {
        storeTrigger(conn, ctxt, trig,
            null, true, STATE_COMPLETE, forceState, recovering);
    } else {
        storeTrigger(conn, ctxt, trig, null, true, newStateIfNotComplete,
                forceState, false);
    }
}
项目:springboot-shiro-cas-mybatis    文件:StaticMetadataResolverAdapter.java   
/**
 * Refresh metadata. Schedules the job to retrieve metadata.
 */
@PostConstruct
public void refreshMetadata() {
    final Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            buildMetadataResolverAggregate();
        }
    });
    thread.start();

    final JobDetail job = JobBuilder.newJob(this.getClass())
            .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString())).build();
    final Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString()))
            .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInMinutes(this.refreshIntervalInMinutes)
                    .repeatForever()).build();

    try {
        scheduler.scheduleJob(job, trigger);
    } catch (final SchedulerException e) {
        throw new RuntimeException(e);
    }
}
项目:lams    文件:DailyTimeIntervalTriggerImpl.java   
/**
 * <p>
 * Updates the <code>DailyTimeIntervalTrigger</code>'s state based on the
 * MISFIRE_INSTRUCTION_XXX that was selected when the <code>DailyTimeIntervalTrigger</code>
 * was created.
 * </p>
 * 
 * <p>
 * If the misfire instruction is set to MISFIRE_INSTRUCTION_SMART_POLICY,
 * then the following scheme will be used: <br>
 * <ul>
 * <li>The instruction will be interpreted as <code>MISFIRE_INSTRUCTION_FIRE_ONCE_NOW</code>
 * </ul>
 * </p>
 */
@Override
public void updateAfterMisfire(org.quartz.Calendar cal) {
    int instr = getMisfireInstruction();

    if(instr == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY)
        return;

    if (instr == MISFIRE_INSTRUCTION_SMART_POLICY) {
        instr = MISFIRE_INSTRUCTION_FIRE_ONCE_NOW;
    }

    if (instr == MISFIRE_INSTRUCTION_DO_NOTHING) {
        Date newFireTime = getFireTimeAfter(new Date());
        while (newFireTime != null && cal != null
                && !cal.isTimeIncluded(newFireTime.getTime())) {
            newFireTime = getFireTimeAfter(newFireTime);
        }
        setNextFireTime(newFireTime);
    } else if (instr == MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) { 
        // fire once now...
        setNextFireTime(new Date());
        // the new fire time afterward will magically preserve the original  
        // time of day for firing for day/week/month interval triggers, 
        // because of the way getFireTimeAfter() works - in its always restarting
        // computation from the start time.
    }
}
项目:nh-micro    文件:MicroQuartzManager.java   
/** 
 * @Description: 添加一个定时任务  
 * @param jobName 任务名 
 * @param jobGroupName 任务组名 
 * @param triggerName 触发器名  
 * @param triggerGroupName 触发器组名 
 * @param jobClass 任务 
 * @param time 时间设置,参考quartz说明文档 
 * 
 */  
@SuppressWarnings("unchecked")    
public static void addJob(String jobName, String jobGroupName,    
        String triggerName, String triggerGroupName, Class jobClass,    
        String time) {    
    try {    
        Scheduler sched = gSchedulerFactory.getScheduler();    
        JobDetail job = newJob(jobClass)  
                .withIdentity(jobName, jobGroupName)  
                .build();  
        // 表达式调度构建器  
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(time);  
        // 按新的cronExpression表达式构建一个新的trigger  
        Trigger trigger = TriggerBuilder  
                .newTrigger()  
                .withIdentity(triggerName, triggerGroupName)  
                        .withSchedule(scheduleBuilder).build();  
        sched.scheduleJob(job, trigger);   
        // 启动    
        if (!sched.isShutdown()) {    
            sched.start();    
        }    
    } catch (Exception e) {    
        throw new RuntimeException(e);    
    }    
}
项目:gitplex-mit    文件:DefaultTaskScheduler.java   
@Override
public synchronized String schedule(SchedulableTask task) {
       try {
        JobDetail job = JobBuilder.newJob(HelperTask.class)
                .withIdentity(UUID.randomUUID().toString())
                .build();
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(UUID.randomUUID().toString())
                .withSchedule(task.getScheduleBuilder())
                .forJob(job)
                .build();
        trigger.getJobDataMap().put("task", task);
        quartz.scheduleJob(job, trigger);
        return job.getKey().getName();
    } catch (SchedulerException e) {
        throw new RuntimeException(e);
    }
}
项目:asura    文件:RAMJobStore.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>
 *
 */
public void resumeJobGroup(SchedulingContext ctxt, String groupName) {
    synchronized (lock) {
        String[] jobNames = getJobNames(ctxt, groupName);

        if(pausedJobGroups.contains(groupName)) {
            pausedJobGroups.remove(groupName);
        }

        for (int i = 0; i < jobNames.length; i++) {
            Trigger[] triggers = getTriggersForJob(ctxt, jobNames[i],
                    groupName);
            for (int j = 0; j < triggers.length; j++) {
                resumeTrigger(ctxt, triggers[j].getName(),
                        triggers[j].getGroup());
            }
        }
    }
}
项目:cas-server-4.2.1    文件:StaticMetadataResolverAdapter.java   
/**
 * Refresh metadata. Schedules the job to retrieve metadata.
 */
@PostConstruct
public void refreshMetadata() {
    final Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            buildMetadataResolverAggregate();
        }
    });
    thread.start();

    final JobDetail job = JobBuilder.newJob(this.getClass())
            .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString())).build();
    final Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString()))
            .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInMinutes(this.refreshIntervalInMinutes)
                    .repeatForever()).build();

    try {
        scheduler.scheduleJob(job, trigger);
    } catch (final SchedulerException e) {
        throw new RuntimeException(e);
    }
}
项目:sponge    文件:QuartzEventScheduler.java   
/**
 * Schedules an event after a specified time with the specified interval.
 *
 * @param event event.
 * @param delay delay in milliseconds.
 * @param interval interval in milliseconds.
 * @return scheduled event entry.
 */
@Override
public EventSchedulerEntry scheduleAfter(Event event, long delay, long interval) {
    TriggerBuilder<Trigger> builder = newTrigger();

    if (delay > 0) {
        builder.startAt(Date.from(Instant.now().plusMillis(delay)));
    }

    if (interval > 0) {
        builder.withSchedule(
                simpleSchedule().withIntervalInMilliseconds(interval).repeatForever().withMisfireHandlingInstructionFireNow());
    }

    return doSchedule(event, builder.build(), interval == 0);
}
项目:asura    文件:QuartzScheduler.java   
public void notifySchedulerListenersSchduled(Trigger trigger) {
    // build a list of all scheduler listeners that are to be notified...
    List schedListeners = getSchedulerListeners();

    // notify all scheduler listeners
    java.util.Iterator itr = schedListeners.iterator();
    while (itr.hasNext()) {
        SchedulerListener sl = (SchedulerListener) itr.next();
        try {
            sl.jobScheduled(trigger);
        } catch (Exception e) {
            getLog().error(
                    "Error while notifying SchedulerListener of scheduled job."
                            + "  Triger=" + trigger.getFullName(), e);
        }
    }
}
项目:Limitart    文件:SchedulerUtil.java   
/**
 * 增加一个调度任务(cron版)
 * 
 * @param name
 *            任务名称
 * @param job
 *            执行内容
 * @param cronExpression
 *            cron表达式
 * @throws SchedulerException
 */
public Trigger addSchedule(String name, Class<? extends Job> task, String cronExpression, JobDataMap param)
        throws SchedulerException {
    Scheduler sched = SF.getScheduler();
    JobBuilder builder = JobBuilder.newJob(task);
    builder.withIdentity(name, Scheduler.DEFAULT_GROUP);
    if (param != null) {
        builder.usingJobData(param);
    }
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name, Scheduler.DEFAULT_GROUP)
            .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
    sched.scheduleJob(builder.build(), trigger);
    if (!sched.isShutdown())
        sched.start();
    return trigger;
}
项目:asura    文件:StdJDBCDelegate.java   
public Trigger[] selectTriggersForCalendar(Connection conn, String calName)
    throws SQLException, ClassNotFoundException, IOException {

    ArrayList trigList = new ArrayList();
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_TRIGGERS_FOR_CALENDAR));
        ps.setString(1, calName);
        rs = ps.executeQuery();

        while (rs.next()) {
            trigList.add(selectTrigger(conn,
                    rs.getString(COL_TRIGGER_NAME), rs
                            .getString(COL_TRIGGER_GROUP)));
        }
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }

    return (Trigger[]) trigList.toArray(new Trigger[trigList.size()]);
}
项目:lams    文件:RAMJobStore.java   
protected boolean applyMisfire(TriggerWrapper tw) {

        long misfireTime = System.currentTimeMillis();
        if (getMisfireThreshold() > 0) {
            misfireTime -= getMisfireThreshold();
        }

        Date tnft = tw.trigger.getNextFireTime();
        if (tnft == null || tnft.getTime() > misfireTime 
                || tw.trigger.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) { 
            return false; 
        }

        Calendar cal = null;
        if (tw.trigger.getCalendarName() != null) {
            cal = retrieveCalendar(tw.trigger.getCalendarName());
        }

        signaler.notifyTriggerListenersMisfired((OperableTrigger)tw.trigger.clone());

        tw.trigger.updateAfterMisfire(cal);

        if (tw.trigger.getNextFireTime() == null) {
            tw.state = TriggerWrapper.STATE_COMPLETE;
            signaler.notifySchedulerListenersFinalized(tw.trigger);
            synchronized (lock) {
                timeTriggers.remove(tw);
            }
        } else if (tnft.equals(tw.trigger.getNextFireTime())) {
            return false;
        }

        return true;
    }
项目:asura    文件:LoggingTriggerHistoryPlugin.java   
public void triggerFired(Trigger trigger, JobExecutionContext context) {
    if (!getLog().isInfoEnabled()) {
        return;
    } 

    Object[] args = {
        trigger.getName(), trigger.getGroup(),
        trigger.getPreviousFireTime(), trigger.getNextFireTime(),
        new java.util.Date(), context.getJobDetail().getName(),
        context.getJobDetail().getGroup(),
        new Integer(context.getRefireCount())
    };

    getLog().info(MessageFormat.format(getTriggerFiredMessage(), args));
}
项目:spring-boot-quartz-demo    文件:JobServiceImpl.java   
/**
 * Schedule a job by jobName at given date.
 */
@Override
public boolean scheduleCronJob(String jobName, Class<? extends QuartzJobBean> jobClass, Date date, String cronExpression) {
    System.out.println("Request received to scheduleJob");

    String jobKey = jobName;
    String groupKey = "SampleGroup";    
    String triggerKey = jobName;        

    JobDetail jobDetail = JobUtil.createJob(jobClass, false, context, jobKey, groupKey);

    System.out.println("creating trigger for key :"+jobKey + " at date :"+date);
    Trigger cronTriggerBean = JobUtil.createCronTrigger(triggerKey, date, cronExpression, SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);

    try {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        Date dt = scheduler.scheduleJob(jobDetail, cronTriggerBean);
        System.out.println("Job with key jobKey :"+jobKey+ " and group :"+groupKey+ " scheduled successfully for date :"+dt);
        return true;
    } catch (SchedulerException e) {
        System.out.println("SchedulerException while scheduling job with key :"+jobKey + " message :"+e.getMessage());
        e.printStackTrace();
    }

    return false;
}
项目:asura    文件:LoggingTriggerHistoryPlugin.java   
public void triggerMisfired(Trigger trigger) {
    if (!getLog().isInfoEnabled()) {
        return;
    } 

    Object[] args = {
        trigger.getName(), trigger.getGroup(),
        trigger.getPreviousFireTime(), trigger.getNextFireTime(),
        new java.util.Date(), trigger.getJobName(),
        trigger.getJobGroup()
    };

    getLog().info(MessageFormat.format(getTriggerMisfiredMessage(), args));
}
项目:springboot-quartz    文件:ScheduleJobService.java   
public List<ScheduleJob> getRunningJobList() throws SchedulerException{  
    List<JobExecutionContext> executingJobList = scheduler.getCurrentlyExecutingJobs();  
    List<ScheduleJob> jobList = new ArrayList<>(executingJobList.size());  
    for(JobExecutionContext executingJob : executingJobList){  
        ScheduleJob scheduleJob = new ScheduleJob();  
        JobDetail jobDetail = executingJob.getJobDetail();  
        JobKey jobKey = jobDetail.getKey();  
        Trigger trigger = executingJob.getTrigger();  
        this.wrapScheduleJob(scheduleJob,scheduler,jobKey,trigger);  
        jobList.add(scheduleJob);  
    }  
    return jobList;  
}
项目:lams    文件:QuartzScheduler.java   
public void notifyTriggerListenersMisfired(Trigger trigger)
    throws SchedulerException {
    // build a list of all trigger listeners that are to be notified...
    List<TriggerListener> triggerListeners = buildTriggerListenerList();

    // notify all trigger listeners in the list
    for(TriggerListener tl: triggerListeners) {
        try {
            if(!matchTriggerListener(tl, trigger.getKey()))
                continue;
            tl.triggerMisfired(trigger);
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "TriggerListener '" + tl.getName()
                            + "' threw exception: " + e.getMessage(), e);
            throw se;
        }
    }
}
项目:taboola-cronyx    文件:QuartzSchedulerServiceImpl.java   
@Override
public void saveOrUpdateTrigger(TriggerDefinition cronyxTrigger) {
    try {
        validateTrigger(cronyxTrigger);
        onStoreAfterTrigger(cronyxTrigger);
        Trigger newQuartzTrigger = cronyxToQuartzSelector.convert(cronyxTrigger);
        Trigger existingQuartzTrigger = scheduler.getTrigger(newQuartzTrigger.getKey());
        if (existingQuartzTrigger == null) {
            scheduler.scheduleJob(newQuartzTrigger);
        } else {
            updateExistingTrigger(newQuartzTrigger, existingQuartzTrigger);
        }
    } catch (SchedulerException e) {
        throw new SchedulingException(e);
    }
}
项目:asura    文件:JobStoreSupport.java   
/**
 * <p>
 * Inform the <code>JobStore</code> that the scheduler is now firing the
 * given <code>Trigger</code> (executing its associated <code>Job</code>),
 * that it had previously acquired (reserved).
 * </p>
 * 
 * @return null if the trigger or its job or calendar no longer exist, or
 *         if the trigger was not successfully put into the 'executing'
 *         state.
 */
public TriggerFiredBundle triggerFired(
        final SchedulingContext ctxt, final Trigger trigger) throws JobPersistenceException {
    return 
        (TriggerFiredBundle)executeInNonManagedTXLock(
            LOCK_TRIGGER_ACCESS,
            new TransactionCallback() {
                public Object execute(Connection conn) throws JobPersistenceException {
                    try {
                        return triggerFired(conn, ctxt, trigger);
                    } catch (JobPersistenceException jpe) {
                        // If job didn't exisit, we still want to commit our work and return null.
                        if (jpe.getErrorCode() == SchedulerException.ERR_PERSISTENCE_JOB_DOES_NOT_EXIST) {
                            return null;
                        } else {
                            throw jpe;
                        }
                    }
                }
            });
}
项目:asura    文件:JobStoreSupport.java   
/**
 * <p>
 * Store the given <code>{@link org.quartz.JobDetail}</code> and <code>{@link org.quartz.Trigger}</code>.
 * </p>
 * 
 * @param newJob
 *          The <code>JobDetail</code> to be stored.
 * @param newTrigger
 *          The <code>Trigger</code> to be stored.
 * @throws ObjectAlreadyExistsException
 *           if a <code>Job</code> with the same name/group already
 *           exists.
 */
public void storeJobAndTrigger(final SchedulingContext ctxt, final JobDetail newJob,
        final Trigger newTrigger) 
    throws ObjectAlreadyExistsException, JobPersistenceException {
    executeInLock(
        (isLockOnInsert()) ? LOCK_TRIGGER_ACCESS : null,
        new VoidTransactionCallback() {
            public void execute(Connection conn) throws JobPersistenceException {
                if (newJob.isVolatile() && !newTrigger.isVolatile()) {
                    JobPersistenceException jpe = 
                        new JobPersistenceException(
                            "Cannot associate non-volatile trigger with a volatile job!");
                    jpe.setErrorCode(SchedulerException.ERR_CLIENT_ERROR);
                    throw jpe;
                }

                storeJob(conn, ctxt, newJob, false);
                storeTrigger(conn, ctxt, newTrigger, newJob, false,
                        Constants.STATE_WAITING, false, false);
            }
        });
}
项目: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;
}
项目:springboot-shiro-cas-mybatis    文件:AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapter.java   
/**
 * Schedule throttle job.
 */
@PostConstruct
public void scheduleThrottleJob() {
    try {
        if (shouldScheduleCleanerJob()) {
            logger.info("Preparing to schedule throttle job");

            final JobDetail job = JobBuilder.newJob(this.getClass())
                .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString()))
                .build();

            final Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString()))
                .startAt(new Date(System.currentTimeMillis() + this.startDelay))
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInMilliseconds(this.refreshInterval)
                    .repeatForever()).build();

            logger.debug("Scheduling {} job", this.getClass().getName());
            scheduler.scheduleJob(job, trigger);
            logger.info("{} will clean tickets every {} seconds",
                this.getClass().getSimpleName(),
                TimeUnit.MILLISECONDS.toSeconds(this.refreshInterval));
        }
    } catch (final Exception e){
        logger.warn(e.getMessage(), e);
    }

}
项目:springboot-shiro-cas-mybatis    文件:DefaultServicesManagerImpl.java   
/**
 * Schedule reloader job.
 */
@PostConstruct
public void scheduleReloaderJob() {
    try {
        if (shouldScheduleLoaderJob()) {
            LOGGER.debug("Preparing to schedule reloader job");

            final JobDetail job = JobBuilder.newJob(ServiceRegistryReloaderJob.class)
                    .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString()))
                    .build();

            final Trigger trigger = TriggerBuilder.newTrigger()
                    .withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString()))
                    .startAt(DateTime.now().plusSeconds(this.startDelay).toDate())
                    .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                            .withIntervalInSeconds(this.refreshInterval)
                            .repeatForever()).build();

            LOGGER.debug("Scheduling {} job", this.getClass().getName());
            scheduler.scheduleJob(job, trigger);
            LOGGER.info("Services manager will reload service definitions every {} seconds",
                    this.refreshInterval);
        }

    } catch (final Exception e) {
        LOGGER.warn(e.getMessage(), e);
    }
}
项目:asura    文件:JobStoreSupport.java   
/**
 * <p>
 * Inform the <code>JobStore</code> that the scheduler no longer plans to
 * fire the given <code>Trigger</code>, that it had previously acquired
 * (reserved).
 * </p>
 */
public void releaseAcquiredTrigger(final SchedulingContext ctxt, final Trigger trigger)
    throws JobPersistenceException {
    executeInNonManagedTXLock(
        LOCK_TRIGGER_ACCESS,
        new VoidTransactionCallback() {
            public void execute(Connection conn) throws JobPersistenceException {
                releaseAcquiredTrigger(conn, ctxt, trigger);
            }
        });
}
项目:lams    文件:PlainTerracottaJobStore.java   
@Override
public Trigger.TriggerState getTriggerState(final TriggerKey triggerKey) throws JobPersistenceException {
  return clusteredJobStore.getTriggerState(triggerKey);
}
项目:springboot-shiro-cas-mybatis    文件:AutowiringSchedulerFactoryBean.java   
@Override
public void afterPropertiesSet() throws Exception {
    final Map<String, Trigger> triggers = this.applicationContext.getBeansOfType(Trigger.class);
    super.setTriggers(triggers.values().toArray(new Trigger[triggers.size()]));

    logger.debug("Autowired the following triggers defined in application context: {}", triggers.keySet().toString());
    super.afterPropertiesSet();
}
项目:lams    文件:TriggerSupport.java   
public static TabularData toTabularData(List<? extends Trigger> triggers) {
    TabularData tData = new TabularDataSupport(TABULAR_TYPE);
    if (triggers != null) {
        ArrayList<CompositeData> list = new ArrayList<CompositeData>();
        for (Trigger trigger : triggers) {
            list.add(toCompositeData(trigger));
        }
        tData.putAll(list.toArray(new CompositeData[list.size()]));
    }
    return tData;
}
项目:asura    文件:RemoteScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
public Trigger getTrigger(String triggerName, String triggerGroup)
    throws SchedulerException {
    try {
        return getRemoteScheduler().getTrigger(schedCtxt, triggerName,
                triggerGroup);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:taboola-cronyx    文件:QuartzTriggerListenerAdapter.java   
@Override
public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
    CronyxExecutionContext cronyxContext = contextRegistry.get(context.getFireInstanceId());
    if (cronyxContext == null) {
        logger.error("there is no active context registered with the name [%s]", context.getFireInstanceId());
        throw new Error("this should never happen as a triggetFired event should always be invoked before triggerComplete");
    }

    updateCronyxContext(context, cronyxContext);
    onEvent(cronyxContext);
    contextRegistry.unregister(context.getFireInstanceId());
}
项目:quartz-web    文件:QuartzManager.java   
/**
 * 获取所有的Trigger
 * @param schedulerName
 * @return
 * @throws SchedulerException
 */
public List<? extends Trigger> getAllTriggersOfScheduler(String schedulerName) throws SchedulerException {
    List<Trigger> triggersOfScheduler = new ArrayList<Trigger>();
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    List<JobDetail> jobDetails = getAllJobsOfScheduler(schedulerName);
    for (JobDetail jobDetail : jobDetails) {
        List<? extends Trigger> triggersOfJob = QuartzUtils.getTriggersOfJob(jobDetail, scheduler);
        triggersOfScheduler.addAll(triggersOfJob);
    }

    return triggersOfScheduler;
}
项目:lams    文件:RemoteScheduler.java   
public void scheduleJob(JobDetail jobDetail, Set<? extends Trigger> triggersForJob, boolean replace) throws SchedulerException {
    try {
        getRemoteScheduler().scheduleJob(jobDetail, triggersForJob, replace);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:lams    文件:QuartzScheduler.java   
public void notifySchedulerListenersFinalized(Trigger trigger) {
    // build a list of all scheduler listeners that are to be notified...
    List<SchedulerListener> schedListeners = buildSchedulerListenerList();

    // notify all scheduler listeners
    for(SchedulerListener sl: schedListeners) {
        try {
            sl.triggerFinalized(trigger);
        } catch (Exception e) {
            getLog().error(
                    "Error while notifying SchedulerListener of finalized trigger."
                            + "  Triger=" + trigger.getKey(), e);
        }
    }
}
项目:lams    文件:QuartzSchedulerMBeanImpl.java   
public CompositeData getTrigger(String name, String groupName) throws Exception {
    try {
        Trigger trigger = scheduler.getTrigger(triggerKey(name, groupName));
        return TriggerSupport.toCompositeData(trigger);
    } catch (Exception e) {
        throw newPlainException(e);
    }
}
项目:asura    文件:RemoteMBeanScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
public Date rescheduleJob(String triggerName,
        String groupName, Trigger newTrigger) throws SchedulerException {
    return (Date)invoke(
            "unscheduleJob", 
            new Object[] { schedulingContext, triggerName, groupName, newTrigger}, 
            new String[] { SchedulingContext.class.getName(), String.class.getName(), String.class.getName(), Trigger.class.getName() });
}
项目:quartz-web    文件:QuartzManager.java   
/**
 * 更新Trigger
 * @param schedulerName
 * @param trigger
 * @throws SchedulerException
 */
public void updateTriggerForJob(String schedulerName, Trigger trigger) throws SchedulerException {
    Assert.notNull(trigger, "trigger can not be null");
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    if (existTrigger(schedulerName, QuartzUtils.getTriggerName(trigger), QuartzUtils.getTriggerGroup(trigger))) {
        scheduler.rescheduleJob(trigger.getKey(), trigger);
    } else {
        throw new IllegalArgumentException("trigger [" + trigger.getKey().getName() +
                ":" + trigger.getKey().getGroup() + "] not exist");
    }
}
项目:asura    文件:RAMJobStore.java   
/**
 * <p>
 * Remove (delete) the <code>{@link org.quartz.Job}</code> with the given
 * name, and any <code>{@link org.quartz.Trigger}</code> s that reference
 * it.
 * </p>
 *
 * @param jobName
 *          The name of the <code>Job</code> to be removed.
 * @param groupName
 *          The group name of the <code>Job</code> to be removed.
 * @return <code>true</code> if a <code>Job</code> with the given name &
 *         group was found and removed from the store.
 */
public boolean removeJob(SchedulingContext ctxt, String jobName,
        String groupName) {
    String key = JobWrapper.getJobNameKey(jobName, groupName);

    boolean found = false;

    synchronized (lock) {
        Trigger[] trigger = getTriggersForJob(ctxt, jobName,
                groupName);
        for (int i = 0; i < trigger.length; i++) {
            Trigger trig = trigger[i];
            this.removeTrigger(ctxt, trig.getName(), trig.getGroup());
            found = true;
        }

        found = (jobsByFQN.remove(key) != null) | found;
        if (found) {

            HashMap grpMap = (HashMap) jobsByGroup.get(groupName);
            if (grpMap != null) {
                grpMap.remove(jobName);
                if (grpMap.size() == 0) {
                    jobsByGroup.remove(groupName);
                }
            }
        }
    }

    return found;
}