Author |
Message |
02/02/2010 05:13:14
|
stevecoh
journeyman
Joined: 01/27/2010 09:34:13
Messages: 27
Offline
|
I'm writing a JUnit test for a task I'm developing. I want the task to execute immediately and then I test various assertions. To that end, rather than wait for some arbitrary length of time for the task to complete, I thought I'd try waiting on the job to complete with a JobListener.
To that end, I created an implementation of JobListener and called it right before manually triggering the job:
Code:
JobDetail detail = scheduler.getJobDetail(jobname, groupname);
JobDoneListener listener = new JobDoneListener (detail);
scheduler.addJobListener(listener);
scheduler.triggerJob(jobname, groupname);
At the completion of the job I expect my listener's jobWasExecuted() method to fire. It does not. But if I change the third line above to
Code:
scheduler.addGlobalJobListener(listener);
then it does fire. This solves my problem but I'd still like to understand what's going on. What is the use case for non-global JobListeners as opposed to globals and how do you code one so it fires?
|
|
|
02/02/2010 07:36:16
|
jhouse
seraphim
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline
|
Non-global listeners have to be explicitly referenced by a job for them to be notified.
e.g.
JobDetail.addJobListener(myListenersName);
|
|
|
02/02/2010 07:44:33
|
stevecoh
journeyman
Joined: 01/27/2010 09:34:13
Messages: 27
Offline
|
Okay but what's the purpose, then, of Scheduler.addJobListener()? Does it do anything?
|
|
|
02/02/2010 07:54:24
|
jhouse
seraphim
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline
|
Yes, it gives the scheduler a handle to the listener, so that it can invoke it when the job runs.
The job only identifies the name of the non-global listener(s) that it explicitly wants to have invoked.
The scheduler then needs to have a handle to the listeners created by your application, so that it can invoke them.
|
|
|
02/02/2010 07:57:09
|
stevecoh
journeyman
Joined: 01/27/2010 09:34:13
Messages: 27
Offline
|
My head is spinning. Is there a code sample somewhere?
|
|
|
02/02/2010 08:36:48
|
QrtzHelp
journeyman
Joined: 01/16/2010 09:44:00
Messages: 37
Offline
|
Look at Example 9.
|
|
|
02/02/2010 11:58:12
|
stevecoh
journeyman
Joined: 01/27/2010 09:34:13
Messages: 27
Offline
|
Thanks, that helps. So it looks as though a non-global Job Listener must be "added" to both the scheduler and the job, to the scheduler "by value" and to the job "by reference". In my simple use case I have no need of this and the global JobListener is fine.
What would be an example of a use case where the Local listener is needed?
|
|
|
02/02/2010 13:23:07
|
QrtzHelp
journeyman
Joined: 01/16/2010 09:44:00
Messages: 37
Offline
|
When you want the listener only to be notified of particular jobs.
|
|
|
|