javax.ejb.TimerConfig Java Examples

The following examples show how to use javax.ejb.TimerConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimerServiceBean.java    From development with Apache License 2.0 6 votes vote down vote up
void createTimerWithPeriod(TimerService timerService, TimerType timerType,
        long timerOffset, Period period) {
    if (isTimerCreated(timerType, timerService)) {
        return;
    }
    TimerConfig config = new TimerConfig();
    config.setInfo(timerType);
    Date startDate = getDateForNextTimerExpiration(period, timerOffset);
    ScheduleExpression schedleExpression = getExpressionForPeriod(period,
            startDate);
    Timer timer = timerService.createCalendarTimer(schedleExpression,
            config);
    Date nextStart = timer.getNextTimeout();
    SimpleDateFormat sdf = new SimpleDateFormat();
    logger.logInfo(Log4jLogger.SYSTEM_LOG,
            LogMessageIdentifier.INFO_TIMER_CREATED,
            String.valueOf(timerType), sdf.format(nextStart));
}
 
Example #2
Source File: EjbTimerServiceImpl.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public Timer createTimer(final Object primaryKey,
                         final Method timeoutMethod,
                         final long duration,
                         final TimerConfig timerConfig) throws IllegalArgumentException, IllegalStateException, EJBException {
    if (duration < 0) {
        throw new IllegalArgumentException("duration is negative: " + duration);
    }
    checkState();

    final Date expiration = new Date(System.currentTimeMillis() + duration);
    try {
        final TimerData timerData = timerStore.createSingleActionTimer(this, (String) deployment.getDeploymentID(), primaryKey, timeoutMethod, expiration, timerConfig);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
 
Example #3
Source File: EjbTimerServiceImpl.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public Timer createTimer(final Object primaryKey,
                         final Method timeoutMethod,
                         final Date expiration,
                         final TimerConfig timerConfig) throws IllegalArgumentException, IllegalStateException, EJBException {
    if (expiration == null) {
        throw new IllegalArgumentException("expiration is null");
    }
    if (expiration.getTime() < 0) {
        throw new IllegalArgumentException("expiration is negative: " + expiration.getTime());
    }
    checkState();

    try {
        final TimerData timerData = timerStore.createSingleActionTimer(this, (String) deployment.getDeploymentID(), primaryKey, timeoutMethod, expiration, timerConfig);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
 
Example #4
Source File: EjbTimerServiceImpl.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public Timer createTimer(final Object primaryKey, final Method timeoutMethod, final ScheduleExpression scheduleExpression, final TimerConfig timerConfig) {
    if (scheduleExpression == null) {
        throw new IllegalArgumentException("scheduleExpression is null");
    }
    //TODO add more schedule expression validation logic ?
    checkState();
    try {
        final TimerData timerData = timerStore.createCalendarTimer(this,
            (String) deployment.getDeploymentID(),
            primaryKey,
            timeoutMethod,
            scheduleExpression,
            timerConfig,
            false);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
 
Example #5
Source File: TimerServiceBean2Test.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void initTimers_interval() throws Exception {
    // given
    TimerServiceStub timeServiceStub = mock(TimerServiceStub.class);
    when(ctx.getTimerService()).thenReturn(timeServiceStub);
    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(TimerType.BILLING_INVOCATION);
    doReturn(new TimerStub(null, timerConfig)).when(timeServiceStub)
            .createCalendarTimer(any(ScheduleExpression.class),
                    any(TimerConfig.class));

    // when
    tm.initTimers();

    // then
    verify(timeServiceStub, times(4)).createTimer(any(Date.class),
            eq(10000L), any(TimerType.class));
}
 
Example #6
Source File: MemoryTimerStore.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public TimerData createCalendarTimer(final EjbTimerServiceImpl timerService, final String deploymentId, final Object primaryKey, final Method timeoutMethod, final ScheduleExpression scheduleExpression, final TimerConfig timerConfig, final boolean auto)
    throws TimerStoreException {
    final long id = counter.incrementAndGet();
    final TimerData timerData = new CalendarTimerData(id, timerService, deploymentId, primaryKey, timeoutMethod, timerConfig, scheduleExpression, auto);
    getTasks().addTimerData(timerData);
    return timerData;
}
 
Example #7
Source File: TimerServiceStub.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public Timer createIntervalTimer(long arg0, long arg1, TimerConfig arg2)
        throws IllegalArgumentException, IllegalStateException,
        EJBException {

    return null;
}
 
Example #8
Source File: TimerServiceStub.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public Timer createIntervalTimer(Date arg0, long arg1, TimerConfig arg2)
        throws IllegalArgumentException, IllegalStateException,
        EJBException {

    return null;
}
 
Example #9
Source File: TimerServiceStub.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public Timer createCalendarTimer(ScheduleExpression arg0, TimerConfig arg1)
        throws IllegalArgumentException, IllegalStateException,
        EJBException {
    TimerStub timer = new TimerStub(arg0, arg1);
    timers.add(timer);
    return timer;
}
 
Example #10
Source File: TimerServiceStub.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public Timer createSingleActionTimer(Date arg0, TimerConfig arg1)
        throws IllegalArgumentException, IllegalStateException,
        EJBException {

    return null;
}
 
Example #11
Source File: TransactionRegistryInTimeoutTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public Timer setTimerNow() {
    final ScheduleExpression schedule = new ScheduleExpression().second("*/3").minute("*").hour("*");

    final TimerConfig timerConfig = new TimerConfig();
    timerConfig.setPersistent(false);

    return timerService.createCalendarTimer(schedule, timerConfig);
}
 
Example #12
Source File: GetTimerTest.java    From tomee with Apache License 2.0 5 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 #13
Source File: SingleActionTimerTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void createTimer() {
    try {
        this.timer = this.timerService.createSingleActionTimer(100, new TimerConfig(TIMER_NAME, false));
    } catch (final Exception e) {
        throw new RuntimeException("SingleActionTimer: Failed to create timer", e);
    }
}
 
Example #14
Source File: Bot.java    From monolith with Apache License 2.0 5 votes vote down vote up
public Timer start() {
    String startMessage = new StringBuilder("==========================\n")
            .append("Bot started at ").append(new Date().toString()).append("\n")
            .toString();
    event.fire(startMessage);
    return timerService.createIntervalTimer(0, DURATION, new TimerConfig(null, false));
}
 
Example #15
Source File: Bot.java    From monolith with Apache License 2.0 5 votes vote down vote up
public Timer start() {
    String startMessage = new StringBuilder("==========================\n")
            .append("Bot started at ").append(new Date().toString()).append("\n")
            .toString();
    event.fire(startMessage);
    return timerService.createIntervalTimer(0, DURATION, new TimerConfig(null, false));
}
 
Example #16
Source File: Bot.java    From monolith with Apache License 2.0 5 votes vote down vote up
public Timer start() {
    String startMessage = new StringBuilder("==========================\n")
            .append("Bot started at ").append(new Date().toString()).append("\n")
            .toString();
    event.fire(startMessage);
    return timerService.createIntervalTimer(0, DURATION, new TimerConfig(null, false));
}
 
Example #17
Source File: TimerServiceStub.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public Timer createSingleActionTimer(long arg0, TimerConfig arg1)
        throws IllegalArgumentException, IllegalStateException,
        EJBException {

    return null;
}
 
Example #18
Source File: TimerStub.java    From development with Apache License 2.0 5 votes vote down vote up
public TimerStub(ScheduleExpression scheduleExpression, TimerConfig config) {
    this.scheduleExpression = scheduleExpression;
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, 1);
    this.execDate = cal.getTime();
    this.info = config.getInfo();
}
 
Example #19
Source File: QuartzPersistenceForEJBTimersTest.java    From tomee with Apache License 2.0 5 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 #20
Source File: FarmerBrown.java    From tomee with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void construct() {
    final TimerConfig plantTheCorn = new TimerConfig("plantTheCorn", false);
    timerService.createCalendarTimer(new ScheduleExpression().month(5).dayOfMonth("20-Last").minute(0).hour(8), plantTheCorn);
    timerService.createCalendarTimer(new ScheduleExpression().month(6).dayOfMonth("1-10").minute(0).hour(8), plantTheCorn);

    final TimerConfig harvestTheCorn = new TimerConfig("harvestTheCorn", false);
    timerService.createCalendarTimer(new ScheduleExpression().month(9).dayOfMonth("20-Last").minute(0).hour(8), harvestTheCorn);
    timerService.createCalendarTimer(new ScheduleExpression().month(10).dayOfMonth("1-10").minute(0).hour(8), harvestTheCorn);

    final TimerConfig checkOnTheDaughters = new TimerConfig("checkOnTheDaughters", false);
    timerService.createCalendarTimer(new ScheduleExpression().second("*").minute("*").hour("*"), checkOnTheDaughters);
}
 
Example #21
Source File: MethodScheduleBuilder.java    From tomee with Apache License 2.0 5 votes vote down vote up
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));
        }

    }
 
Example #22
Source File: EjbTimerServiceImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public Timer createTimer(final Object primaryKey,
                         final Method timeoutMethod,
                         final long initialDuration,
                         final long intervalDuration,
                         final TimerConfig timerConfig) throws IllegalArgumentException, IllegalStateException, EJBException {
    if (initialDuration < 0) {
        throw new IllegalArgumentException("initialDuration is negative: " + initialDuration);
    }
    if (intervalDuration < 0) {
        throw new IllegalArgumentException("intervalDuration is negative: " + intervalDuration);
    }
    checkState();

    final Date initialExpiration = new Date(System.currentTimeMillis() + initialDuration);
    try {
        final TimerData timerData = timerStore.createIntervalTimer(this,
            (String) deployment.getDeploymentID(),
            primaryKey,
            timeoutMethod,
            initialExpiration,
            intervalDuration,
            timerConfig);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
 
Example #23
Source File: TimerData.java    From tomee with Apache License 2.0 5 votes vote down vote up
public TimerData(final long id,
                 final EjbTimerServiceImpl timerService,
                 final String deploymentId,
                 final Object primaryKey,
                 final Method timeoutMethod,
                 final TimerConfig timerConfig) {
    this.id = id;
    this.timerService = timerService;
    this.deploymentId = deploymentId;
    this.primaryKey = primaryKey;
    this.info = timerConfig == null ? null : timerConfig.getInfo();
    this.persistent = timerConfig == null || timerConfig.isPersistent();
    this.timer = new TimerImpl(this);
    this.timeoutMethod = timeoutMethod;
}
 
Example #24
Source File: MemoryTimerStore.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public TimerData createSingleActionTimer(final EjbTimerServiceImpl timerService, final String deploymentId, final Object primaryKey, final Method timeoutMethod, final Date expiration, final TimerConfig timerConfig) throws TimerStoreException {
    final long id = counter.incrementAndGet();
    final TimerData timerData = new SingleActionTimerData(id, timerService, deploymentId, primaryKey, timeoutMethod, timerConfig, expiration);
    getTasks().addTimerData(timerData);
    return timerData;
}
 
Example #25
Source File: MemoryTimerStore.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public TimerData createIntervalTimer(final EjbTimerServiceImpl timerService, final String deploymentId, final Object primaryKey, final Method timeoutMethod, final Date initialExpiration, final long intervalDuration, final TimerConfig timerConfig)
    throws TimerStoreException {
    final long id = counter.incrementAndGet();
    final TimerData timerData = new IntervalTimerData(id, timerService, deploymentId, primaryKey, timeoutMethod, timerConfig, initialExpiration, intervalDuration);
    getTasks().addTimerData(timerData);
    return timerData;
}
 
Example #26
Source File: EjbTimerServiceImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public Timer createTimer(final Object primaryKey,
                         final Method timeoutMethod,
                         final Date initialExpiration,
                         final long intervalDuration,
                         final TimerConfig timerConfig) throws IllegalArgumentException, IllegalStateException, EJBException {
    if (initialExpiration == null) {
        throw new IllegalArgumentException("initialExpiration is null");
    }
    if (initialExpiration.getTime() < 0) {
        throw new IllegalArgumentException("initialExpiration is negative: " + initialExpiration.getTime());
    }
    if (intervalDuration < 0) {
        throw new IllegalArgumentException("intervalDuration is negative: " + intervalDuration);
    }
    checkState();

    try {
        final TimerData timerData = timerStore.createIntervalTimer(this,
            (String) deployment.getDeploymentID(),
            primaryKey,
            timeoutMethod,
            initialExpiration,
            intervalDuration,
            timerConfig);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
 
Example #27
Source File: TimerServiceImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
public Timer createTimer(final Date expiration, final Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException {
    return ejbTimerService.createTimer(primaryKey, ejbTimeout, expiration, new TimerConfig(info, true));
}
 
Example #28
Source File: TimerServiceImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
public Timer createTimer(final long duration, final Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException {
    return ejbTimerService.createTimer(primaryKey, ejbTimeout, duration, new TimerConfig(info, true));
}
 
Example #29
Source File: TimerServiceImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
public Timer createTimer(final Date initialExpiration, final long intervalDuration, final Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException {
    return ejbTimerService.createTimer(primaryKey, ejbTimeout, initialExpiration, intervalDuration, new TimerConfig(info, true));
}
 
Example #30
Source File: IntervalTimerData.java    From tomee with Apache License 2.0 4 votes vote down vote up
public IntervalTimerData(final long id, final EjbTimerServiceImpl timerService, final String deploymentId, final Object primaryKey, final Method timeoutMethod, final TimerConfig timerConfig, final Date initialExpiration, final long intervalDuration) {
    super(id, timerService, deploymentId, primaryKey, timeoutMethod, timerConfig);
    this.initialExpiration = initialExpiration;
    this.intervalDuration = intervalDuration;
}