1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
56
56
* <b>Note:</b> Quartz 1.x support is deprecated - please upgrade to Quartz 2.0+.
57
57
*
58
58
* @author Juergen Hoeller
59
+ * @author Stephane Nicoll
59
60
* @since 2.5.6
60
61
*/
61
62
public abstract class SchedulerAccessor implements ResourceLoaderAware {
@@ -395,7 +396,8 @@ private JobDetail findJobDetail(Trigger trigger) {
395
396
}
396
397
else {
397
398
try {
398
- Map <?, ?> jobDataMap = (Map <?, ?>) ReflectionUtils .invokeMethod (Trigger .class .getMethod ("getJobDataMap" ), trigger );
399
+ Map <?, ?> jobDataMap =
400
+ (Map <?, ?>) ReflectionUtils .invokeMethod (Trigger .class .getMethod ("getJobDataMap" ), trigger );
399
401
return (JobDetail ) jobDataMap .remove (JobDetailAwareTrigger .JOB_DETAIL_KEY );
400
402
}
401
403
catch (NoSuchMethodException ex ) {
@@ -472,19 +474,33 @@ protected void registerListeners() throws SchedulerException {
472
474
target = getScheduler ();
473
475
quartz2 = false ;
474
476
}
477
+ Class <?> targetClass = target .getClass ();
475
478
476
479
try {
477
480
if (this .schedulerListeners != null ) {
478
- Method addSchedulerListener = target . getClass () .getMethod ("addSchedulerListener" , SchedulerListener .class );
481
+ Method addSchedulerListener = targetClass .getMethod ("addSchedulerListener" , SchedulerListener .class );
479
482
for (SchedulerListener listener : this .schedulerListeners ) {
480
483
ReflectionUtils .invokeMethod (addSchedulerListener , target , listener );
481
484
}
482
485
}
483
486
if (this .globalJobListeners != null ) {
484
- Method addJobListener = target .getClass ().getMethod (
485
- (quartz2 ? "addJobListener" : "addGlobalJobListener" ), JobListener .class );
487
+ Method addJobListener ;
488
+ if (quartz2 ) {
489
+ // addJobListener(JobListener) only introduced as late as Quartz 2.2, so we need
490
+ // to fall back to the Quartz 2.0/2.1 compatible variant with an empty matchers List
491
+ addJobListener = targetClass .getMethod ("addJobListener" , JobListener .class , List .class );
492
+ }
493
+ else {
494
+ addJobListener = targetClass .getMethod ("addGlobalJobListener" , JobListener .class );
495
+ }
486
496
for (JobListener listener : this .globalJobListeners ) {
487
- ReflectionUtils .invokeMethod (addJobListener , target , listener );
497
+ if (quartz2 ) {
498
+ List <?> emptyMatchers = new LinkedList <Object >();
499
+ ReflectionUtils .invokeMethod (addJobListener , target , listener , emptyMatchers );
500
+ }
501
+ else {
502
+ ReflectionUtils .invokeMethod (addJobListener , target , listener );
503
+ }
488
504
}
489
505
}
490
506
if (this .jobListeners != null ) {
@@ -497,10 +513,23 @@ protected void registerListeners() throws SchedulerException {
497
513
}
498
514
}
499
515
if (this .globalTriggerListeners != null ) {
500
- Method addTriggerListener = target .getClass ().getMethod (
501
- (quartz2 ? "addTriggerListener" : "addGlobalTriggerListener" ), TriggerListener .class );
516
+ Method addTriggerListener ;
517
+ if (quartz2 ) {
518
+ // addTriggerListener(TriggerListener) only introduced as late as Quartz 2.2, so we need
519
+ // to fall back to the Quartz 2.0/2.1 compatible variant with an empty matchers List
520
+ addTriggerListener = targetClass .getMethod ("addTriggerListener" , TriggerListener .class , List .class );
521
+ }
522
+ else {
523
+ addTriggerListener = targetClass .getMethod ("addGlobalTriggerListener" , TriggerListener .class );
524
+ }
502
525
for (TriggerListener listener : this .globalTriggerListeners ) {
503
- ReflectionUtils .invokeMethod (addTriggerListener , target , listener );
526
+ if (quartz2 ) {
527
+ List <?> emptyMatchers = new LinkedList <Object >();
528
+ ReflectionUtils .invokeMethod (addTriggerListener , target , listener , emptyMatchers );
529
+ }
530
+ else {
531
+ ReflectionUtils .invokeMethod (addTriggerListener , target , listener );
532
+ }
504
533
}
505
534
}
506
535
if (this .triggerListeners != null ) {
0 commit comments