[Jboss-cvs] JBossAS SVN: r56633 - branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 7 23:15:52 EDT 2006


Author: bill.burke at jboss.com
Date: 2006-09-07 23:15:50 -0400 (Thu, 07 Sep 2006)
New Revision: 56633

Added:
   branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/BaseTimerTesterBean.java
   branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TimerTesterService.java
   branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TransactionalTimerTesterBean.java
Log:


Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/BaseTimerTesterBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/BaseTimerTesterBean.java	2006-09-08 03:15:10 UTC (rev 56632)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/BaseTimerTesterBean.java	2006-09-08 03:15:50 UTC (rev 56633)
@@ -0,0 +1,110 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.test.timer;
+
+import java.util.Date;
+
+import javax.annotation.Resource;
+import javax.ejb.SessionContext;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+import org.jboss.logging.Logger;
+
+/**
+ * This class forms the base of both an EJB3 timer tester bean and
+ * an EJB 2.1 timer tester bean.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56264 $
+ */
+public abstract class BaseTimerTesterBean
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(BaseTimerTesterBean.class);
+   
+   protected static boolean timerCalled = false;
+
+   private @Resource TimerService timerService;
+
+   protected @Resource SessionContext ctx;
+   
+   // TODO: fix this state in the stateless bean
+   private static Timer timer;
+
+   @TransactionAttribute(TransactionAttributeType.MANDATORY)
+   public void checkMandatoryTransaction()
+   {
+      
+   }
+   
+   private void reset()
+   {
+      timerCalled = false;
+      timer = null;
+   }
+   
+   public void setTimer(Date expiration)
+   {
+      reset();
+      System.out.println("************ set timer " + expiration);
+      timer = timerService.createTimer(expiration, "TimerSLSBean");
+   }
+   
+   public void startTimer(long pPeriod)
+   {
+      reset();
+      System.out.println("************ startTimer");
+      timer = timerService.createTimer(new Date(new Date().getTime() + pPeriod), "TimerSLSBean");
+   }
+
+   public void startTimerAndRollback(long pPeriod)
+   {
+      reset();
+      System.out.println("************ startTimerAndRollback");
+      timer = ctx.getTimerService().createTimer(pPeriod, "TimerSLSBean");
+      ctx.setRollbackOnly();
+   }
+
+   public void startTimerViaEJBContext(long pPeriod)
+   {
+      reset();
+      System.out.println("************ startTimerViaEJBContext");
+      timer = ctx.getTimerService().createTimer(new Date(new Date().getTime() + pPeriod), "TimerSLSBean");
+   }
+
+   public void accessTimer()
+   {
+      //Access timer to make sure we have pushed the AllowedOperationsAssociation
+      timer.getTimeRemaining();
+      timer.getHandle();
+      timer.getInfo();
+   }
+   
+   public boolean isTimerCalled()
+   {
+      return timerCalled;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TimerTesterService.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TimerTesterService.java	2006-09-08 03:15:10 UTC (rev 56632)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TimerTesterService.java	2006-09-08 03:15:50 UTC (rev 56633)
@@ -0,0 +1,50 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.test.timer;
+
+import javax.ejb.Remote;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+
+import org.jboss.annotation.ejb.Service;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 46184 $
+ */
+ at Remote(TimerTester.class)
+ at Service
+public class TimerTesterService extends BaseTimerTesterBean
+{
+   private static final Logger log = Logger.getLogger(TimerTesterService.class);
+   
+   @Timeout
+   public void timeoutHandler(Timer timer)
+   {
+      log.info("EJB TIMEOUT!!!!");
+      timerCalled = true;
+      //timer.cancel();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TransactionalTimerTesterBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TransactionalTimerTesterBean.java	2006-09-08 03:15:10 UTC (rev 56632)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/timer/TransactionalTimerTesterBean.java	2006-09-08 03:15:50 UTC (rev 56633)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.timer;
+
+import javax.annotation.Resource;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(TimerTester.class)
+public class TransactionalTimerTesterBean extends BaseTimerTesterBean
+{
+   private static final Logger log = Logger.getLogger(TransactionalTimerTesterBean.class);
+   
+   @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+   @Timeout
+   public void timeoutHandler(Timer timer)
+   {
+      log.info("EJB TIMEOUT!!!!");
+      timerCalled = true;
+      
+      TimerTester me = (TimerTester) ctx.getBusinessObject(TimerTester.class);
+      me.checkMandatoryTransaction();
+   }
+}




More information about the jboss-cvs-commits mailing list