TimerServiceImplpublic class TimerServiceImpl extends Object implements javax.ejb.TimerServiceImplements the EJB3 Timer Service specification (EJB3 chapter 18).
Each bean container has its own job and trigger group. |
Fields Summary |
---|
private static final Logger | log | private org.quartz.Scheduler | scheduler | private ObjectName | objectName | private String | groupName | private long | jobNum | private long | triggerNum |
Methods Summary |
---|
protected javax.ejb.Timer | createTimer(org.quartz.Trigger trigger, java.io.Serializable info)
try {
String name = "myJob" + jobNum;
jobNum++;
Class jobClass = QuartzTimerJob.class;
Timer timer = new TimerImpl(scheduler, trigger, info);
PersistentTimer persistentTimer = new PersistentTimer(trigger, objectName, info);
JobDetail jobDetail = new JobDetail(name, groupName, jobClass);
jobDetail.getJobDataMap().put("timer", persistentTimer);
scheduler.scheduleJob(jobDetail, trigger);
return timer;
}
catch(SchedulerException e) {
// translate the exception, because the client might not have quartz
log.error("createTimer failed", e);
throw new EJBException(e.getMessage());
}
| public javax.ejb.Timer | createTimer(long duration, java.io.Serializable info)Create a single-action timer that expires after a specified duration.
if(duration < 0) throw new IllegalArgumentException("duration must not be negative");
// TODO: check state
Date expiration = new Date(System.currentTimeMillis() + duration);
return createTimer(expiration, info);
| public javax.ejb.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.
if(initialDuration < 0) throw new IllegalArgumentException("initialDuration must not be negative");
if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
// TODO: check state
Date initialExpiration = new Date(System.currentTimeMillis() + initialDuration);
return createTimer(initialExpiration, intervalDuration, info);
| public javax.ejb.Timer | createTimer(java.util.Date expiration, java.io.Serializable info)Create a single-action timer that expires at a given point in time.
if(expiration == null) throw new IllegalArgumentException("expiration must not be null");
if(expiration.getTime() < 0) throw new IllegalArgumentException("expiration.time must not be negative");
// TODO: check state
String triggerName = "myTrigger" + triggerNum;
triggerNum++;
Trigger trigger = new SimpleTrigger(triggerName, groupName, expiration);
return createTimer(trigger, info);
| public javax.ejb.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.
if(initialExpiration == null) throw new IllegalArgumentException("initialExpiration must not be null");
if(initialExpiration.getTime() < 0) throw new IllegalArgumentException("initialExpiration.time must not be negative");
if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
// TODO: check state
String triggerName = "myTrigger" + triggerNum;
triggerNum++;
Date endTime = null;
Trigger trigger = new SimpleTrigger(triggerName, groupName, initialExpiration, endTime, SimpleTrigger.REPEAT_INDEFINITELY, intervalDuration);
return createTimer(trigger, info);
| protected org.quartz.Scheduler | getScheduler()
return scheduler;
| public java.util.Collection | getTimers()Get all the active timers associated with this bean.
throw new RuntimeException("NYI");
| protected void | shutdown()
log.debug("shutting down " + this);
try
{
String triggerNames[] = scheduler.getTriggerNames(groupName);
for(String triggerName : triggerNames)
scheduler.unscheduleJob(triggerName, groupName);
String jobNames[] = scheduler.getJobNames(groupName);
for(String jobName : jobNames)
scheduler.deleteJob(jobName, groupName);
}
catch(SchedulerException e)
{
log.error("shutdown failed", e);
// TODO: ignore?
}
| public java.lang.String | toString()
return "Timer Service " + objectName;
|
|