[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
JobListener doesn't get added right when two triggers registered.  XML
Forum Index -> Quartz
Author Message
Creature

neo

Joined: 12/16/2009 06:27:32
Messages: 1
Offline

Hi, all! I'm having a weird thing happen where if I assign 2 triggers to a job, it doesn't hit the listener I assign to the job. In fact, when I debug the program and look at all the set variables, just when I assign the "now" trigger I can see the listener in the JobListeners array of the job detail, but inside of the execute method for that job, the jobListeners array is empty. Basically what I need is two triggers, 1 is a cron trigger who's job is to tell me whether or not the job's scheduled for today (don't care about the time). If the job is scheduled for today, it will be executed by another process once that process completes by creating a "now" trigger and assigning it to the job.

Here's the test classes I wrote to duplicate the error on the small scale:

Am I doing something wrong or is this a bug?

// the main class
Code:
 // this method gets called by main (nothing else happens in main)
 public static void schedule() throws SchedulerException, ParseException, InterruptedException
     {
         SchedulerFactory sf = new StdSchedulerFactory();
         Scheduler sched = sf.getScheduler();
 
         sched.start();
 
         JobDetail job = new JobDetail("job1", sched.DEFAULT_GROUP, TestJob.class);
 
         SimpleTrigger trigger = new SimpleTrigger("trigger1", "regularTrigger");//, new Date(), null, 3, 3000);
 
         CronTrigger cronTrigger = new CronTrigger("trigger2", "chronTrigger", "0 08 15 * * ?");
         sched.scheduleJob(job, cronTrigger);
 
         trigger.setJobName("job1");
         trigger.setJobGroup(sched.DEFAULT_GROUP);
         
         sched.addJobListener(new TestJobListener());
         job.addJobListener("TestJobListener_name");
 
         sched.scheduleJob(trigger);
 
     }// end schedule()
 


// the job's class:
Code:
 public class TestJob implements Job
 {
 
     @Override
     public void execute(JobExecutionContext arg0) throws JobExecutionException
     {
         System.out.println("Job executed: " + new Date());
 
     }// end execute(.)
 
 }// end class Job
 


the job listener:
Code:
public class TestJobListener implements JobListener
 {
     @Override
     public void jobWasExecuted(JobExecutionContext jobContext,
             JobExecutionException jobException)
     {
         System.out.println("!!!!!Job was executed");
     }
 
     @Override
     public String getName()
     {
         return "TestJobListener_name";
     }
 
     @Override
     public void jobToBeExecuted(JobExecutionContext jec)
     {
         System.out.println("!!Job is about to be executed");
     }
 
     @Override
     public void jobExecutionVetoed(JobExecutionContext jec)
     {
         System.out.println("!!!!    JOB EXECUTION VETOED !!!!");
     }
 
 }// end class TestJobListener
 


Output (snipped the scheduler initialized loggin):
Code:
 Job executed: Wed Dec 16 08:45:05 CST 2009 


As you can see there is no vetoed, about to be executed, or has been executed system out printlines.

schedule initialization log I snipped earlier (I don't know if it matters):
Code:
 log4j: Parsing for [root] with value=[debug,CONSOLE].
 log4j: Level token is [debug].
 log4j: Category root set to DEBUG
 log4j: Parsing appender named "CONSOLE".
 log4j: Parsing layout options for "CONSOLE".
 log4j: Setting property [conversionPattern] to [[%p] - %m%n].
 log4j: End of parsing for "CONSOLE".
 log4j: Parsed "CONSOLE" options.
 log4j: Parsing for [com.crystaldecisions] with value=[FATAL].
 log4j: Level token is [FATAL].
 log4j: Category com.crystaldecisions set to FATAL
 log4j: Handling log4j.additivity.com.crystaldecisions=[null]
 log4j: Parsing for [org.quartz] with value=[WARN].
 log4j: Level token is [WARN].
 log4j: Category org.quartz set to WARN
 log4j: Handling log4j.additivity.org.quartz=[null]
 log4j: Parsing for [bbec] with value=[ALL,BBEC_FILE,CONSOLE].
 log4j: Level token is [ALL].
 log4j: Category bbec set to ALL
 log4j: Parsing appender named "BBEC_FILE".
 log4j: Parsing layout options for "BBEC_FILE".
 log4j: Setting property [conversionPattern] to [%d{HH:mm:ss,SSS} [%p] - %m%n].
 log4j: End of parsing for "BBEC_FILE".
 log4j: Setting property [threshold] to [DEBUG].
 log4j: Setting property [suffix] to [.log].
 log4j: Setting property [directory] to [/log/BBEC_LOG].
 log4j: Setting property [append] to [true].
 log4j: Setting property [prefix] to [BBEC_RESULT_LOG.].
 log4j: Parsed "BBEC_FILE" options.
 log4j: Parsing appender named "CONSOLE".
 log4j: Appender "CONSOLE" was already parsed.
 log4j: Handling log4j.additivity.bbec=[false]
 log4j: Setting additivity for "bbec" to false
 log4j: Parsing for [com.rcody.Logging.Logging] with value=[INFO].
 log4j: Level token is [INFO].
 log4j: Category com.rcody.Logging.Logging set to INFO
 log4j: Handling log4j.additivity.com.rcody.Logging.Logging=[null]
 log4j: Parsing for [com.rcody.RuffaloNetworking.networking] with value=[ALL,BBEC_FILE,CONSOLE].
 log4j: Level token is [ALL].
 log4j: Category com.rcody.RuffaloNetworking.networking set to ALL
 log4j: Parsing appender named "BBEC_FILE".
 log4j: Appender "BBEC_FILE" was already parsed.
 log4j: Parsing appender named "CONSOLE".
 log4j: Appender "CONSOLE" was already parsed.
 log4j: Handling log4j.additivity.com.rcody.RuffaloNetworking.networking=[false;]
 log4j: Setting additivity for "com.rcody.RuffaloNetworking.networking" to true
 log4j: Finished configuring.
jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline


You are storing the job before adding the listener to it, hence the copy that is retrieved from storage has no listener on it. (You are adding the listener to your copy of the job, not the scheduler's copy).
 
Forum Index -> Quartz
Go to:   
Powered by JForum 2.1.7 © JForum Team