Search in sources :

Example 1 with TimerConfig

use of javax.ejb.TimerConfig in project jbpm by kiegroup.

the class DeploymentSynchronizerCDInvoker method configure.

@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));
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimerConfig(javax.ejb.TimerConfig) PostConstruct(javax.annotation.PostConstruct)

Example 2 with TimerConfig

use of javax.ejb.TimerConfig in project jbpm by kiegroup.

the class EJBTimerScheduler method internalSchedule.

public void internalSchedule(TimerJobInstance timerJobInstance) {
    TimerConfig config = new TimerConfig(new EjbTimerJob(timerJobInstance), true);
    Date expirationTime = timerJobInstance.getTrigger().hasNextFireTime();
    logger.debug("Timer expiration date is {}", expirationTime);
    if (expirationTime != null) {
        timerService.createSingleActionTimer(expirationTime, config);
        logger.debug("Timer scheduled {} on {} scheduler service", timerJobInstance);
        localCache.putIfAbsent(((EjbGlobalJobHandle) timerJobInstance.getJobHandle()).getUuid(), timerJobInstance);
    } else {
        logger.info("Timer that was to be scheduled has already expired");
    }
}
Also used : TimerConfig(javax.ejb.TimerConfig) Date(java.util.Date)

Example 3 with TimerConfig

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

the class TimerServiceSuspendTestCase method testIntervalTimersDoNotBackUp.

/**
 * This test makes sure that interval timers that are scheduled while a timer is suspended do not back up, and only a single
 * run will occur when the container is resumed
 */
@Test
public void testIntervalTimersDoNotBackUp() 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().createIntervalTimer(100, 100, new TimerConfig("", false));
            Thread.sleep(5000);
            Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
        } finally {
            op = new ModelNode();
            op.get(ModelDescriptionConstants.OP).set("resume");
            managementClient.getControllerClient().execute(op);
        }
        // if they were backed up we give them some time to run
        Thread.sleep(300);
        int timerServiceCount = SuspendTimerServiceBean.getTimerServiceCount();
        Assert.assertTrue("Interval " + (System.currentTimeMillis() - start) + " count " + timerServiceCount, timerServiceCount < 40);
    } finally {
        if (timer != null) {
            timer.cancel();
            Thread.sleep(100);
        }
    }
}
Also used : Timer(javax.ejb.Timer) TimerConfig(javax.ejb.TimerConfig) ModelNode(org.jboss.dmr.ModelNode) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 4 with TimerConfig

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

the class TimerServiceSuspendTestCase method testSuspendWithIntervalTimer.

@Test
public void testSuspendWithIntervalTimer() throws NamingException, IOException, InterruptedException {
    SuspendTimerServiceBean.resetTimerServiceCalled();
    InitialContext ctx = new InitialContext();
    SuspendTimerServiceBean bean = (SuspendTimerServiceBean) ctx.lookup("java:module/" + SuspendTimerServiceBean.class.getSimpleName());
    ModelNode op = new ModelNode();
    Timer timer = null;
    try {
        try {
            timer = bean.getTimerService().createIntervalTimer(100, 100, new TimerConfig("", false));
            Assert.assertTrue(SuspendTimerServiceBean.awaitTimerServiceCount() > 0);
            op.get(ModelDescriptionConstants.OP).set("suspend");
            managementClient.getControllerClient().execute(op);
            SuspendTimerServiceBean.resetTimerServiceCalled();
            Thread.sleep(200);
            Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
        } finally {
            op = new ModelNode();
            op.get(ModelDescriptionConstants.OP).set("resume");
            managementClient.getControllerClient().execute(op);
        }
        Assert.assertTrue(SuspendTimerServiceBean.awaitTimerServiceCount() > 0);
    } finally {
        if (timer != null) {
            timer.cancel();
            Thread.sleep(100);
        }
    }
}
Also used : Timer(javax.ejb.Timer) TimerConfig(javax.ejb.TimerConfig) ModelNode(org.jboss.dmr.ModelNode) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 5 with TimerConfig

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

the class NonPersistentTimerServiceBean method createTimer.

public void createTimer() {
    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setPersistent(false);
    timerService.createIntervalTimer(100, 100, timerConfig);
}
Also used : TimerConfig(javax.ejb.TimerConfig)

Aggregations

TimerConfig (javax.ejb.TimerConfig)37 ScheduleExpression (javax.ejb.ScheduleExpression)13 Date (java.util.Date)8 PostConstruct (javax.annotation.PostConstruct)7 Test (org.junit.Test)7 Timer (javax.ejb.Timer)6 InitialContext (javax.naming.InitialContext)6 ModelNode (org.jboss.dmr.ModelNode)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 InSequence (org.jboss.arquillian.junit.InSequence)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Serializable (java.io.Serializable)1 Method (java.lang.reflect.Method)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1