2016/02/07 - Apache Onami has been retired.

For more information, please explore the Attic.

User's guide

The org.apache.onami.scheduler.QuartzModule makes easier the org.quartz.Scheduler creation and org.quartz.Job creation and scheduling.

Scheduler

Once the Guice Injector will be created using the org.apache.onami.scheduler.QuartzModule, the org.quartz.Scheduler will be ready and started. Users can require the org.quartz.Scheduler injection for custom operations and for shutdown it.

public class MyApplicationShutdownListener
{

    @Inject
    private org.quartz.Scheduler scheduler;

    public void shutdown()
        throws Exception
    {
        ...
        scheduler.shutdown();
        ...
    }

}

Users that need to register listeners, can us the org.apache.onami.scheduler.QuartzModule EDSL:

Guice.createInjector(..., new org.apache.onami.scheduler.QuartzModule()
{

   @Override
   protected void schedule()
   {
       addJobListener( com.acme.MyJobListener.class );
       addTriggerListener( com.acme.MyTriggerListener.class );
       addSchedulerListener( com.acme.MySchedulerListener.class );
   }

});

Don't create listeners instances manually, let Guice do the job for you!

Job

org.quartz.Job instances and scheduling are managed as well, a typical example of scheduling org.quartz.Job is:

Guice.createInjector(..., new org.apache.onami.scheduler.QuartzModule()
{

   @Override
   protected void schedule()
   {
       ...
       scheduleJob( com.acme.MyJobImpl.class ).withCronExpression( "0/2 * * * * ?" );
       ...
   }

});

Don't create jobs instances manually, let Guice do the job for you!

Please refer to JobSchedulerBuilder Javadoc to see all the scheduling configuration parameters.

Implicit scheduling

Job classes annotated with org.apache.onami.scheduler.Scheduled will be automatically scheduled extracting configuration parameters, i.e. given the :

@javax.inject.Singleton
@org.apache.onami.scheduler.Scheduled( jobName = "test", cronExpression = "0/2 * * * * ?" )
public class com.acme.MyJobImpl
    implements org.quartz.Job
{

    @javax.inject.Inject
    private MyCustomService service;

    public void execute( JobExecutionContext context )
        throws JobExecutionException
    {
        service.customOperation();
    }

}

Then, when creating the Injector instance:

Guice.createInjector(..., new org.apache.onami.scheduler.QuartzModule()
{

   @Override
   protected void schedule()
   {
       ...
       scheduleJob( com.acme.MyJobImpl.class );
       ...
   }

});

Starting the schedule manually

Since version 1.1 the Scheduler instance can be started manually; that feature is incredibly useful due to serious deadlock issue found in the main Guice thread:

Guice.createInjector(..., new org.apache.onami.scheduler.QuartzModule()
{

   @Override
   protected void schedule()
   {
       ...
       configureScheduler().withManualStart();
       ...
   }

});

So users have to get the Scheduler instance and invoke the start explicitly.

Simple enough, uh?