/** * Expose the specified context attributes and/or the current * ApplicationContext in the Quartz SchedulerContext. */ private void populateSchedulerContext(Scheduler scheduler) throws SchedulerException { // Put specified objects into Scheduler context. if (this.schedulerContextMap != null) { scheduler.getContext().putAll(this.schedulerContextMap); } // Register ApplicationContext in Scheduler context. if (this.applicationContextSchedulerContextKey != null) { if (this.applicationContext == null) { throw new IllegalStateException( "SchedulerFactoryBean needs to be set up in an ApplicationContext " + "to be able to handle an 'applicationContextSchedulerContextKey'"); } scheduler.getContext().put(this.applicationContextSchedulerContextKey, this.applicationContext); } }
private void initialize() throws SchedulerException { scheduler.getContext().put(EVENT_BUS_KEY, eventBus); scheduler.getContext().put(TRANSACTION_MANAGER_KEY, transactionManager); scheduler.getContext().put(EVENT_JOB_DATA_BINDER_KEY, jobDataBinder); initialized = true; }
private void initialize() throws SchedulerException { scheduler.getContext().put(DeadlineJob.TRANSACTION_MANAGER_KEY, transactionManager); scheduler.getContext().put(DeadlineJob.SCOPE_AWARE_RESOLVER, scopeAwareProvider); scheduler.getContext().put(DeadlineJob.JOB_DATA_SERIALIZER, serializer); scheduler.getContext().put(DeadlineJob.HANDLER_INTERCEPTORS, handlerInterceptors()); }
/** * Expose the specified context attributes and/or the current * ApplicationContext in the Quartz SchedulerContext. */ private void populateSchedulerContext(Scheduler scheduler) throws SchedulerException { // Put specified objects into Scheduler context. if (this.schedulerContextMap != null) { scheduler.getContext().putAll(this.schedulerContextMap); } // Register ApplicationContext in Scheduler context. if (this.applicationContextSchedulerContextKey != null) { if (this.applicationContext == null) { throw new IllegalStateException( "SchedulerFactoryBean needs to be set up in an ApplicationContext " + "to be able to handle an 'applicationContextSchedulerContextKey'"); } scheduler.getContext().put(this.applicationContextSchedulerContextKey, this.applicationContext); } }
((SchedulerContextAware) this.jobFactory).setSchedulerContext(scheduler.getContext());
@Override public void initialize(String name, Scheduler scheduler, ClassLoadHelper helper) throws SchedulerException { getLog().info("Registering Job Interrupt Monitor Plugin"); this.name = name; this.executor = Executors.newScheduledThreadPool(1); scheduler.getContext().put(JOB_INTERRUPT_MONITOR_KEY, this); this.scheduler = scheduler; // Set the trigger Listener as this class to the ListenerManager here this.scheduler.getListenerManager().addTriggerListener(this); }
@Override public void initialize(String name, Scheduler scheduler, ClassLoadHelper helper) throws SchedulerException { getLog().info("Registering Job Interrupt Monitor Plugin"); this.name = name; this.executor = Executors.newScheduledThreadPool(1); scheduler.getContext().put(JOB_INTERRUPT_MONITOR_KEY, this); this.scheduler = scheduler; // Set the trigger Listener as this class to the ListenerManager here this.scheduler.getListenerManager().addTriggerListener(this); }
public void triggerFired(Trigger trigger, JobExecutionContext context) { // Call the scheduleJobInterruptMonitor and capture the ScheduledFuture in context try { // Schedule Monitor only if the job wants AutoInterruptable functionality if (context.getJobDetail().getJobDataMap().getBoolean(AUTO_INTERRUPTIBLE)) { JobInterruptMonitorPlugin monitorPlugin = (JobInterruptMonitorPlugin) context.getScheduler() .getContext().get(JOB_INTERRUPT_MONITOR_KEY); // Get the MaxRuntime from Job Data if NOT available use DEFAULT_MAX_RUNTIME from Plugin Configuration long jobDataDelay = DEFAULT_MAX_RUNTIME; if (context.getJobDetail().getJobDataMap().get(MAX_RUN_TIME) != null){ jobDataDelay = context.getJobDetail().getJobDataMap().getLong(MAX_RUN_TIME); } future = monitorPlugin.scheduleJobInterruptMonitor(context.getJobDetail().getKey(), jobDataDelay); getLog().debug("Job's Interrupt Monitor has been scheduled to interrupt with the delay :" + DEFAULT_MAX_RUNTIME); } } catch (SchedulerException e) { getLog().info("Error scheduling interrupt monitor " + e.getMessage(), e); } }
public void triggerFired(Trigger trigger, JobExecutionContext context) { // Call the scheduleJobInterruptMonitor and capture the ScheduledFuture in context try { // Schedule Monitor only if the job wants AutoInterruptable functionality if (context.getJobDetail().getJobDataMap().getBoolean(AUTO_INTERRUPTIBLE)) { JobInterruptMonitorPlugin monitorPlugin = (JobInterruptMonitorPlugin) context.getScheduler() .getContext().get(JOB_INTERRUPT_MONITOR_KEY); // Get the MaxRuntime from Job Data if NOT available use DEFAULT_MAX_RUNTIME from Plugin Configuration long jobDataDelay = DEFAULT_MAX_RUNTIME; if (context.getJobDetail().getJobDataMap().get(MAX_RUN_TIME) != null){ jobDataDelay = context.getJobDetail().getJobDataMap().getLong(MAX_RUN_TIME); } future = monitorPlugin.scheduleJobInterruptMonitor(context.getJobDetail().getKey(), jobDataDelay); getLog().debug("Job's Interrupt Monitor has been scheduled to interrupt with the delay :" + DEFAULT_MAX_RUNTIME); } } catch (SchedulerException e) { getLog().info("Error scheduling interrupt monitor " + e.getMessage(), e); } }
@Override public void execute(JobExecutionContext context) throws JobExecutionException { logger.debug("Starting job to publish a scheduled event"); JobDetail jobDetail = context.getJobDetail(); JobDataMap jobData = jobDetail.getJobDataMap(); try { SchedulerContext schedulerContext = context.getScheduler().getContext(); EventJobDataBinder jobDataBinder = (EventJobDataBinder) schedulerContext.get(EVENT_JOB_DATA_BINDER_KEY); Object event = jobDataBinder.fromJobData(jobData); EventMessage<?> eventMessage = createMessage(event); EventBus eventBus = (EventBus) context.getScheduler().getContext().get(EVENT_BUS_KEY); TransactionManager txManager = (TransactionManager) context.getScheduler().getContext().get(TRANSACTION_MANAGER_KEY); UnitOfWork<EventMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(null); if (txManager != null) { unitOfWork.attachTransaction(txManager); } unitOfWork.execute(() -> eventBus.publish(eventMessage)); if (logger.isInfoEnabled()) { logger.info("Job successfully executed. Scheduled Event [{}] has been published.", eventMessage.getPayloadType().getSimpleName()); } } catch (Exception e) { logger.error("Exception occurred while publishing scheduled event [{}]", jobDetail.getDescription(), e); throw new JobExecutionException(e); } }
getScheduler().getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName(), this);
getScheduler().getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName(), this);
@Override public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException { Job job = super.newJob(bundle, scheduler); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.putAll(scheduler.getContext()); jobDataMap.putAll(bundle.getJobDetail().getJobDataMap()); jobDataMap.putAll(bundle.getTrigger().getJobDataMap()); setBeanProps(job, jobDataMap); return job; }
@Override public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException { Job job = super.newJob(bundle, scheduler); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.putAll(scheduler.getContext()); jobDataMap.putAll(bundle.getJobDetail().getJobDataMap()); jobDataMap.putAll(bundle.getTrigger().getJobDataMap()); setBeanProps(job, jobDataMap); return job; }
/** * This implementation applies the passed-in job data map as bean property * values, and delegates to {@code executeInternal} afterwards. * @see #executeInternal */ @Override public final void execute(JobExecutionContext context) throws JobExecutionException { try { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValues(context.getScheduler().getContext()); pvs.addPropertyValues(context.getMergedJobDataMap()); bw.setPropertyValues(pvs, true); } catch (SchedulerException ex) { throw new JobExecutionException(ex); } executeInternal(context); }
SchedulerContext schedCtxt = null; try { schedCtxt = context.getScheduler().getContext(); } catch (SchedulerException e) { throw new JobExecutionException("Error obtaining scheduler context.", e, false);
SchedulerContext schedCtxt = null; try { schedCtxt = context.getScheduler().getContext(); } catch (SchedulerException e) { throw new JobExecutionException("Error obtaining scheduler context.", e, false);
schedulerContext = context.getScheduler().getContext(); } catch (Exception e) { logger.error("Exception occurred during processing a deadline job [{}]", jobDetail.getDescription(), e);
given(scheduler.getContext()).willReturn(schedulerContext); schedulerFactoryBean.start(); Scheduler returnedScheduler = schedulerFactoryBean.getObject(); assertEquals(tb, returnedScheduler.getContext().get("testBean")); assertEquals(ac, returnedScheduler.getContext().get("appCtx"));
/** * This implementation applies the passed-in job data map as bean property * values, and delegates to {@code executeInternal} afterwards. * @see #executeInternal */ @Override public final void execute(JobExecutionContext context) throws JobExecutionException { try { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValues(context.getScheduler().getContext()); pvs.addPropertyValues(context.getMergedJobDataMap()); bw.setPropertyValues(pvs, true); } catch (SchedulerException ex) { throw new JobExecutionException(ex); } executeInternal(context); }