下面列出了怎么用org.quartz.spi.TriggerFiredBundle的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Create the job instance, populating it with property values taken
* from the scheduler context, job data map and trigger data map.
*/
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object job = super.createJobInstance(bundle);
if (isEligibleForPropertyPopulation(job)) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
MutablePropertyValues pvs = new MutablePropertyValues();
if (this.schedulerContext != null) {
pvs.addPropertyValues(this.schedulerContext);
}
pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
if (this.ignoredUnknownProperties != null) {
for (String propName : this.ignoredUnknownProperties) {
if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
pvs.removePropertyValue(propName);
}
}
bw.setPropertyValues(pvs);
}
else {
bw.setPropertyValues(pvs, true);
}
}
return job;
}
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException
{
Job result = null;
try
{
Class<? extends Job> jobClass = bundle.getJobDetail().getJobClass();
result = BeanProvider.getContextualReference(jobClass);
scheduler.getContext().put(jobClass.getName(), Boolean.TRUE);
}
catch (Exception e)
{
if (result == null)
{
result = defaultFactory.newJob(bundle, scheduler);
}
}
return result;
}
public Job newJob(TriggerFiredBundle bundle, Scheduler Scheduler) throws SchedulerException {
JobDetail jobDetail = bundle.getJobDetail();
Class<? extends Job> jobClass = jobDetail.getJobClass();
try {
if(log.isDebugEnabled()) {
log.debug(
"Producing instance of Job '" + jobDetail.getKey() +
"', class=" + jobClass.getName());
}
return jobClass.newInstance();
} catch (Exception e) {
SchedulerException se = new SchedulerException(
"Problem instantiating class '"
+ jobDetail.getJobClass().getName() + "'", e);
throw se;
}
}
/**
* <p>
* Create a JobExcecutionContext with the given context data.
* </p>
*/
public JobExecutionContextImpl(Scheduler scheduler,
TriggerFiredBundle firedBundle, Job job) {
this.scheduler = scheduler;
this.trigger = firedBundle.getTrigger();
this.calendar = firedBundle.getCalendar();
this.jobDetail = firedBundle.getJobDetail();
this.job = job;
this.recovering = firedBundle.isRecovering();
this.fireTime = firedBundle.getFireTime();
this.scheduledFireTime = firedBundle.getScheduledFireTime();
this.prevFireTime = firedBundle.getPrevFireTime();
this.nextFireTime = firedBundle.getNextFireTime();
this.jobDataMap = new JobDataMap();
this.jobDataMap.putAll(jobDetail.getJobDataMap());
this.jobDataMap.putAll(trigger.getJobDataMap());
}
public Job newJob(TriggerFiredBundle bundle) throws SchedulerException {
JobDetail jobDetail = bundle.getJobDetail();
Class jobClass = jobDetail.getJobClass();
try {
if(log.isDebugEnabled()) {
log.debug(
"Producing instance of Job '" + jobDetail.getFullName() +
"', class=" + jobClass.getName());
}
return (Job) jobClass.newInstance();
} catch (Exception e) {
SchedulerException se = new SchedulerException(
"Problem instantiating class '"
+ jobDetail.getJobClass().getName() + "'", e);
throw se;
}
}
/**
* <p>
* Create a JobExcecutionContext with the given context data.
* </p>
*/
public JobExecutionContext(Scheduler scheduler,
TriggerFiredBundle firedBundle, Job job) {
this.scheduler = scheduler;
this.trigger = firedBundle.getTrigger();
this.calendar = firedBundle.getCalendar();
this.jobDetail = firedBundle.getJobDetail();
this.job = job;
this.recovering = firedBundle.isRecovering();
this.fireTime = firedBundle.getFireTime();
this.scheduledFireTime = firedBundle.getScheduledFireTime();
this.prevFireTime = firedBundle.getPrevFireTime();
this.nextFireTime = firedBundle.getNextFireTime();
this.jobDataMap = new JobDataMap();
this.jobDataMap.putAll(jobDetail.getJobDataMap());
this.jobDataMap.putAll(trigger.getJobDataMap());
}
/**
* <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;
}
}
}
});
}
/**
* Create the job instance, populating it with property values taken
* from the scheduler context, job data map and trigger data map.
*/
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object job = super.createJobInstance(bundle);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
MutablePropertyValues pvs = new MutablePropertyValues();
if (this.schedulerContext != null) {
pvs.addPropertyValues(this.schedulerContext);
}
pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
if (this.ignoredUnknownProperties != null) {
for (String propName : this.ignoredUnknownProperties) {
if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
pvs.removePropertyValue(propName);
}
}
bw.setPropertyValues(pvs);
}
else {
bw.setPropertyValues(pvs, true);
}
}
return job;
}
private void setTargetObject(Job job, TriggerFiredBundle bundle, boolean forceCreateObject) throws Exception {
PojoJobMeta pojoJobMeta = getPojoJobMeta(bundle.getJobDetail());
if (pojoJobMeta == null) return;
if (pojoJobMeta.getTargetObject() != null && !forceCreateObject) return;
Object targetObject;
Class targetClass = pojoJobMeta.getTargetClass();
try {
targetObject = beanFactory.getBean(targetClass);
} catch (NoSuchBeanDefinitionException e) {
targetObject = targetClass.newInstance();
beanFactory.autowireBean(targetObject);
}
populateJobDataMapTargetObject(bundle, targetObject);
pojoJobMeta.setTargetObject(targetObject);
MethodInvokingJobDetailFactoryBean methodInvoker = createMethodInvoker(pojoJobMeta);
methodInvoker.setTargetObject(targetObject);
MethodInvokingJob methodInvokingJob = (MethodInvokingJob) job;
methodInvokingJob.setMethodInvoker(methodInvoker);
}
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
Object job = beanFactory.getBean(bundle.getJobDetail().getKey().getName());
if (isEligibleForPropertyPopulation(job)) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
MutablePropertyValues pvs = new MutablePropertyValues();
if (this.schedulerContext != null) {
pvs.addPropertyValues(this.schedulerContext);
}
pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
if (this.ignoredUnknownProperties != null) {
for (String propName : this.ignoredUnknownProperties) {
if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
pvs.removePropertyValue(propName);
}
}
bw.setPropertyValues(pvs);
} else {
bw.setPropertyValues(pvs, true);
}
}
return job;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
// 调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
// 进行注入
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
try {
Object jobObject = createJobInstance(bundle);
return adaptJob(jobObject);
}
catch (Throwable ex) {
throw new SchedulerException("Job instantiation failed", ex);
}
}
/**
* Create the job instance, populating it with property values taken
* from the scheduler context, job data map and trigger data map.
*/
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object job = (this.applicationContext != null ?
this.applicationContext.getAutowireCapableBeanFactory().createBean(
bundle.getJobDetail().getJobClass(), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false) :
super.createJobInstance(bundle));
if (isEligibleForPropertyPopulation(job)) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
MutablePropertyValues pvs = new MutablePropertyValues();
if (this.schedulerContext != null) {
pvs.addPropertyValues(this.schedulerContext);
}
pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
if (this.ignoredUnknownProperties != null) {
for (String propName : this.ignoredUnknownProperties) {
if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
pvs.removePropertyValue(propName);
}
}
bw.setPropertyValues(pvs);
}
else {
bw.setPropertyValues(pvs, true);
}
}
return job;
}
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
log.info("+++++++createJobInstance");
final Object job = super.createJobInstance(bundle);
beanFactory.autowireBean(job);
return job;
}
/**
* create the job
*/
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object job = super.createJobInstance(bundle);
factory.autowireBean(job);
return job;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
try {
Object jobObject = createJobInstance(bundle);
return adaptJob(jobObject);
}
catch (Throwable ex) {
throw new SchedulerException("Job instantiation failed", ex);
}
}
/**
* Create the job instance, populating it with property values taken
* from the scheduler context, job data map and trigger data map.
*/
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object job = (this.applicationContext != null ?
this.applicationContext.getAutowireCapableBeanFactory().createBean(
bundle.getJobDetail().getJobClass(), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false) :
super.createJobInstance(bundle));
if (isEligibleForPropertyPopulation(job)) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
MutablePropertyValues pvs = new MutablePropertyValues();
if (this.schedulerContext != null) {
pvs.addPropertyValues(this.schedulerContext);
}
pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
if (this.ignoredUnknownProperties != null) {
for (String propName : this.ignoredUnknownProperties) {
if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
pvs.removePropertyValue(propName);
}
}
bw.setPropertyValues(pvs);
}
else {
bw.setPropertyValues(pvs, true);
}
}
return job;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
//进行注入
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
//进行注入
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
/**
* {@inheritDoc}
*/
@Override
public synchronized Job newJob(TriggerFiredBundle trigger, Scheduler s)
throws SchedulerException {
Long scheduleId = trigger.getJobDetail().getJobDataMap().getLong("schedule_id");
return new TaskoJob(scheduleId);
}
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
final Object job = super.createJobInstance(bundle);
beanFactory.autowireBean(job);
return job;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
//进行注入,这属于Spring的技术,不清楚的可以查看Spring的API.
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
public Job newJob(TriggerFiredBundle bundle, org.quartz.Scheduler Scheduler) throws SchedulerException {
Class<? extends Job> jobClass = bundle.getJobDetail().getJobClass();
if (jobClass.equals(InvokerJob.class)) {
return new InvokerJob(invokers);
}
return super.newJob(bundle, Scheduler);
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
// 调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
// 进行注入
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
//调用父类的方法
Object jobInstance = super.createJobInstance(bundle);
//进行注入
capableBeanFactory.autowireBean(jobInstance);
return jobInstance;
}
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) {
try {
final Object job = super.createJobInstance(bundle);
beanFactory.autowireBean(job);
return job;
} catch (Exception e) {
LOGGER.error("fail to create job instance. {}", e);
}
return null;
}
@Override
protected Object createJobInstance(TriggerFiredBundle bundle)
throws Exception {
Object job = super.createJobInstance(bundle);
if(job instanceof ApplicationContextAware)
{
((ApplicationContextAware)job).setApplicationContext(context);
}
return job;
}