public void programmaticTimeout() { logger.info("TimerEJB: programmatic timeout occurred"); timeoutDone = false; long duration = 60; Timer timer = timerService.createSingleActionTimer(duration, new TimerConfig()); timer.getInfo(); try { timer.getSchedule(); } catch (IllegalStateException e) { logger.log(SEVERE, "it is not a scheduler", e); } TimerHandle timerHandle = timer.getHandle(); timerHandle.getTimer(); timer.isCalendarTimer(); timer.isPersistent(); timer.getTimeRemaining(); }
public Job createJob(Job job) throws JobAlreadyExistsException { if (job.getId() != null && em.find(Job.class, job.getId()) != null) { throw new JobAlreadyExistsException(); } ScheduleExpression schedule = new ScheduleExpression(); schedule.second(job.getSecond()); schedule.minute(job.getMinute()); schedule.hour(job.getHour()); schedule.dayOfMonth(job.getDayOfMonth()); schedule.dayOfWeek(job.getDayOfWeek()); schedule.month(job.getMonth()); schedule.year(job.getYear()); TimerConfig timerConfig = new TimerConfig(job.getId(), true); Timer timer = timerService.createCalendarTimer(schedule, timerConfig); TimerHandle timerHandle = timer.getHandle(); job.serialize(timerHandle); logger.info("Timer {} created with cron expression {}. The next timeout is {}.", job.getId(), job.getCronExpression(), timer.getNextTimeout()); if (job.getId() != null) { em.merge(job); } else { em.persist(job); } return job; }
public void removeJob(long jobId) { Job job = em.find(Job.class, jobId); if (job != null) { em.remove(job); TimerHandle timerHandle = job.geTimerHandle(); if (timerHandle != null) { timerHandle.getTimer().cancel(); } } else { logger.info("Job with id {} not found. Cancelling...", jobId); } }
public void serialize(TimerHandle timerHandle) { try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(timerHandle); stream.flush(); this.timerHandle = new SerialBlob(bytes.toByteArray()); } catch (SQLException | IOException e) { throw new RuntimeException(e); } }
public TimerHandle geTimerHandle() { try { if (timerHandle == null) return null; ObjectInputStream input = new ObjectInputStream(timerHandle.getBinaryStream()); return (TimerHandle) input.readObject(); } catch (ClassNotFoundException | SQLException | IOException e) { throw new RuntimeException(e); } }
public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException { checkState(); if (!timerData.isPersistent()) { throw new IllegalStateException("can't getHandle for a non-persistent timer"); } return new TimerHandleImpl(timerData.getId(), timerData.getDeploymentId()); }
@Override public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException, EJBException { throw new UnsupportedOperationException(); }
@Override public TimerHandle getHandle() throws EJBException, IllegalStateException, NoSuchObjectLocalException { return null; }
@Override public TimerHandle getHandle() throws IllegalStateException, EJBException { return null; }
@Override public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException, EJBException { return handle; }