public void stopBatch() {
    Collection<Timer> timer = timerservice.getTimers();

    for (Timer timer1 : timer) {
      timer1.cancel();
    }
  }
Esempio n. 2
0
 @Override
 public void remove(String id) {
   JobExecution jobExecution = find(id);
   Timer timer = findTimer(jobExecution);
   if (timer != null) {
     timer.cancel();
   }
   super.remove(id);
 }
Esempio n. 3
0
 public Timer findTimer(JobExecution jobExecution) {
   Collection<Timer> timers = timerService.getTimers();
   for (Timer timer : timers) {
     if (jobExecution.getId().compareTo((String) timer.getInfo()) == 0) {
       return timer;
     }
   }
   return null;
 }
 public void addTimer(EventInfo eventInfo) {
   em.persist(eventInfo);
   TimerConfig conf = new TimerConfig();
   conf.setInfo(eventInfo);
   ScheduleExpression schedule = new ScheduleExpression();
   schedule.start(eventInfo.getEventStart());
   schedule.end(eventInfo.getEventEnd());
   schedule.timezone(eventInfo.getTimeZone());
   Timer timer = timerService.createCalendarTimer(schedule, conf);
   System.out.println(timer.getHandle());
 }
Esempio n. 5
0
  public Date schedule(JobExecution jobExecution) {
    Date startTime = jobExecution.getStartTime();
    Date now = Calendar.getInstance().getTime();

    if (startTime.compareTo(now) < 0) {
      startTime = now;
    }

    Timer timer = timerService.createTimer(startTime, jobExecution.getId());
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
    LOGGER.log(Level.INFO, "Job Scheduled to {0}", df.format(timer.getNextTimeout()));
    return timer.getNextTimeout();
  }
  @Timeout
  public void handleTimeout(Timer timer) throws IOException {

    int gameId = (int) timer.getInfo();
    JsonObject gameSummary = (JsonObject) gameResource.endGame(gameId);

    // call websocket to inform end game

    ws.SendtoSameGameConnectedSessions(gameSummary.toString(), gameId);

    timer.cancel();

    System.out.println(gameId);
  }
Esempio n. 7
0
  private void cancelTimers(final ThreadContext threadContext) {
    final BeanContext beanContext = threadContext.getBeanContext();
    final Object primaryKey = threadContext.getPrimaryKey();

    // stop timers
    if (primaryKey != null && beanContext.getEjbTimerService() != null) {
      final EjbTimerService timerService = beanContext.getEjbTimerService();
      if (timerService != null && timerService instanceof EjbTimerServiceImpl) {
        for (final Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
          timer.cancel();
        }
      }
    }
  }
Esempio n. 8
0
  @Override
  public void scheduleConfigCacheReloader() {
    // each time the webapp is reloaded, we don't want to create duplicate jobs
    Collection<Timer> timers = timerService.getTimers();
    for (Timer existingTimer : timers) {
      LOG.debug("Found timer - attempting to cancel: " + existingTimer.toString());
      try {
        existingTimer.cancel();
      } catch (Exception e) {
        LOG.warn("Failed in attempting to cancel timer: " + existingTimer.toString());
      }
    }

    // timer that will trigger every 60 seconds
    timerService.createIntervalTimer(60000L, 60000L, new TimerConfig(null, false));
  }
  private String getKey(InvocationContext invocation) {
    final String method = invocation.getMethod().toString();

    final Object object = invocation.getTimer();
    if (!(object instanceof Timer)) {
      return method;
    }

    final Timer timer = (Timer) object;
    final Serializable info = timer.getInfo();
    if (info == null || info instanceof ScheduleExpression) {
      return method;
    } else {
      return info.toString();
    }
  }
Esempio n. 10
0
  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
      throws ServletException, IOException {
    final PrintWriter writer = response.getWriter();
    writer.print("<html>");
    writer.print("<body>");
    writer.print("<h1>Timers</h1>");
    writer.print("<ul>");

    for (final Timer timer : this.memoryReportBean.getTimers()) {
      writer.print("<li>");
      writer.print(timer.getInfo());
      writer.print("</li>");
    }

    writer.print("</ul>");
    writer.print("</body>");
    writer.print("</html>");
  }
Esempio n. 11
0
 @Timeout
 public void timeout(Timer timer) {
   if (beanManager.getContext(ApplicationScoped.class).isActive()) {
     applicationScopeActive = true;
     if (beanId > 0.0) {
       if (beanId == simpleApplicationBeanInstance.get().getId()) {
         sameBean = true;
       }
     } else {
       beanId = simpleApplicationBeanInstance.get().getId();
     }
   }
   // CDITCK-221 - applicationScopeActive, beanId and sameBean have been set and are testable
   if (timer.getInfo().equals(CLIMB_COMMAND)) {
     climbed = true;
   }
   if (timer.getInfo().equals(DESCEND_COMMAND)) {
     descended = true;
   }
 }
 @Timeout
 private void timeOut(Timer timer) {
   System.out.println("Timer[" + timer.getInfo() + "] TimerBean: timeout occurred");
   System.out.println("Timer[" + timer.getInfo() + "] Persistent : " + timer.isPersistent());
   if (timer.getInfo() != null && (timer.getInfo() instanceof EventInfo)) {
     if (((EventInfo) timer.getInfo()).isRemovable()) {
       timer.cancel();
       EventInfo eventInfo = em.find(EventInfo.class, ((EventInfo) timer.getInfo()).getId());
       em.remove(eventInfo);
     } else {
       if (((EventInfo) timer.getInfo()).isEnabled()) {}
     }
     try {
       Thread.sleep(5000);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
   System.out.println("Timer[" + timer.getInfo() + "] wait expired.");
 }
Esempio n. 13
0
  @Timeout
  public void check(Timer timer) {
    BatchIntervalInfo bi = (BatchIntervalInfo) timer.getInfo();
    try {
      List<ProjectInformation> pi =
          projectInformationService.getProjectInformation(bi.getUsername(), bi.getPassword());
      for (ProjectInformation projectInformation : pi) {
        markCritialTasks(projectInformation, bi);
        if (!bi.isReportFull()) {
          filterOutSendedWarnings(projectInformation, bi);
          filterOutNotCriticalTasks(projectInformation, bi);
        }
        if (projectInformation.getTasks().size() > 0) {
          send(projectInformation);
          markTasksAsSended(projectInformation);
        }
      }

    } catch (Exception ex) {
      Logger.getLogger(BatchTimerBean.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Esempio n. 14
0
  @Timeout
  public void startJob(Timer timer) {
    // Retrieves the job execution from the database.
    String jobExecutionId = (String) timer.getInfo();
    JobExecution currentJobExecution = find(jobExecutionId);
    if (currentJobExecution != null) {
      JobScheduler jobScheduler = currentJobExecution.getJobScheduler();

      // Starts the job execution.
      if (currentJobExecution.getStatus() == JobStatus.SCHEDULED) {
        currentJobExecution.setStartTime(Calendar.getInstance().getTime());
        startJob(currentJobExecution);
      }

      if (jobScheduler.getFrequencyType() != JobFrequencyType.ONCE
          && jobScheduler.getFrequencyType() != JobFrequencyType.INSTANT) {
        schedule(jobScheduler);
      } else {
        jobScheduler.setActive(Boolean.FALSE);
      }
    }
  }
 public void cancelMyTimer() {
   for (Object obj : timerService.getAllTimers()) {
     Timer timer = (Timer) obj;
     timer.cancel();
   }
 }
Esempio n. 16
0
 public Date findTimeout(JobExecution jobExecution) {
   Timer timer = findTimer(jobExecution);
   return timer != null ? timer.getNextTimeout() : null;
 }