@Override public void executeEvent(final CatchingEventUUID eventUUID) throws EventNotFoundException { final EventService eventService = EnvTool.getEventService(); final long id = Long.parseLong(eventUUID.getValue()); final Job job = eventService.getJob(id); if (EventConstants.TIMER.equals(job.getEventType())) { updateExpirationDate(job, new Date()); } }
@Override public void updateExpirationDate(final CatchingEventUUID eventUUID, final Date expiration) throws EventNotFoundException { final EventService eventService = EnvTool.getEventService(); final long id = Long.parseLong(eventUUID.getValue()); final Job job = eventService.getJob(id); if (job == null) { throw new EventNotFoundException("Event " + id + "does not exist."); } updateExpirationDate(job, expiration); }
@Override public CatchingEvent getEvent(final CatchingEventUUID eventUUID) throws EventNotFoundException { final EventService eventService = EnvTool.getEventService(); final long jobId = Long.parseLong(eventUUID.getValue()); final Job job = eventService.getJob(jobId); if (job == null) { throw new EventNotFoundException("Event " + jobId + "does not exist."); } return getEvent(job); }
@Override public void deleteEvent(final CatchingEventUUID eventUUID) throws EventNotFoundException { final EventService eventService = EnvTool.getEventService(); final long id = Long.parseLong(eventUUID.getValue()); final Job job = eventService.getJob(id); if (job == null) { throw new EventNotFoundException("Event " + id + "does not exist."); } eventService.removeJob(job); EnvTool.getEventExecutor().refreshEventMatcher(); }
@Override public String execute(final Environment environment) throws Exception { // serialize the stack trace final StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); final Job job = EnvTool.getEventService().getJob(jobId); if (job.getExecutionUUID() != null) { final Execution execution = EnvTool.getJournal().getExecutionWithEventUUID(job.getExecutionUUID()); if (execution != null) { if (!Execution.STATE_ACTIVE.equals(execution.getState())) { execution.unlock(); } execution.lock(execution.getState()); } } final int decrementedRetries = job.getRetries() - 1; if (LOG.isLoggable(Level.INFO)) { LOG.info("Decrementing retries on job: " + job + ": " + decrementedRetries); } job.setRetries(decrementedRetries); job.setException(sw.toString()); return job.getProcessUUID(); }