Search in sources :

Example 11 with TimerConfig

use of javax.ejb.TimerConfig in project wildfly by wildfly.

the class TimerServiceSuspendTestCase method testSingleActionTimerWhenSuspended.

/**
     * Tests that a single action timer that executes when the container is suspended will run as normal once it is resumed
     */
@Test
public void testSingleActionTimerWhenSuspended() throws NamingException, IOException, InterruptedException {
    SuspendTimerServiceBean.resetTimerServiceCalled();
    InitialContext ctx = new InitialContext();
    SuspendTimerServiceBean bean = (SuspendTimerServiceBean) ctx.lookup("java:module/" + SuspendTimerServiceBean.class.getSimpleName());
    Timer timer = null;
    try {
        long start = 0;
        ModelNode op = new ModelNode();
        try {
            op.get(ModelDescriptionConstants.OP).set("suspend");
            managementClient.getControllerClient().execute(op);
            //create the timer while the container is suspended
            start = System.currentTimeMillis();
            timer = bean.getTimerService().createSingleActionTimer(1, new TimerConfig("", false));
            Thread.sleep(1000);
            Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
        } finally {
            op = new ModelNode();
            op.get(ModelDescriptionConstants.OP).set("resume");
            managementClient.getControllerClient().execute(op);
        }
        Assert.assertEquals(1, SuspendTimerServiceBean.awaitTimerServiceCount());
    } finally {
        if (timer != null) {
            try {
                timer.cancel();
                Thread.sleep(100);
            } catch (Exception e) {
            //as the timer has already expired this may throw an exception
            }
        }
    }
}
Also used : Timer(javax.ejb.Timer) TimerConfig(javax.ejb.TimerConfig) ModelNode(org.jboss.dmr.ModelNode) InitialContext(javax.naming.InitialContext) IOException(java.io.IOException) NamingException(javax.naming.NamingException) Test(org.junit.Test)

Example 12 with TimerConfig

use of javax.ejb.TimerConfig in project wildfly by wildfly.

the class OtherTimerBeanInSameModule method createTimerForNextDay.

public void createTimerForNextDay(final boolean persistent, final String info) {
    this.timerService.createSingleActionTimer(new Date(System.currentTimeMillis() + (60 * 60 * 24 * 1000)), new TimerConfig(info, persistent));
    logger.trace("Created a timer persistent = " + persistent + " info = " + info);
}
Also used : TimerConfig(javax.ejb.TimerConfig) Date(java.util.Date)

Example 13 with TimerConfig

use of javax.ejb.TimerConfig in project wildfly by wildfly.

the class SimpleTimerBean method createTimerForNextDay.

public void createTimerForNextDay(final boolean persistent, final String info) {
    this.timerService.createSingleActionTimer(new Date(System.currentTimeMillis() + (60 * 60 * 24 * 1000)), new TimerConfig(info, persistent));
    logger.trace("Created a timer persistent = " + persistent + " info = " + info);
}
Also used : TimerConfig(javax.ejb.TimerConfig) Date(java.util.Date)

Example 14 with TimerConfig

use of javax.ejb.TimerConfig in project wildfly by wildfly.

the class DatabaseTimerServiceTestCase method testTimedObjectTimeoutMethod.

@Test
public void testTimedObjectTimeoutMethod() throws NamingException {
    InitialContext ctx = new InitialContext();
    TimedObjectTimerServiceBean bean = (TimedObjectTimerServiceBean) ctx.lookup("java:module/" + TimedObjectTimerServiceBean.class.getSimpleName());
    bean.resetTimerServiceCalled();
    bean.getTimerService().createTimer(TIMER_TIMEOUT_TIME_MS, INFO_MSG_FOR_CHECK);
    Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
    bean.resetTimerServiceCalled();
    long ts = (new Date()).getTime() + TIMER_INIT_TIME_MS;
    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(INFO_MSG_FOR_CHECK);
    bean.getTimerService().createSingleActionTimer(new Date(ts), timerConfig);
    Assert.assertTrue(TimedObjectTimerServiceBean.awaitTimerCall());
    Assert.assertEquals(INFO_MSG_FOR_CHECK, bean.getTimerInfo());
    Assert.assertFalse(bean.isCalendar());
    Assert.assertTrue(bean.isPersistent());
}
Also used : TimerConfig(javax.ejb.TimerConfig) InitialContext(javax.naming.InitialContext) Date(java.util.Date) Test(org.junit.Test)

Example 15 with TimerConfig

use of javax.ejb.TimerConfig in project wildfly by wildfly.

the class CancelledTimerServiceBean method createTimer.

public TimerHandle createTimer() {
    ScheduleExpression expression = new ScheduleExpression();
    expression.second("*");
    expression.minute("*");
    expression.hour("*");
    expression.dayOfMonth("*");
    expression.year("*");
    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(new String("info"));
    return timerService.createCalendarTimer(expression, timerConfig).getHandle();
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimerConfig(javax.ejb.TimerConfig)

Aggregations

TimerConfig (javax.ejb.TimerConfig)16 Test (org.junit.Test)7 Date (java.util.Date)6 InitialContext (javax.naming.InitialContext)6 ScheduleExpression (javax.ejb.ScheduleExpression)4 Timer (javax.ejb.Timer)4 ModelNode (org.jboss.dmr.ModelNode)3 InSequence (org.jboss.arquillian.junit.InSequence)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 PostConstruct (javax.annotation.PostConstruct)1 NoMoreTimeoutsException (javax.ejb.NoMoreTimeoutsException)1 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)1 NamingException (javax.naming.NamingException)1 ScheduleData (org.apache.openejb.core.timer.ScheduleData)1