org.objectweb.easybeans.component.quartz
Class QuartzTimerService

java.lang.Object
  extended by org.objectweb.easybeans.component.quartz.QuartzTimerService
All Implemented Interfaces:
TimerService

public class QuartzTimerService
extends java.lang.Object
implements TimerService

Implementation of the EJB Timer service that is based on the Quartz framework.

Author:
Florent Benoit

Field Summary
private  Factory factory
          An EJB Timer service is linked to an EasyBeans factory.
private  long jobDetailId
          JobDetail id.
private  org.quartz.Scheduler scheduler
          The timer service is also linked to a Quartz scheduler.
private  java.lang.String triggerGroupName
          Name of the group for triggers.
private  long triggerId
          Trigger name ID.
 
Constructor Summary
QuartzTimerService(Factory factory, org.quartz.Scheduler scheduler)
          Build a new instance of the EJB Timer service for the given factory and the given scheduler.
 
Method Summary
 Timer createTimer(java.util.Date initialExpiration, long intervalDuration, java.io.Serializable info)
          Create an interval timer whose first expiration occurs at a given point in time and whose subsequent expirations occur after a specified interval.
 Timer createTimer(java.util.Date expiration, java.io.Serializable info)
          Create a single-action timer that expires at a given point in time.
 Timer createTimer(long initialDuration, long intervalDuration, java.io.Serializable info)
          Create an interval timer whose first expiration occurs after a specified duration, and whose subsequent expirations occur after a specified interval.
 Timer createTimer(long duration, java.io.Serializable info)
          Create a single-action timer that expires after a specified duration.
private  java.lang.String getJobDetailGroupName()
          Get the group name for each job detail.
private  java.lang.String getNewJobDetailName()
          Get an unique identifier for a JobDetail name.
 org.quartz.Scheduler getScheduler()
          Gets the Scheduler.
 java.util.Collection getTimers()
          Get all the active timers associated with this bean.
private  java.lang.String getTriggerGroupName()
          Get the group name for each Trigger.
private  java.lang.String getTriggerName()
          Get an unique identifier for a Trigger name.
private  Timer internalTimer(org.quartz.Trigger trigger, java.io.Serializable info)
          Create a timer object that is sent to the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

private Factory factory
An EJB Timer service is linked to an EasyBeans factory.


scheduler

private org.quartz.Scheduler scheduler
The timer service is also linked to a Quartz scheduler.


triggerGroupName

private java.lang.String triggerGroupName
Name of the group for triggers.


triggerId

private long triggerId
Trigger name ID.


jobDetailId

private long jobDetailId
JobDetail id.

Constructor Detail

QuartzTimerService

public QuartzTimerService(Factory factory,
                          org.quartz.Scheduler scheduler)
Build a new instance of the EJB Timer service for the given factory and the given scheduler.

Parameters:
factory - the given factory
scheduler - the given scheduler
Method Detail

createTimer

public Timer createTimer(long duration,
                         java.io.Serializable info)
                  throws java.lang.IllegalArgumentException,
                         java.lang.IllegalStateException,
                         EJBException
Create a single-action timer that expires after a specified duration.

Specified by:
createTimer in interface TimerService
Parameters:
duration - The number of milliseconds that must elapse before the timer expires.
info - Application information to be delivered along with the timer expiration notification. This can be null.
Returns:
The newly created Timer.
Throws:
java.lang.IllegalArgumentException - If duration is negative
java.lang.IllegalStateException - If this method is invoked while the instance is in a state that does not allow access to this method.
EJBException - If this method fails due to a system-level failure.

createTimer

public Timer createTimer(long initialDuration,
                         long intervalDuration,
                         java.io.Serializable info)
                  throws java.lang.IllegalArgumentException,
                         java.lang.IllegalStateException,
                         EJBException
Create an interval timer whose first expiration occurs after a specified duration, and whose subsequent expirations occur after a specified interval.

Specified by:
createTimer in interface TimerService
Parameters:
initialDuration - The number of milliseconds that must elapse before the first timer expiration notification.
intervalDuration - The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
info - Application information to be delivered along with the timer expiration. This can be null.
Returns:
The newly created Timer.
Throws:
java.lang.IllegalArgumentException - If initialDuration is negative, or intervalDuration is negative.
java.lang.IllegalStateException - If this method is invoked while the instance is in a state that does not allow access to this method.
EJBException - If this method could not complete due to a system-level failure.

createTimer

public Timer createTimer(java.util.Date expiration,
                         java.io.Serializable info)
                  throws java.lang.IllegalArgumentException,
                         java.lang.IllegalStateException,
                         EJBException
Create a single-action timer that expires at a given point in time.

Specified by:
createTimer in interface TimerService
Parameters:
expiration - The point in time at which the timer must expire.
info - Application information to be delivered along with the timer expiration notification. This can be null.
Returns:
The newly created Timer.
Throws:
java.lang.IllegalArgumentException - If expiration is null, or expiration.getTime() is negative.
java.lang.IllegalStateException - If this method is invoked while the instance is in a state that does not allow access to this method.
EJBException - If this method could not complete due to a system-level failure.

createTimer

public Timer createTimer(java.util.Date initialExpiration,
                         long intervalDuration,
                         java.io.Serializable info)
                  throws java.lang.IllegalArgumentException,
                         java.lang.IllegalStateException,
                         EJBException
Create an interval timer whose first expiration occurs at a given point in time and whose subsequent expirations occur after a specified interval.

Specified by:
createTimer in interface TimerService
Parameters:
initialExpiration - The point in time at which the first timer expiration must occur.
intervalDuration - The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
info - Application information to be delivered along with the timer expiration. This can be null.
Returns:
The newly created Timer.
Throws:
java.lang.IllegalArgumentException - If initialExpiration is null, or initialExpiration.getTime() is negative, or intervalDuration is negative.
java.lang.IllegalStateException - If this method is invoked while the instance is in a state that does not allow access to this method.
EJBException - If this method could not complete due to a system-level failure.

internalTimer

private Timer internalTimer(org.quartz.Trigger trigger,
                            java.io.Serializable info)
Create a timer object that is sent to the client. Also, create a new job and send it to the Quartz Scheduler.

Parameters:
trigger - the object containing the data for the scheduling.
info - the optional serializable object given by the developer.
Returns:
a Timer object.

getTimers

public java.util.Collection getTimers()
                               throws java.lang.IllegalStateException,
                                      EJBException
Get all the active timers associated with this bean.

Specified by:
getTimers in interface TimerService
Returns:
A collection of javax.ejb.Timer objects.
Throws:
java.lang.IllegalStateException - If this method is invoked while the instance is in a state that does not allow access to this method.
EJBException - If this method could not complete due to a system-level failure.

getTriggerName

private java.lang.String getTriggerName()
Get an unique identifier for a Trigger name.

Returns:
a new trigger name

getNewJobDetailName

private java.lang.String getNewJobDetailName()
Get an unique identifier for a JobDetail name.

Returns:
a new job detail name

getTriggerGroupName

private java.lang.String getTriggerGroupName()
Get the group name for each Trigger.

Returns:
the group name

getJobDetailGroupName

private java.lang.String getJobDetailGroupName()
Get the group name for each job detail.

Returns:
the group name

getScheduler

public org.quartz.Scheduler getScheduler()
Gets the Scheduler.

Returns:
the scheduler.