Package javax.ejb

Examples of javax.ejb.Timer


        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);
            }
        }
    }
View Full Code Here


    @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);
            }
            Thread.sleep(300); //if they were backed up we give them some time to run
            int timerServiceCount = SuspendTimerServiceBean.getTimerServiceCount();
            Assert.assertTrue("Interval " + (System.currentTimeMillis() - start) + " count " + timerServiceCount, timerServiceCount < 40);
        } finally {
            if (timer != null) {
                timer.cancel();
                Thread.sleep(100);
            }
        }
    }
View Full Code Here

    @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
                }
            }
View Full Code Here

        checkState();

        Collection<Timer> timers = new ArrayList<Timer>();
        for (Iterator iterator = timerStore.getTimers((String)deployment.getDeploymentID()).iterator(); iterator.hasNext();) {
            TimerData timerData = (TimerData) iterator.next();
            Timer timer = timerData.getTimer();
            timers.add(timer);
        }
        return timers;
    }
View Full Code Here

     *
     * @param timerData the timer to call.
     */
    private void ejbTimeout(TimerData timerData) {
        try {
            Timer timer = getTimer(timerData.getId());
            if (timer == null) {
                return;
            }

            for (int tries = 0; tries < (1 + retryAttempts); tries++) {
View Full Code Here

        }
        final EjbTimerService timerService = beanContext.getEjbTimerService();
        if (timerService == null) {
            throw new NoSuchObjectLocalException("Deployment no longer supports ejbTimout " + deploymentId + ". Has this ejb been redeployed?");
        }
        final Timer timer = timerService.getTimer(id);
        if (timer == null) {
            throw new NoSuchObjectLocalException("Timer not found for ejb " + deploymentId);
        }
        return timer;
    }
View Full Code Here

     * @param timerData the timer to call.
     */
    @SuppressWarnings("ReturnInsideFinallyBlock")
    public void ejbTimeout(final TimerData timerData) {
        try {
            Timer timer = getTimer(timerData.getId());
            // quartz can be backed by some advanced config (jdbc for instance)
            if (timer == null && timerStore instanceof MemoryTimerStore && timerData.getTimer() != null) {
                try {
                    timerStore.addTimerData(timerData);
                    timer = timerData.getTimer(); // TODO: replace memoryjobstore by the db one?
View Full Code Here

     * @param timerData the timer to call.
     */
    @SuppressWarnings("ReturnInsideFinallyBlock")
    public void ejbTimeout(final TimerData timerData) {
        try {
            Timer timer = getTimer(timerData.getId());
            // quartz can be backed by some advanced config (jdbc for instance)
            if (timer == null && timerStore instanceof MemoryTimerStore && timerData.getTimer() != null) {
                try {
                    timerStore.addTimerData(timerData);
                    timer = timerData.getTimer(); // TODO: replace memoryjobstore by the db one?
View Full Code Here

        public Timer getTimer()
            throws IllegalStateException,
                   NoSuchObjectLocalException,
                   EJBException
        {
            Timer timer = (Timer) instance().call(new Callable() {
                public Object call()
                {
                    try
                    {
                        return handle.getTimer();
View Full Code Here

     * @param timerData the timer to call.
     */
    @SuppressWarnings("ReturnInsideFinallyBlock")
    public void ejbTimeout(final TimerData timerData) {
        try {
            Timer timer = getTimer(timerData.getId());
            // quartz can be backed by some advanced config (jdbc for instance)
            if (timer == null && timerStore instanceof MemoryTimerStore && timerData.getTimer() != null) {
                try {
                    timerStore.addTimerData(timerData);
                    timer = timerData.getTimer(); // TODO: replace memoryjobstore by the db one?
View Full Code Here

TOP

Related Classes of javax.ejb.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.