You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Daniel Henze <dh...@googlemail.com> on 2010/07/12 22:20:31 UTC

Quartz Job setup with JobDetails requires parameter free constructor - how to inject Service bindings

Hi there,

I am using chenillekit-quartz integration and followed the example setup 
on the module homepage 
(http://chenillekit.codehaus.org/chenillekit-quartz/index.html). All 
good so far, got things up and running. But now I want to run a job that 
has other services (DAO, MailService) as dependencies. Setup is done via 
JobDetails class which uses a parameter free constructor to instantiate 
the implementation of an Interface:

new JobDetail("MailSenderJob", null, MailSenderJob.class)

I tried binding that clas (MailSenderJob) with build method in 
Application module and @Inject annotation, but nothing did work, always 
getting a NullpointerException when it comes to that service. I also 
could not find a JobDetail constructor that allows for setting 
dependencies, but no luck.

How can I get the service dependencies in MailSenderJob set up since 
Quartz does only use default constructor?

Thankful for any hints
Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Quartz Job setup with JobDetails requires parameter free constructor - how to inject Service bindings

Posted by Alfie Kirkpatrick <Al...@ioko.com>.
It's still a WIP but I created a TapestryJobCreator which gets a PerthreadManager and a Runnable (your service) in the JobDataMap. This just calls run() on the service and does any cleanup. I need to tidy up the job creation part but you could easily get to the point where you had something like:

	public static void contributeSchedulerService(Configuration<JobInfo> config, MyService service) {
		config.add(new JobInfo("0 0/30 * * * ?", service));
	}

(where MyService implements Runnable and JobInfo is just a simple DTO)

Here is the TapestryJobCreator...

public class TapestryJobCreator implements Job {
	private static final Logger logger=LoggerFactory.getLogger(TapestryJobCreator.class);
	
	public void execute(JobExecutionContext context)
			throws JobExecutionException {

		logger.info("Executing job");
		
		PerthreadManager perthreadManager = (PerthreadManager) context
				.getJobDetail().getJobDataMap().get("perThreadManager");

		Runnable runner = (Runnable) context
			.getJobDetail().getJobDataMap().get("runner");

		try {
			runner.run();
		} finally {
			logger.info("Doing cleanup");
			perthreadManager.cleanup();
		}
	}
}

Hope it helps,
Alfie.

-----Original Message-----
From: Daniel Henze [mailto:dhenze@googlemail.com] 
Sent: 12 July 2010 21:21
To: Tapestry users
Subject: Quartz Job setup with JobDetails requires parameter free constructor - how to inject Service bindings

Hi there,

I am using chenillekit-quartz integration and followed the example setup 
on the module homepage 
(http://chenillekit.codehaus.org/chenillekit-quartz/index.html). All 
good so far, got things up and running. But now I want to run a job that 
has other services (DAO, MailService) as dependencies. Setup is done via 
JobDetails class which uses a parameter free constructor to instantiate 
the implementation of an Interface:

new JobDetail("MailSenderJob", null, MailSenderJob.class)

I tried binding that clas (MailSenderJob) with build method in 
Application module and @Inject annotation, but nothing did work, always 
getting a NullpointerException when it comes to that service. I also 
could not find a JobDetail constructor that allows for setting 
dependencies, but no luck.

How can I get the service dependencies in MailSenderJob set up since 
Quartz does only use default constructor?

Thankful for any hints
Daniel


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Quartz Job setup with JobDetails requires parameter free constructor - how to inject Service bindings

Posted by Kalle Korhonen <ka...@gmail.com>.
You create a JobSchedulingBundle (service), create a JobDataMap in it,
add all the services to the map you need in your Job and then then get
the map via executionContext.getMergedJobDataMap(). The concept behind
JobDataMap is solid but you could arguably make a tighter and
easier-to-use Tapestry-specific integration for Quartz. I'd love to be
able to do just:
configuration.add("0 0 0 * * ?", myJob);

But I'm too lazy/busy to work on it myself since even the current
Chenillekit-provided integration works fine with the expense of a few
redundant lines of code.

Kalle


make On Mon, Jul 12, 2010 at 1:20 PM, Daniel Henze
<dh...@googlemail.com> wrote:
> Hi there,
>
> I am using chenillekit-quartz integration and followed the example setup on
> the module homepage
> (http://chenillekit.codehaus.org/chenillekit-quartz/index.html). All good so
> far, got things up and running. But now I want to run a job that has other
> services (DAO, MailService) as dependencies. Setup is done via JobDetails
> class which uses a parameter free constructor to instantiate the
> implementation of an Interface:
>
> new JobDetail("MailSenderJob", null, MailSenderJob.class)
>
> I tried binding that clas (MailSenderJob) with build method in Application
> module and @Inject annotation, but nothing did work, always getting a
> NullpointerException when it comes to that service. I also could not find a
> JobDetail constructor that allows for setting dependencies, but no luck.
>
> How can I get the service dependencies in MailSenderJob set up since Quartz
> does only use default constructor?
>
> Thankful for any hints
> Daniel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org