Search in sources :

Example 6 with EjbTimerService

use of org.apache.openejb.core.timer.EjbTimerService in project tomee by apache.

the class EjbTimerImplSerializableTest method serializeDeserialize.

@Test
public void serializeDeserialize() throws Exception {
    final EjbTimerService timer = timerService();
    assertNotNull(timer);
    assertThat(timer, instanceOf(EjbTimerServiceImpl.class));
    final byte[] serial = serialize(timer);
    final EjbTimerService timerDeserialized = (EjbTimerService) deserialize(serial);
    assertThat(timerDeserialized, instanceOf(EjbTimerServiceImpl.class));
    assertThat(((EjbTimerServiceImpl) timerDeserialized).getScheduler(), notNullValue());
    assertEqualsByReflection(timer, timerDeserialized, "deployment");
    assertEqualsByReflection(timer, timerDeserialized, "transacted");
    assertEqualsByReflection(timer, timerDeserialized, "retryAttempts");
}
Also used : EjbTimerServiceImpl(org.apache.openejb.core.timer.EjbTimerServiceImpl) EjbTimerService(org.apache.openejb.core.timer.EjbTimerService) Test(org.junit.Test)

Example 7 with EjbTimerService

use of org.apache.openejb.core.timer.EjbTimerService in project tomee by apache.

the class BaseContext method getTimerService.

public TimerService getTimerService() throws IllegalStateException {
    doCheck(Call.getTimerService);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext beanContext = threadContext.getBeanContext();
    final EjbTimerService timerService = beanContext.getEjbTimerService();
    if (timerService == null) {
        throw new IllegalStateException("This ejb does not support timers " + beanContext.getDeploymentID());
    } else if (!timerService.isStarted()) {
        try {
            timerService.start();
        } catch (final OpenEJBException e) {
            throw new IllegalStateException(e);
        }
    }
    return new TimerServiceImpl(timerService, threadContext.getPrimaryKey(), beanContext.getEjbTimeout()) {

        @Override
        public Collection<Timer> getAllTimers() throws IllegalStateException, EJBException {
            // allowed here
            return Timers.all();
        }
    };
}
Also used : BeanContext(org.apache.openejb.BeanContext) OpenEJBException(org.apache.openejb.OpenEJBException) Timer(javax.ejb.Timer) TimerServiceImpl(org.apache.openejb.core.timer.TimerServiceImpl) EjbTimerService(org.apache.openejb.core.timer.EjbTimerService)

Aggregations

EjbTimerService (org.apache.openejb.core.timer.EjbTimerService)7 BeanContext (org.apache.openejb.BeanContext)4 Timer (javax.ejb.Timer)3 EjbTimerServiceImpl (org.apache.openejb.core.timer.EjbTimerServiceImpl)3 EJBLocalObject (javax.ejb.EJBLocalObject)2 EJBObject (javax.ejb.EJBObject)2 MethodContext (org.apache.openejb.MethodContext)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 CalendarTimerData (org.apache.openejb.core.timer.CalendarTimerData)1 ScheduleData (org.apache.openejb.core.timer.ScheduleData)1 TimerServiceImpl (org.apache.openejb.core.timer.TimerServiceImpl)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1 Test (org.junit.Test)1