protected void setString(final AutoTimer timer, final String value) { timer.getTimerConfig().setInfo(value); } },
@PostConstruct public void initialize() { ScheduleExpression scheduleExpression = new ScheduleExpression() .hour("*") .minute("*") .second("*/5"); TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo("Every 5 second timer"); timerService.createCalendarTimer(scheduleExpression, timerConfig); }
AutoTimer autoTimer = new AutoTimer(); autoTimer.getTimerConfig().setInfo(timer.getInfo()); autoTimer.getTimerConfig().setPersistent(timer.isPersistent());
protected void setString(final AutoTimer timer, final String value) { timer.getTimerConfig().setInfo(value); } },
private Timer createTimerInternal(long initialDuration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException { TimerConfig tc = new TimerConfig(); tc.setInfo(info); return createTimerInternal(initialDuration, intervalDuration, tc); }
private Timer createTimerInternal(long initialDuration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException { TimerConfig tc = new TimerConfig(); tc.setInfo(info); return createTimerInternal(initialDuration, intervalDuration, tc); }
private Timer createTimerInternal(Date initialExpiration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException { TimerConfig tc = new TimerConfig(); tc.setInfo(info); return createTimerInternal(initialExpiration, intervalDuration, tc); }
private Timer createTimerInternal(Date initialExpiration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException { TimerConfig tc = new TimerConfig(); tc.setInfo(info); return createTimerInternal(initialExpiration, intervalDuration, tc); }
/** * Schedule a job for regular execution. * <p/> * @param job * @param when The ScheduleExpression dictating when the job should be run. */ public void scheduleJobOnCalendar(Jobs job, ScheduleExpression when) { TimerConfig config = new TimerConfig(); config.setInfo(job.getId()); timerService.createCalendarTimer(when, config); }
/** * Schedule a job for a single execution, at the given date. * <p/> * @param job * @param when */ public void scheduleJobOnce(Jobs job, Date when) { TimerConfig config = new TimerConfig(); config.setInfo(job.getId()); timerService.createSingleActionTimer(when, config); }
import javax.annotation.Resource; import javax.ejb.Stateless; import javax.ejb.Timeout; import javax.ejb.Timer; import javax.ejb.TimerConfig; import javax.ejb.TimerService; @Stateless public class TimerBean { @Resource protected TimerService timerService; @Timeout public void timeoutHandler(Timer timer) { String name = timer.getInfo().toString(); System.out.println("Timer name=" + name); } public void startTimer(long initialExpiration, long interval, String name){ TimerConfig config = new TimerConfig(); config.setInfo(name); config.setPersistent(false); timerService.createIntervalTimer(initialExpiration, interval, config); } }
/** * {@inheritDoc} */ public void startTimer(String cronSchedule) throws InvalidCronExpressionException { LOG.debug("start document service's cleanup task timer"); if (null == cronSchedule || cronSchedule.isEmpty()) { // TODO: error message sufficient? or explode here?... LOG.error("No interval set for document service cleanup task!"); return; } // remove old timers cancelTimers(); TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(TIMER_ID); timerConfig.setPersistent(true); ScheduleExpression schedule = getScheduleExpression(cronSchedule); Timer timer; try { timer = this.timerService .createCalendarTimer(schedule, timerConfig); } catch (Exception e) { LOG.error("Exception while creating timer for document service " + "cleanup task: " + e.getMessage(), e); throw new InvalidCronExpressionException(e); } LOG.debug("created timer for document service cleanup task: next=" + timer.getNextTimeout().toString()); }
/** * {@inheritDoc} */ public void startTimerNow(TrustPointEntity trustPoint) { TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(trustPoint.getName()); timerConfig.setPersistent(false); Timer timer = this.timerService.createSingleActionTimer(1000 * 10, timerConfig); LOG.debug("created single action timer for trustpoint " + trustPoint.getName() + " at " + timer.getNextTimeout().toString()); }
public Timer createCalendarTimer(ScheduleExpression schedule) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, javax.ejb.EJBException { checkCreateTimerCallPermission(); checkScheduleExpression(schedule); TimerConfig tc = new TimerConfig(); tc.setInfo(null); return createTimerInternal(schedule, tc); }
config.setInfo(name); config.setPersistent(false); timerService.createIntervalTimer(initialExpiration, interval, config);
public Timer createCalendarTimer(ScheduleExpression schedule) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, javax.ejb.EJBException { checkCreateTimerCallPermission(); checkScheduleExpression(schedule); TimerConfig tc = new TimerConfig(); tc.setInfo(null); return createTimerInternal(schedule, tc); }
@Singleton @Startup public class LabbBean { @Resource protected TimerService timerService; @PostConstruct public void init() { //Init your timers from the data in the database here for (all your timers) { TimerConfig config = new TimerConfig(); config.setInfo("timer1"); config.setPersistent(false); ScheduleExpression schedule = new ScheduleExpression(); schedule.dayOfMonth(10); schedule.minute(2); timerService.createCalendarTimer(schedule, config); } } //method called when timeout occurs @Timeout public void timeoutHandler(Timer timer) { String name = timer.getInfo().toString(); System.out.println("Timer name=" + name); } }
public static void testCreate(String timerId, EJBContext context, String ownerId, Date initialExpiration, long intervalDuration, Serializable info) throws CreateException { TimerLocal timerLocal = getEJBTimerService().getTimerLocal(); EjbDescriptor ejbDesc = ((EJBContextImpl) context).getContainer().getEjbDescriptor(); long containerId = ejbDesc.getUniqueId(); long applicationId = ejbDesc.getApplication().getUniqueId(); Object timedObjectPrimaryKey = (context instanceof EntityContext) ? ((EntityContext)context).getPrimaryKey() : null; TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(info); timerLocal.createTimer(timerId, containerId, applicationId, ownerId, timedObjectPrimaryKey, initialExpiration, intervalDuration, null, timerConfig); return; }
private void addSchedulesToMethod(final MethodContext methodContext, final MethodScheduleInfo info) { if (methodContext == null) { return; } for (final ScheduleInfo scheduleInfo : info.schedules) { final ScheduleExpression expr = new ScheduleExpression(); expr.second(scheduleInfo.second == null ? "0" : scheduleInfo.second); expr.minute(scheduleInfo.minute == null ? "0" : scheduleInfo.minute); expr.hour(scheduleInfo.hour == null ? "0" : scheduleInfo.hour); expr.dayOfWeek(scheduleInfo.dayOfWeek == null ? "*" : scheduleInfo.dayOfWeek); expr.dayOfMonth(scheduleInfo.dayOfMonth == null ? "*" : scheduleInfo.dayOfMonth); expr.month(scheduleInfo.month == null ? "*" : scheduleInfo.month); expr.year(scheduleInfo.year == null ? "*" : scheduleInfo.year); expr.timezone(scheduleInfo.timezone); expr.start(scheduleInfo.start); expr.end(scheduleInfo.end); final TimerConfig config = new TimerConfig(); config.setInfo(scheduleInfo.info); config.setPersistent(scheduleInfo.persistent); methodContext.getSchedules().add(new ScheduleData(config, expr)); } }
private void addSchedulesToMethod(final MethodContext methodContext, final MethodScheduleInfo info) { if (methodContext == null) { return; } for (final ScheduleInfo scheduleInfo : info.schedules) { final ScheduleExpression expr = new ScheduleExpression(); expr.second(scheduleInfo.second == null ? "0" : scheduleInfo.second); expr.minute(scheduleInfo.minute == null ? "0" : scheduleInfo.minute); expr.hour(scheduleInfo.hour == null ? "0" : scheduleInfo.hour); expr.dayOfWeek(scheduleInfo.dayOfWeek == null ? "*" : scheduleInfo.dayOfWeek); expr.dayOfMonth(scheduleInfo.dayOfMonth == null ? "*" : scheduleInfo.dayOfMonth); expr.month(scheduleInfo.month == null ? "*" : scheduleInfo.month); expr.year(scheduleInfo.year == null ? "*" : scheduleInfo.year); expr.timezone(scheduleInfo.timezone); expr.start(scheduleInfo.start); expr.end(scheduleInfo.end); final TimerConfig config = new TimerConfig(); config.setInfo(scheduleInfo.info); config.setPersistent(scheduleInfo.persistent); methodContext.getSchedules().add(new ScheduleData(config, expr)); } }