[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]
Global vs Local Job Triggers  XML
Forum Index -> Quartz
Author Message
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?
jhouse

seraphim
[Avatar]
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);

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?
jhouse

seraphim
[Avatar]
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.
stevecoh

journeyman

Joined: 01/27/2010 09:34:13
Messages: 27
Offline

My head is spinning. Is there a code sample somewhere?
QrtzHelp

journeyman

Joined: 01/16/2010 09:44:00
Messages: 37
Offline


Look at Example 9.
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?
QrtzHelp

journeyman

Joined: 01/16/2010 09:44:00
Messages: 37
Offline


When you want the listener only to be notified of particular jobs.
 
Forum Index -> Quartz
Go to:   
Powered by JForum 2.1.7 © JForum Team