org.quartz.Scheduler.getContext()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中org.quartz.Scheduler.getContext()方法的一些代码示例,展示了Scheduler.getContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.getContext()方法的具体详情如下:
包路径:org.quartz.Scheduler
类名称:Scheduler
方法名:getContext

Scheduler.getContext介绍

[英]Returns the SchedulerContext of the Scheduler.
[中]返回SchedulerSchedulerContext

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * 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);
  }
}

代码示例来源:origin: AxonFramework/AxonFramework

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;
}

代码示例来源:origin: AxonFramework/AxonFramework

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());
}

代码示例来源:origin: org.springframework/spring-context-support

/**
 * 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);
  }
}

代码示例来源:origin: spring-projects/spring-framework

((SchedulerContextAware) this.jobFactory).setSchedulerContext(scheduler.getContext());

代码示例来源:origin: quartz-scheduler/quartz

@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);
}

代码示例来源:origin: quartz-scheduler/quartz

@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);
}

代码示例来源:origin: quartz-scheduler/quartz

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);
  }
}

代码示例来源:origin: quartz-scheduler/quartz

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);
  }
}

代码示例来源:origin: AxonFramework/AxonFramework

@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);
  }
}

代码示例来源:origin: quartz-scheduler/quartz

getScheduler().getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName(), this);

代码示例来源:origin: quartz-scheduler/quartz

getScheduler().getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName(), this);

代码示例来源:origin: quartz-scheduler/quartz

@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;
}

代码示例来源:origin: quartz-scheduler/quartz

@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;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * 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);
}

代码示例来源:origin: quartz-scheduler/quartz

SchedulerContext schedCtxt = null;
try {
  schedCtxt = context.getScheduler().getContext();
} catch (SchedulerException e) {
  throw new JobExecutionException("Error obtaining scheduler context.", e, false);

代码示例来源:origin: quartz-scheduler/quartz

SchedulerContext schedCtxt = null;
try {
  schedCtxt = context.getScheduler().getContext();
} catch (SchedulerException e) {
  throw new JobExecutionException("Error obtaining scheduler context.", e, false);

代码示例来源:origin: AxonFramework/AxonFramework

schedulerContext = context.getScheduler().getContext();
} catch (Exception e) {
  logger.error("Exception occurred during processing a deadline job [{}]", jobDetail.getDescription(), e);

代码示例来源:origin: spring-projects/spring-framework

given(scheduler.getContext()).willReturn(schedulerContext);
  schedulerFactoryBean.start();
  Scheduler returnedScheduler = schedulerFactoryBean.getObject();
  assertEquals(tb, returnedScheduler.getContext().get("testBean"));
  assertEquals(ac, returnedScheduler.getContext().get("appCtx"));

代码示例来源:origin: org.springframework/spring-context-support

/**
 * 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);
}

相关文章