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
}
}
}
}
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);
}
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);
}
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());
}
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();
}
Aggregations