Search in sources :

Example 21 with TimerConfig

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

the class RefreshBeanBase method createTimer.

/**
 * {@inheritDoc}
 */
@Override
public byte[] createTimer(final long delay, final Serializable info) {
    final Timer timer = timerService.createSingleActionTimer(delay, new TimerConfig(info, true));
    if (info == Info.RETURN_HANDLE) {
        final TimerHandle handle = timer.getHandle();
        try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
            final ObjectOutputStream out = new ObjectOutputStream(bos)) {
            out.writeObject(handle);
            out.flush();
            return bos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException("Failed to serialize timer handle for timer: " + timer, e);
        }
    } else {
        return null;
    }
}
Also used : Timer(javax.ejb.Timer) TimerConfig(javax.ejb.TimerConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TimerHandle(javax.ejb.TimerHandle) ObjectOutputStream(java.io.ObjectOutputStream)

Example 22 with TimerConfig

use of javax.ejb.TimerConfig in project tomee by apache.

the class MethodScheduleBuilder method addSchedulesToMethod.

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));
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) ScheduleData(org.apache.openejb.core.timer.ScheduleData) TimerConfig(javax.ejb.TimerConfig)

Example 23 with TimerConfig

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

the class SingletonTimer method initialize.

@PostConstruct
public void initialize() {
    LOGGER.warning("SingletonTimer is initializing.");
    // For the demonstration just output a Hello World log every 5 seconds.
    ScheduleExpression scheduleExpression = new ScheduleExpression().hour("*").minute("*").second("0/5");
    // Persistent must be set to false (since it defaults to true) because the timer is not specific to this JVM.
    TimerConfig test = new TimerConfig("Hello World!", false);
    timerService.createCalendarTimer(scheduleExpression, test);
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimerConfig(javax.ejb.TimerConfig) PostConstruct(javax.annotation.PostConstruct)

Example 24 with TimerConfig

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

the class TimeoutExample method initialize.

@PostConstruct
public void initialize() {
    ScheduleExpression se = new ScheduleExpression();
    // Set schedule to every 3 seconds (starting at second 0 of every minute).
    se.hour("*").minute("*").second("0/3");
    timerService.createCalendarTimer(se, new TimerConfig("EJB timer service timeout at ", false));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimerConfig(javax.ejb.TimerConfig) PostConstruct(javax.annotation.PostConstruct)

Example 25 with TimerConfig

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

the class WaitTimeSingletonBean method startTimer.

private void startTimer() {
    final TimerConfig timerConfig = new TimerConfig("WaitTimeSingletonBean timer " + timerNumbers.getAndIncrement(), false);
    timerService.createSingleActionTimer(1, 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