Java Code Examples for javax.ejb.ScheduleExpression

The following are top voted examples for showing how to use javax.ejb.ScheduleExpression. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: jboss-ejb3-calendar-expr-parser   File: CalendarBasedTimeoutTestCase.java View source code 6 votes vote down vote up
@Test
public void testEverySecondTimeout()
{
   ScheduleExpression everySecondExpression = this.getTimezoneSpecificScheduleExpression();
   everySecondExpression.second("*");
   everySecondExpression.minute("*");
   everySecondExpression.hour("*");

   CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everySecondExpression);

   Calendar firstTimeout = calendarTimeout.getFirstTimeout();
   Calendar nextTimeout = calendarTimeout.getNextTimeout(firstTimeout);

   Assert.assertNotNull("Next timeout is null", nextTimeout);
   Assert.assertNotNull("Next timeout is *before* the current time", nextTimeout.after(firstTimeout));
   logger.debug("Previous timeout was: " + firstTimeout.getTime() + " Next timeout is " + nextTimeout.getTime());
   long diff = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
   Assert.assertEquals("Unexpected timeout value: " + nextTimeout, 1 * 1000, diff);
}
 
Example 2
Project: jboss-ejb3-calendar-expr-parser   File: CalendarBasedTimeoutTestCase.java View source code 6 votes vote down vote up
@Test
public void testEveryMinuteEveryHourEveryDay()
{
   ScheduleExpression everyMinEveryHourEveryDay = this.getTimezoneSpecificScheduleExpression();
   everyMinEveryHourEveryDay.minute("*");
   everyMinEveryHourEveryDay.hour("*");

   CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyMinEveryHourEveryDay);

   Calendar firstTimeout = calendarTimeout.getFirstTimeout();
   Calendar previousTimeout = firstTimeout;
   for (int i = 1; i <= 65; i++)
   {
      Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);

      Assert.assertNotNull("Next timeout is null", nextTimeout);
      Assert.assertNotNull("Next timeout is *before* the current time", nextTimeout.after(previousTimeout));
      logger.debug("First timeout was: " + firstTimeout.getTime() + " Previous timeout was: "
            + previousTimeout.getTime() + " Next timeout is " + nextTimeout.getTime());
      long diff = nextTimeout.getTimeInMillis() - previousTimeout.getTimeInMillis();
      long diffWithFirstTimeout = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
      Assert.assertEquals("Unexpected timeout value: " + nextTimeout, 60 * 1000, diff);
      Assert.assertEquals("Unexpected timeout value when compared to first timeout: " + nextTimeout.getTime(),
            60 * 1000 * i, diffWithFirstTimeout);

      previousTimeout = nextTimeout;
   }
}
 
Example 3
Project: http-queue   File: JobManager.java View source code 6 votes vote down vote up
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;
}
 
Example 4
Project: jboss-ejb3-timerservice   File: CalendarBasedTimeoutTestCase.java View source code 6 votes vote down vote up
@Test
public void testEverySecondTimeout()
{
   ScheduleExpression everySecondExpression = this.getTimezoneSpecificScheduleExpression();
   everySecondExpression.second("*");
   everySecondExpression.minute("*");
   everySecondExpression.hour("*");

   CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everySecondExpression);

   Calendar firstTimeout = calendarTimeout.getFirstTimeout();
   Calendar nextTimeout = calendarTimeout.getNextTimeout(firstTimeout);

   Assert.assertNotNull("Next timeout is null", nextTimeout);
   Assert.assertNotNull("Next timeout is *before* the current time", nextTimeout.after(firstTimeout));
   logger.debug("Previous timeout was: " + firstTimeout.getTime() + " Next timeout is " + nextTimeout.getTime());
   long diff = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
   Assert.assertEquals("Unexpected timeout value: " + nextTimeout, 1 * 1000, diff);
}
 
Example 5
Project: jboss-ejb3-timerservice   File: CalendarBasedTimeoutTestCase.java View source code 6 votes vote down vote up
@Test
public void testEveryMinuteEveryHourEveryDay()
{
   ScheduleExpression everyMinEveryHourEveryDay = this.getTimezoneSpecificScheduleExpression();
   everyMinEveryHourEveryDay.minute("*");
   everyMinEveryHourEveryDay.hour("*");

   CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyMinEveryHourEveryDay);

   Calendar firstTimeout = calendarTimeout.getFirstTimeout();
   Calendar previousTimeout = firstTimeout;
   for (int i = 1; i <= 65; i++)
   {
      Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);

      Assert.assertNotNull("Next timeout is null", nextTimeout);
      Assert.assertNotNull("Next timeout is *before* the current time", nextTimeout.after(previousTimeout));
      logger.debug("First timeout was: " + firstTimeout.getTime() + " Previous timeout was: "
            + previousTimeout.getTime() + " Next timeout is " + nextTimeout.getTime());
      long diff = nextTimeout.getTimeInMillis() - previousTimeout.getTimeInMillis();
      long diffWithFirstTimeout = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
      Assert.assertEquals("Unexpected timeout value: " + nextTimeout, 60 * 1000, diff);
      Assert.assertEquals("Unexpected timeout value when compared to first timeout: " + nextTimeout.getTime(),
            60 * 1000 * i, diffWithFirstTimeout);

      previousTimeout = nextTimeout;
   }
}
 
Example 6
Project: bookery   File: BatchJobService.java View source code 6 votes vote down vote up
public BatchJobConfiguration fireUpTimer(BatchJobConfiguration jobConfig) {
    if (jobConfig.isActive()) {
        TimerConfig timerConf = new TimerConfig(jobConfig, false);
        String[] splittedCronJob = jobConfig.getCronJobExpression().split(" ");
        ScheduleExpression schedExp = new ScheduleExpression();
        schedExp.second(splittedCronJob[0]);
        schedExp.minute(splittedCronJob[1]);
        schedExp.hour(splittedCronJob[2]);
        schedExp.dayOfMonth(splittedCronJob[3]);
        schedExp.month(splittedCronJob[4]);
        schedExp.year(splittedCronJob[5]);
        schedExp.dayOfWeek(splittedCronJob[6]);
        Timer timer = timerService.createCalendarTimer(schedExp, timerConf);
        jobConfig.setNextTimeout(timer.getNextTimeout());
        jobConfig = batchJobConfigurationDAO.update(jobConfig);
    }
    return jobConfig;
}
 
Example 7
Project: tomee   File: QuartzPersistenceForEJBTimersTest.java View source code 6 votes vote down vote up
public void newTimer() {
    final TimerConfig tc = new TimerConfig("my-timer", true);
    final ScheduleExpression se = new ScheduleExpression();
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.SECOND, 2);
    se.second(calendar.get(Calendar.SECOND) + "/3");
    se.minute("*");
    se.hour("*");
    se.dayOfMonth("*");
    se.dayOfWeek("*");
    se.month("*");
    timer = timerService.createCalendarTimer(se, tc);
}
 
Example 8
Project: tomee   File: GetTimerTest.java View source code 6 votes vote down vote up
public void newTimer() {
    final TimerConfig tc = new TimerConfig("my-timer", true);
    final ScheduleExpression se = new ScheduleExpression();
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.SECOND, 2);
    se.second(calendar.get(Calendar.SECOND) + "/3");
    se.minute("*");
    se.hour("*");
    se.dayOfMonth("*");
    se.dayOfWeek("*");
    se.month("*");
    timer = timerService.createCalendarTimer(se, tc);
}
 
Example 9
Project: jbpm   File: DeploymentSynchronizerEJBImpl.java View source code 6 votes vote down vote up
@PostConstruct
public void configure() {
	if (DEPLOY_SYNC_ENABLED) {
		ScheduleExpression schedule = new ScheduleExpression();
		
		schedule.hour("*");
		schedule.minute("*");
		schedule.second("*/" + DEPLOY_SYNC_INTERVAL);
		timer = timerService.createCalendarTimer(schedule, new TimerConfig(null, false));
		DeploymentStore store = new DeploymentStore();
		store.setCommandService(commandService);
		
		setDeploymentStore(store);
	}
}
 
Example 10
Project: jbpm   File: DeploymentSynchronizerCDInvoker.java View source code 6 votes vote down vote up
@PostConstruct
public void configure() {
	if (DeploymentSynchronizer.DEPLOY_SYNC_ENABLED) {
		ScheduleExpression schedule = new ScheduleExpression();
		
		schedule.hour("*");
		schedule.minute("*");
		schedule.second("*/" + DeploymentSynchronizer.DEPLOY_SYNC_INTERVAL);
		timer = timerService.createCalendarTimer(schedule, new TimerConfig(null, false));
	
	}
}
 
Example 11
Project: jboss-ejb3-calendar-expr-parser   File: CalendarBasedTimeoutTestCase.java View source code 6 votes vote down vote up
@Test
public void testEvery10Seconds()
{
   ScheduleExpression every10Secs = this.getTimezoneSpecificScheduleExpression();
   every10Secs.second("*/10");
   every10Secs.minute("*");
   every10Secs.hour("*");

   CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(every10Secs);
   Calendar firstTimeout = calendarTimeout.getFirstTimeout();

   int firstTimeoutSecond = firstTimeout.get(Calendar.SECOND);
   Assert.assertTrue("Unexpected second " + firstTimeoutSecond + " in first timeout " + firstTimeout,
         firstTimeoutSecond % 10 == 0);

   Calendar previousTimeout = firstTimeout;
   for (int i = 0; i < 5; i++)
   {
      Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);
      int nextTimeoutSecond = nextTimeout.get(Calendar.SECOND);
      Assert.assertTrue("Unexpected second " + nextTimeoutSecond + " in next timeout " + nextTimeout,
            nextTimeoutSecond % 10 == 0);

      previousTimeout = nextTimeout;

   }

}
 
Example 12
Project: dcm4chee-router   File: FileCacheManagerBean.java View source code 6 votes vote down vote up
@Override
public Timer initTimer(){
    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setPersistent(false);
    ScheduleExpression schedule = new ScheduleExpression();
    int timerInterval = (Integer) device.getDevice()
            .getProperty("Interval.checkForNewReceivedSeries")*1000;
    schedule.second(timerInterval);
    LOG.debug("Creating checkForNewReceivedSeriesTimer with " + timerInterval/1000 
            + " seconds interval");
    return timerService.createIntervalTimer(timerInterval, timerInterval, timerConfig);
}
 
Example 13
Project: jboss-ejb3-timerservice   File: CalendarBasedTimeoutTestCase.java View source code 6 votes vote down vote up
@Test
public void testEvery10Seconds()
{
   ScheduleExpression every10Secs = this.getTimezoneSpecificScheduleExpression();
   every10Secs.second("*/10");
   every10Secs.minute("*");
   every10Secs.hour("*");

   CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(every10Secs);
   Calendar firstTimeout = calendarTimeout.getFirstTimeout();

   int firstTimeoutSecond = firstTimeout.get(Calendar.SECOND);
   Assert.assertTrue("Unexpected second " + firstTimeoutSecond + " in first timeout " + firstTimeout,
         firstTimeoutSecond % 10 == 0);

   Calendar previousTimeout = firstTimeout;
   for (int i = 0; i < 5; i++)
   {
      Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);
      int nextTimeoutSecond = nextTimeout.get(Calendar.SECOND);
      Assert.assertTrue("Unexpected second " + nextTimeoutSecond + " in next timeout " + nextTimeout,
            nextTimeoutSecond % 10 == 0);

      previousTimeout = nextTimeout;

   }

}