Search in sources :

Example 1 with NoSuchObjectLocalException

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

the class ExpiredTimerTestCase method testInvocationOnExpiredTimer.

@Test
public void testInvocationOnExpiredTimer() throws Exception {
    final CountDownLatch timeoutNotifier = new CountDownLatch(1);
    final CountDownLatch timeoutWaiter = new CountDownLatch(1);
    this.bean.createSingleActionTimer(TIMER_TIMEOUT_TIME_MS, new TimerConfig(null, false), timeoutNotifier, timeoutWaiter);
    // wait for the timeout to be invoked
    final boolean timeoutInvoked = timeoutNotifier.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
    Assert.assertTrue("timeout method was not invoked (within " + TIMER_CALL_WAITING_S + " seconds)", timeoutInvoked);
    // the timer stays in timeout method - checking how the invoke of method getNext and getTimeRemaining behave
    try {
        bean.invokeTimeRemaining();
        Assert.fail("Expecting exception " + NoMoreTimeoutsException.class.getSimpleName());
    } catch (NoMoreTimeoutsException e) {
        log.trace("Expected exception " + e.getClass().getSimpleName() + " was thrown on method getTimeRemaining");
    }
    try {
        bean.invokeGetNext();
        Assert.fail("Expecting exception " + NoMoreTimeoutsException.class.getSimpleName());
    } catch (NoMoreTimeoutsException e) {
        log.trace("Expected exception " + e.getClass().getSimpleName() + " was thrown on method getNextTimeout");
    }
    // the timeout can finish
    timeoutWaiter.countDown();
    // as we can't be exactly sure when the timeout method is finished in this moment
    // we invoke in a loop, can check the exception type.
    int count = 0;
    boolean passed = false;
    while (count < 20 && !passed) {
        try {
            bean.invokeTimeRemaining();
            Assert.fail("Expected to fail on invoking on an expired timer");
        } catch (NoSuchObjectLocalException nsole) {
            // expected
            log.trace("Got the expected exception " + nsole);
            passed = true;
        } catch (NoMoreTimeoutsException e) {
            //this will be thrown if the timer is still active
            Thread.sleep(100);
            count++;
        }
    }
    if (!passed) {
        Assert.fail("Got NoMoreTimeoutsException rather than  NoSuchObjectLocalException");
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) NoMoreTimeoutsException(javax.ejb.NoMoreTimeoutsException) TimerConfig(javax.ejb.TimerConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with NoSuchObjectLocalException

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

the class TimerAttributeDefinition method addPersistent.

private static void addPersistent(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final ModelNode detailNode = timerNode.get(PERSISTENT);
        boolean b = timer.isPersistent();
        detailNode.set(b);
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

Example 3 with NoSuchObjectLocalException

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

the class TimerAttributeDefinition method addTimeRemaining.

private static void addTimeRemaining(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final ModelNode detailNode = timerNode.get(TIME_REMAINING);
        long time = timer.getTimeRemaining();
        detailNode.set(time);
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

Example 4 with NoSuchObjectLocalException

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

the class TimerAttributeDefinition method addSchedule.

private static void addSchedule(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final ModelNode schedNode = timerNode.get(SCHEDULE);
        ScheduleExpression sched = timer.getSchedule();
        addScheduleDetailString(schedNode, sched.getYear(), YEAR);
        addScheduleDetailString(schedNode, sched.getMonth(), MONTH);
        addScheduleDetailString(schedNode, sched.getDayOfMonth(), DAY_OF_MONTH);
        addScheduleDetailString(schedNode, sched.getDayOfWeek(), DAY_OF_WEEK);
        addScheduleDetailString(schedNode, sched.getHour(), HOUR);
        addScheduleDetailString(schedNode, sched.getMinute(), MINUTE);
        addScheduleDetailString(schedNode, sched.getSecond(), SECOND);
        addScheduleDetailString(schedNode, sched.getTimezone(), TIMEZONE);
        addScheduleDetailDate(schedNode, sched.getStart(), START);
        addScheduleDetailDate(schedNode, sched.getEnd(), END);
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ScheduleExpression(javax.ejb.ScheduleExpression) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

Example 5 with NoSuchObjectLocalException

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

the class TimerAttributeDefinition method addCalendarTimer.

private static void addCalendarTimer(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final ModelNode detailNode = timerNode.get(CALENDAR_TIMER);
        boolean b = timer.isCalendarTimer();
        detailNode.set(b);
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

Aggregations

NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)7 EJBException (javax.ejb.EJBException)5 ModelNode (org.jboss.dmr.ModelNode)5 Date (java.util.Date)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 NoMoreTimeoutsException (javax.ejb.NoMoreTimeoutsException)1 ScheduleExpression (javax.ejb.ScheduleExpression)1 Timer (javax.ejb.Timer)1 TimerConfig (javax.ejb.TimerConfig)1 BeanContext (org.apache.openejb.BeanContext)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1 Test (org.junit.Test)1