[Jboss-cvs] JBossAS SVN: r56169 - in trunk/ejb3: . src/main/org/jboss/ejb3/mdb src/main/org/jboss/ejb3/service src/main/org/jboss/ejb3/stateless src/main/org/jboss/ejb3/timerservice src/main/org/jboss/ejb3/timerservice/jboss src/main/org/jboss/ejb3/timerservice/quartz src/main/org/jboss/ejb3/timerservice/quartz/jmx src/resources src/resources/standalone

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 23 04:21:52 EDT 2006


Author: wolfc
Date: 2006-08-23 04:21:08 -0400 (Wed, 23 Aug 2006)
New Revision: 56169

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html
Removed:
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/PersistentTimer.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/QuartzTimerJob.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jmx/
Modified:
   trunk/ejb3/.classpath
   trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerService.java
   trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerServiceMBean.java
   trunk/ejb3/src/resources/ejb3-timer-service.xml
   trunk/ejb3/src/resources/standalone/embedded-jboss-beans.xml
Log:
EJBTHREE-619: timer service factory configurable

Modified: trunk/ejb3/.classpath
===================================================================
--- trunk/ejb3/.classpath	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/.classpath	2006-08-23 08:21:08 UTC (rev 56169)
@@ -68,11 +68,7 @@
 	<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/remoting/lib/jboss-remoting.jar"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/server">
-		<accessrules>
-			<accessrule kind="nonaccessible" pattern="org/jboss/ejb/txtimer/**"/>
-		</accessrules>
-	</classpathentry>
+	<classpathentry combineaccessrules="false" kind="src" path="/server"/>
 	<classpathentry kind="lib" path="/thirdparty/hibernate-entitymanager/lib/ejb3-persistence.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/sun-servlet/lib/servlet-api.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/apache-httpclient/lib/commons-httpclient.jar"/>

Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -146,7 +146,7 @@
          
       innerStart();
 
-      timerService = TimerServiceFactory.createTimerService(this.getObjectName(), this);
+      timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
 
       startProxies();
    }
@@ -275,7 +275,7 @@
    {
       if (timerService != null)
       {
-         TimerServiceFactory.removeTimerService(timerService);
+         TimerServiceFactory.getInstance().removeTimerService(timerService);
       }
 
       stopProxies();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -140,7 +140,7 @@
          initBeanContext();
 
          // make sure the timer service is there before injection takes place
-         timerService = TimerServiceFactory.createTimerService(this.getObjectName(), this);
+         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
 
          injectDependencies(beanContext);
 
@@ -155,7 +155,7 @@
 
    public void stop() throws Exception
    {
-      if (timerService != null) TimerServiceFactory.removeTimerService(timerService);
+      if (timerService != null) TimerServiceFactory.getInstance().removeTimerService(timerService);
 
       super.stop();
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -95,7 +95,7 @@
       {
          super.start();
          //timerService = EjbTimerUtil.getTimerService(this, this);
-         timerService = TimerServiceFactory.createTimerService(this.getObjectName(), this);
+         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
       }
       catch (Exception e)
       {
@@ -114,7 +114,7 @@
    public void stop() throws Exception
    {
       //if (timerService != null) EjbTimerUtil.removeTimerService(this);
-      if (timerService != null) TimerServiceFactory.removeTimerService(timerService);
+      if (timerService != null) TimerServiceFactory.getInstance().removeTimerService(timerService);
       super.stop();
    }
 

Deleted: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/PersistentTimer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/PersistentTimer.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/PersistentTimer.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -1,95 +0,0 @@
-/*
-  * 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.timerservice;
-
-import java.io.Serializable;
-
-import javax.ejb.EJBException;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.Timer;
-import javax.ejb.TimerHandle;
-import javax.management.ObjectName;
-
-import org.jboss.ejb3.Ejb3Registry;
-import org.jboss.logging.Logger;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.Trigger;
-
-/**
- * This class contains all the info for find a persistent timer.
- *
- * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
- * @version $Revision$
- */
-public class PersistentTimer implements Serializable, TimerHandle
-{
-   private static final Logger log = Logger.getLogger(PersistentTimer.class);
-   
-   private static final long serialVersionUID = 1L;
-
-   //private String schedulerName;
-   //private String jobName;
-   //private String jobGroup;
-   private String triggerName;
-   private String triggerGroup;
-   private ObjectName objectName;
-   
-   private Serializable info;
-   
-   protected PersistentTimer(Trigger trigger, ObjectName objectName, Serializable info)
-   {
-      assert trigger != null;
-      assert objectName != null;
-      
-      this.triggerName = trigger.getName();
-      this.triggerGroup = trigger.getGroup();
-      this.objectName = objectName;
-      this.info = info;
-   }
-   
-   protected TimedObjectInvoker getTimedObjectInvoker()
-   {
-      // TODO: a hack to get back the container. This needs thinking.
-      TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(objectName.getCanonicalName());
-      assert invoker != null;
-      return invoker;
-   }
-   
-   public Timer getTimer() throws IllegalStateException, NoSuchObjectLocalException, EJBException
-   {
-      // TODO: check state
-      try
-      {
-         Scheduler scheduler = TimerServiceFactory.getScheduler();
-         Trigger trigger = scheduler.getTrigger(triggerName, triggerGroup);
-         if(trigger == null)
-            throw new NoSuchObjectLocalException("can't find trigger '" + triggerName + "' in group '" + triggerGroup + "'");
-         return new TimerImpl(scheduler, trigger, info);
-      }
-      catch(SchedulerException e)
-      {
-         log.error("getTimer failed", e);
-         throw new EJBException(e);
-      }
-   }
-}

Deleted: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/QuartzTimerJob.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/QuartzTimerJob.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/QuartzTimerJob.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -1,47 +0,0 @@
-/*
-  * 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.timerservice;
-
-import org.quartz.Job;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-
-/**
- * Comment
- *
- * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
- * @version $Revision$
- */
-public class QuartzTimerJob implements Job
-{
-   public void execute(JobExecutionContext context) throws JobExecutionException
-   {
-      PersistentTimer timer = (PersistentTimer) context.getJobDetail().getJobDataMap().get("timer");
-      TimedObjectInvoker invoker = timer.getTimedObjectInvoker();
-      try {
-         invoker.callTimeout(timer.getTimer());
-      }
-      catch(Exception e) {
-         throw new JobExecutionException(e);
-      }
-   }  
-}

Deleted: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -1,47 +0,0 @@
-/*
- * 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.timerservice;
-
-// $Id$
-
-import javax.ejb.Timer;
-
-/**
- * An implementation can invoke the ejbTimeout method on a TimedObject.
- *
- * The TimedObjectInvoker has knowledge of the TimedObjectId, it
- * knows which object to invoke.
- *
- * @author Thomas.Diesler at jboss.org
- * @version $Revision$
- * @since 07-Apr-2004
- */
-public interface TimedObjectInvoker
-{
-   /**
-    * Invokes the ejbTimeout method on the TimedObject with the given id.
-    *
-    * @param timer the Timer that is passed to ejbTimeout
-    */
-   void callTimeout(Timer timer) throws Exception;
-
-}

Added: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,47 @@
+/*
+ * 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.timerservice;
+
+// $Id: TimedObjectInvoker.java,v 1.1 2006/06/07 09:26:15 wolfc Exp $
+
+import javax.ejb.Timer;
+
+/**
+ * An implementation can invoke the ejbTimeout method on a TimedObject.
+ *
+ * The TimedObjectInvoker has knowledge of the TimedObjectId, it
+ * knows which object to invoke.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @version $Revision: 1.1 $
+ * @since 07-Apr-2004
+ */
+public interface TimedObjectInvoker extends org.jboss.ejb.txtimer.TimedObjectInvoker
+{
+   /**
+    * Invokes the ejbTimeout method on the TimedObject with the given id.
+    *
+    * @param timer the Timer that is passed to ejbTimeout
+    */
+   void callTimeout(Timer timer) throws Exception;
+
+}

Deleted: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerImpl.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerImpl.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -1,152 +0,0 @@
-/*
-  * 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.timerservice;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.ejb.EJBException;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.Timer;
-import javax.ejb.TimerHandle;
-
-import org.jboss.logging.Logger;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.Trigger;
-
-/**
- * A view on an actual (persistent) timer.
- * 
- * This object must never be serializable (EJB3 18.4.1)
- *
- * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
- * @version $Revision$
- */
-public class TimerImpl implements Timer
-{
-   private static final Logger log = Logger.getLogger(TimerImpl.class);
-   
-   private Scheduler scheduler;
-   private Trigger trigger;
-   private Serializable info;
-   
-   protected TimerImpl(Scheduler scheduler, Trigger trigger, Serializable info) {
-      assert scheduler != null;
-      assert trigger != null;
-      
-      this.scheduler = scheduler;
-      this.trigger = trigger;
-      this.info = info;
-   }
-   
-   protected void checkState()
-   {
-      // TODO: implement bean state checking to see if a call is allowed
-      
-      if(trigger.getNextFireTime() == null)
-         throw new NoSuchObjectLocalException("timer has expired");
-   }
-   
-   /**
-    * Cause the timer and all its associated expiration notifications to be cancelled.
-    * 
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public void cancel() throws IllegalStateException, NoSuchObjectLocalException, EJBException
-   {
-      checkState();
-      
-      try {
-         // TODO: call TimerServiceImpl.cancelTimer instead
-         scheduler.unscheduleJob(trigger.getName(), trigger.getGroup());
-      }
-      catch(SchedulerException e) {
-         log.error("cancel failed", e);
-         throw new EJBException(e.getMessage());
-      }
-   }
-
-   /**
-    * Get the number of milliseconds that will elapse before the next scheduled timer expiration.
-    * 
-    * @return   The number of milliseconds that will elapse before the next scheduled timer expiration.
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public long getTimeRemaining() throws IllegalStateException, NoSuchObjectLocalException, EJBException
-   {
-      // leave all checks to getNextTimeout
-      return getNextTimeout().getTime() - System.currentTimeMillis();
-   }
-
-   /**
-    * Get the point in time at which the next timer expiration is scheduled to occur.
-    * 
-    * @return   The point in time at which the next timer expiration is scheduled to occur.
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public Date getNextTimeout() throws IllegalStateException, NoSuchObjectLocalException, EJBException
-   {
-      checkState();
-      
-      Date nextTimeout = trigger.getNextFireTime();
-      if(nextTimeout == null)
-         throw new IllegalStateException("trigger does not have a next fire time"); // TODO: proper EJB3 state check & exception
-      return nextTimeout;
-   }
-
-   /**
-    * Get the information associated with the timer at the time of creation.
-    * 
-    * @return   The Serializable object that was passed in at timer creation, or null if the info argument passed in at timer creation was null.
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public Serializable getInfo() throws IllegalStateException, NoSuchObjectLocalException, EJBException
-   {
-      checkState();
-      
-      return info;
-   }
-
-   /**
-    * Get a serializable handle to the timer. This handle can be used at a later time to re-obtain the timer reference.
-    * 
-    * @return   A serializable handle to the timer.
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException, EJBException
-   {
-      checkState();
-      
-      return null; // FIXME: implement getHandle
-   }
-}

Deleted: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceImpl.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceImpl.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -1,232 +0,0 @@
-/*
-  * 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.timerservice;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Date;
-
-import javax.ejb.EJBException;
-import javax.ejb.Timer;
-import javax.ejb.TimerService;
-import javax.management.ObjectName;
-
-import org.jboss.logging.Logger;
-import org.quartz.JobDetail;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.SimpleTrigger;
-import org.quartz.Trigger;
-
-/**
- * Implements the EJB3 Timer Service specification (EJB3 chapter 18).
- * 
- * Each bean container has its own job and trigger group.
- *
- * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
- * @version $Revision$
- */
-public class TimerServiceImpl implements TimerService
-{
-   private static final Logger log = Logger.getLogger(TimerServiceImpl.class);
-   
-   private Scheduler scheduler;
-   private ObjectName objectName;
-   private String groupName;
-   private long jobNum = 0;
-   private long triggerNum = 0;
-   
-   protected TimerServiceImpl(Scheduler scheduler, ObjectName objectName, TimedObjectInvoker invoker) {
-      assert scheduler != null;
-      assert objectName != null;
-      assert invoker != null;
-      
-      this.scheduler = scheduler;
-      this.objectName = objectName;
-      this.groupName = objectName.getCanonicalName();
-   }
-   
-   protected Timer createTimer(Trigger trigger, Serializable info)
-   {
-      try {
-         String name = "myJob" + jobNum;
-         jobNum++;
-         
-         Class jobClass = QuartzTimerJob.class;
-         
-         Timer timer = new TimerImpl(scheduler, trigger, info);
-         
-         PersistentTimer persistentTimer = new PersistentTimer(trigger, objectName, info);
-         
-         JobDetail jobDetail = new JobDetail(name, groupName, jobClass);
-         jobDetail.getJobDataMap().put("timer", persistentTimer);
-         
-         scheduler.scheduleJob(jobDetail, trigger);
-         
-         return timer;
-      }
-      catch(SchedulerException e) {
-         // translate the exception, because the client might not have quartz
-         log.error("createTimer failed", e);
-         throw new EJBException(e.getMessage());
-      }
-      
-   }
-   
-   /**
-    * Create a single-action timer that expires after a specified duration.
-    * 
-    * @param    duration    The number of milliseconds that must elapse before the timer expires.
-    * @param    info        Application information to be delivered along with the timer expiration notification. This can be null.
-    * @return   The newly created Timer.
-    * @throws   IllegalArgumentException    If duration is negative.
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method.
-    * @throws   EJBException                If this method fails due to a system-level failure.
-    */
-   public Timer createTimer(long duration, Serializable info) throws IllegalArgumentException, IllegalStateException,
-         EJBException
-   {
-      if(duration < 0) throw new IllegalArgumentException("duration must not be negative");
-      // TODO: check state
-      
-      Date expiration = new Date(System.currentTimeMillis() + duration);
-      return createTimer(expiration, info);
-   }
-
-   /**
-    * Create an interval timer whose first expiration occurs after a specified duration, 
-    * and whose subsequent expirations occur after a specified interval.
-    * 
-    * @param    initialDuration     The number of milliseconds that must elapse before the first timer expiration notification.
-    * @param    intervalDuration    The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
-    * @param    info                Application information to be delivered along with the timer expiration. This can be null.
-    * @return   The newly created Timer.
-    * @throws   IllegalArgumentException    If initialDuration is negative, or intervalDuration is negative. 
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public Timer createTimer(long initialDuration, long intervalDuration, Serializable info)
-         throws IllegalArgumentException, IllegalStateException, EJBException
-   {
-      if(initialDuration < 0) throw new IllegalArgumentException("initialDuration must not be negative");
-      if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
-      // TODO: check state
-      
-      Date initialExpiration = new Date(System.currentTimeMillis() + initialDuration);
-      
-      return createTimer(initialExpiration, intervalDuration, info);
-   }
-
-   /**
-    * Create a single-action timer that expires at a given point in time.
-    * 
-    * @param    expiration  The point in time at which the timer must expire.
-    * @param    info        Application information to be delivered along with the timer expiration notification. This can be null. 
-    * @return   The newly created Timer. 
-    * @throws   IllegalArgumentException    If expiration is null, or expiration.getTime() is negative. 
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public Timer createTimer(Date expiration, Serializable info) throws IllegalArgumentException, IllegalStateException,
-         EJBException
-   {
-      if(expiration == null) throw new IllegalArgumentException("expiration must not be null");
-      if(expiration.getTime() < 0) throw new IllegalArgumentException("expiration.time must not be negative");
-      // TODO: check state
-      
-      String triggerName = "myTrigger" + triggerNum;
-      triggerNum++;
-      
-      Trigger trigger = new SimpleTrigger(triggerName, groupName, expiration);
-      
-      return createTimer(trigger, info);
-   }
-
-   /**
-    * Create an interval timer whose first expiration occurs at a given point in time and whose subsequent expirations occur after a specified interval.
-    * 
-    * @param    initialExpiration   The point in time at which the first timer expiration must occur.
-    * @param    intervalDuration    The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
-    * @param    info                Application information to be delivered along with the timer expiration notification. This can be null. 
-    * @return   The newly created Timer. 
-    * @throws   IllegalArgumentException    If initialExpiration is null, or initialExpiration.getTime() is negative, or intervalDuration is negative. 
-    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
-    * @throws   EJBException                If this method could not complete due to a system-level failure.
-    */
-   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info)
-         throws IllegalArgumentException, IllegalStateException, EJBException
-   {
-      if(initialExpiration == null) throw new IllegalArgumentException("initialExpiration must not be null");
-      if(initialExpiration.getTime() < 0) throw new IllegalArgumentException("initialExpiration.time must not be negative");
-      if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
-      // TODO: check state
-      
-      String triggerName = "myTrigger" + triggerNum;
-      triggerNum++;
-      Date endTime = null;
-      
-      Trigger trigger = new SimpleTrigger(triggerName, groupName, initialExpiration, endTime, SimpleTrigger.REPEAT_INDEFINITELY, intervalDuration);
-      
-      return createTimer(trigger, info);
-   }
-
-   protected Scheduler getScheduler()
-   {
-      return scheduler;
-   }
-
-   /**
-    * Get all the active timers associated with this bean.
-    * 
-    * @return   A collection of javax.ejb.Timer objects.
-    * @throws   IllegalStateException   If this method is invoked while the instance is in a state that does not allow access to this method.
-    * @throws   EJBException            If this method could not complete due to a system-level failure.
-    */
-   public Collection getTimers() throws IllegalStateException, EJBException
-   {
-      throw new RuntimeException("NYI");
-   }
-
-   protected void shutdown()
-   {
-      log.info("shutting down " + this);
-      try
-      {
-         String triggerNames[] = scheduler.getTriggerNames(groupName);
-         for(String triggerName : triggerNames)
-            scheduler.unscheduleJob(triggerName, groupName);
-         String jobNames[] = scheduler.getJobNames(groupName);
-         for(String jobName : jobNames)
-            scheduler.deleteJob(jobName, groupName);
-      }
-      catch(SchedulerException e)
-      {
-         log.error("shutdown failed", e);
-         // TODO: ignore?
-      }
-   }
-   
-   public String toString()
-   {
-      return "Timer Service " + objectName;
-   }
-}

Added: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,100 @@
+/*
+ * 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.timerservice.jboss;
+
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
+import org.jboss.ejb.txtimer.EJBTimerService;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanServerLocator;
+
+/**
+ * Factory to create timer services which use the JBoss EJB Timer Service.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class JBossTimerServiceFactory extends TimerServiceFactory
+{
+   private static Logger log = Logger.getLogger(JBossTimerServiceFactory.class);
+   
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.timerservice.TimerServiceFactory#createTimerService(javax.management.ObjectName, org.jboss.ejb3.timerservice.TimedObjectInvoker)
+    */
+   @Override
+   public TimerService createTimerService(ObjectName objectName, TimedObjectInvoker invoker)
+   {
+      TimerService timerService = null;
+      try
+      {
+         EJBTimerService service = (EJBTimerService) MBeanProxyExt.create(EJBTimerService.class, EJBTimerService.OBJECT_NAME, MBeanServerLocator.locateJBoss());
+         timerService = new TimerServiceFacade(objectName, service.createTimerService(objectName, null, invoker));
+      }
+      catch (Exception e)
+      {
+         //throw new EJBException("Could not create timer service", e);
+         if (log.isTraceEnabled())
+         {
+            log.trace("Unable to initialize timer service", e);
+         }
+         else
+         {
+            log.trace("Unable to initialize timer service");
+         }
+      }
+      return timerService;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.timerservice.TimerServiceFactory#removeTimerService(javax.ejb.TimerService)
+    */
+   @Override
+   public void removeTimerService(TimerService timerService)
+   {
+      removeTimerService(((TimerServiceFacade) timerService).getObjectName());
+   }
+
+   protected void removeTimerService(ObjectName containerId)
+   {
+      try
+      {
+         EJBTimerService service = (EJBTimerService) MBeanProxyExt.create(EJBTimerService.class, EJBTimerService.OBJECT_NAME, MBeanServerLocator.locateJBoss());
+         service.removeTimerService(containerId, true);
+      }
+      catch (Exception e)
+      {
+         //throw new EJBException("Could not remove timer service", e);
+         if (log.isTraceEnabled())
+         {
+            log.trace("Unable to initialize timer service", e);
+         }
+         else
+         {
+            log.trace("Unable to initialize timer service");
+         }
+      }
+   }
+}

Added: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,80 @@
+/*
+ * 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.timerservice.jboss;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class TimerServiceFacade implements TimerService
+{
+   private TimerService delegate;
+   
+   private ObjectName containerId;
+   
+   protected TimerServiceFacade(ObjectName containerId, TimerService delegate)
+   {
+      this.containerId = containerId;
+      this.delegate = delegate;
+   }
+
+   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(initialExpiration, intervalDuration, info);
+   }
+
+   public Timer createTimer(Date expiration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(expiration, info);
+   }
+
+   public Timer createTimer(long initialDuration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(initialDuration, intervalDuration, info);
+   }
+
+   public Timer createTimer(long duration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(duration, info);
+   }
+
+   public Collection getTimers() throws IllegalStateException, EJBException
+   {
+      return delegate.getTimers();
+   }
+   
+   protected ObjectName getObjectName()
+   {
+      return containerId;
+   }
+}

Copied: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java (from rev 56095, trunk/ejb3/src/main/org/jboss/ejb3/timerservice/PersistentTimer.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/PersistentTimer.java	2006-08-19 14:20:06 UTC (rev 56095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,96 @@
+/*
+  * 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.timerservice.quartz;
+
+import java.io.Serializable;
+
+import javax.ejb.EJBException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.Timer;
+import javax.ejb.TimerHandle;
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.Ejb3Registry;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.logging.Logger;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+
+/**
+ * This class contains all the info for find a persistent timer.
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+public class PersistentTimer implements Serializable, TimerHandle
+{
+   private static final Logger log = Logger.getLogger(PersistentTimer.class);
+   
+   private static final long serialVersionUID = 1L;
+
+   //private String schedulerName;
+   //private String jobName;
+   //private String jobGroup;
+   private String triggerName;
+   private String triggerGroup;
+   private ObjectName objectName;
+   
+   private Serializable info;
+   
+   protected PersistentTimer(Trigger trigger, ObjectName objectName, Serializable info)
+   {
+      assert trigger != null;
+      assert objectName != null;
+      
+      this.triggerName = trigger.getName();
+      this.triggerGroup = trigger.getGroup();
+      this.objectName = objectName;
+      this.info = info;
+   }
+   
+   protected TimedObjectInvoker getTimedObjectInvoker()
+   {
+      // TODO: a hack to get back the container. This needs thinking.
+      TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(objectName.getCanonicalName());
+      assert invoker != null;
+      return invoker;
+   }
+   
+   public Timer getTimer() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      // TODO: check state
+      try
+      {
+         Scheduler scheduler = QuartzTimerServiceFactory.getScheduler();
+         Trigger trigger = scheduler.getTrigger(triggerName, triggerGroup);
+         if(trigger == null)
+            throw new NoSuchObjectLocalException("can't find trigger '" + triggerName + "' in group '" + triggerGroup + "'");
+         return new TimerImpl(scheduler, trigger, info);
+      }
+      catch(SchedulerException e)
+      {
+         log.error("getTimer failed", e);
+         throw new EJBException(e);
+      }
+   }
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java (from rev 56095, trunk/ejb3/src/main/org/jboss/ejb3/timerservice/QuartzTimerJob.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/QuartzTimerJob.java	2006-08-19 14:20:06 UTC (rev 56095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,48 @@
+/*
+  * 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.timerservice.quartz;
+
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+public class QuartzTimerJob implements Job
+{
+   public void execute(JobExecutionContext context) throws JobExecutionException
+   {
+      PersistentTimer timer = (PersistentTimer) context.getJobDetail().getJobDataMap().get("timer");
+      TimedObjectInvoker invoker = timer.getTimedObjectInvoker();
+      try {
+         invoker.callTimeout(timer.getTimer());
+      }
+      catch(Exception e) {
+         throw new JobExecutionException(e);
+      }
+   }  
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,269 @@
+/*
+  * 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.timerservice.quartz;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
+import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionManagerService;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.impl.StdSchedulerFactory;
+import org.quartz.utils.DBConnectionManager;
+import org.quartz.utils.JNDIConnectionProvider;
+
+/**
+ * Creates timer service objects for use in EJB3 containers. For this
+ * two methods are provided: createTimerService and removeTimerService.
+ * 
+ * The factory can be started and stopped within both an embedded and full stack.
+ * 
+ * For now only one scheduler is supported. Each bean container has its own
+ * job and trigger group within Quartz.
+ * 
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56116 $
+ */
+public class QuartzTimerServiceFactory extends TimerServiceFactory
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(QuartzTimerServiceFactory.class);
+   
+   private TransactionManager tm;
+   
+   private static Scheduler scheduler;
+   
+   private Properties properties;
+   
+   /**
+    * Contains the sql statements to create the database schema.
+    */
+   private Properties sqlProperties;
+   
+   private void createSchema()
+   {
+      try
+      {
+         tm.begin();
+         try
+         {
+            Connection conn = getConnection();
+            try
+            {
+               boolean success = execute(conn, "CREATE_TABLE_JOB_DETAILS");
+               if(success)
+               {
+                  execute(conn, "CREATE_TABLE_JOB_LISTENERS");
+                  execute(conn, "CREATE_TABLE_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_SIMPLE_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_CRON_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_BLOB_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_TRIGGER_LISTENERS");
+                  execute(conn, "CREATE_TABLE_CALENDARS");
+                  execute(conn, "CREATE_TABLE_PAUSED_TRIGGER_GRPS");
+                  execute(conn, "CREATE_TABLE_FIRED_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_SCHEDULER_STATE");
+                  execute(conn, "CREATE_TABLE_LOCKS");
+                  
+                  execute(conn, "INSERT_TRIGGER_ACCESS");
+                  execute(conn, "INSERT_JOB_ACCESS");
+                  execute(conn, "INSERT_CALENDAR_ACCESS");
+                  execute(conn, "INSERT_STATE_ACCESS");
+                  execute(conn, "INSERT_MISFIRE_ACCESS");
+               }
+            }
+            finally
+            {
+               conn.close();
+            }
+            tm.commit();
+         }
+         catch(SQLException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (RollbackException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (HeuristicMixedException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (HeuristicRollbackException e)
+         {
+            throw new RuntimeException(e);
+         }
+         finally
+         {
+            if(tm.getStatus() == Status.STATUS_ACTIVE)
+               tm.rollback();
+         }
+      }
+      catch(SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (NotSupportedException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   /**
+    * Create a TimerService for use in a bean container.
+    * 
+    * @param objectName the name of the bean container
+    * @param invoker    the invoker to call on timeouts
+    * @return           an EJB TimerService
+    */
+   public TimerService createTimerService(ObjectName objectName, TimedObjectInvoker invoker)
+   {
+      Scheduler scheduler = getScheduler();
+      if (scheduler == null) return null;
+      
+      return new TimerServiceImpl(scheduler, objectName, invoker);
+   }
+   
+   private boolean execute(Connection conn, String stmtName) throws SQLException
+   {
+      String sql = sqlProperties.getProperty(stmtName);
+      if(sql == null)
+         throw new IllegalStateException("No sql set for '" + stmtName + "'");
+      
+      PreparedStatement stmt = conn.prepareStatement(sql);
+      try
+      {
+         stmt.execute();
+         return true;
+      }
+      catch(SQLException e)
+      {
+         log.warn("sql failed: " + sql);
+         if(log.isDebugEnabled())
+            log.debug("sql failed: " + sql, e);
+         return false;
+      }
+      finally
+      {
+         stmt.close();
+      }
+   }
+   
+   private Connection getConnection() throws SQLException
+   {
+      return DBConnectionManager.getInstance().getConnection("myDS");
+   }
+   
+   /**
+    * @return   the scheduler for package use
+    */
+   protected static Scheduler getScheduler()
+   {
+      if(scheduler == null)
+      {
+         return null;
+         //throw new IllegalStateException("TimerServiceFactory hasn't been started yet");
+      }
+      
+      return scheduler;
+   }
+   
+   public void removeTimerService(TimerService aTimerService)
+   {
+      TimerServiceImpl timerService = (TimerServiceImpl) aTimerService;
+      timerService.shutdown();
+   }
+   
+   public void setDataSource(String jndiName)
+   {
+      JNDIConnectionProvider connectionProvider = new JNDIConnectionProvider(jndiName, false);
+      // FIXME: remove hardcoding
+      DBConnectionManager.getInstance().addConnectionProvider("myDS", connectionProvider);
+   }
+   
+   public void setProperties(final Properties props)
+   {
+//      if(scheduler != null)
+//         throw new IllegalStateException("already started");
+      
+      // TODO: precondition the prop
+      properties = props;
+   }
+   
+   public void setSqlProperties(Properties props)
+   {
+      this.sqlProperties = props;
+   }
+   
+   public synchronized void start() throws Exception
+   {
+      if(scheduler != null)
+         throw new IllegalStateException("already started");
+      
+      log.debug("properties = " + properties);
+      
+      InitialContext ctx = new InitialContext();
+      tm = (TransactionManager) ctx.lookup(TransactionManagerService.JNDI_NAME);
+      
+      createSchema();
+      
+      // TODO: bind in JNDI, or is this done by the JMX bean?
+      SchedulerFactory factory;
+      if(properties == null)
+         factory = new StdSchedulerFactory();
+      else
+         factory = new StdSchedulerFactory(properties);
+      scheduler = factory.getScheduler();
+      // TODO: really start right away?
+      scheduler.start();
+   }
+   
+   public synchronized void stop() throws Exception
+   {
+      if(scheduler == null)
+         throw new IllegalStateException("already stopped");
+      
+      // TODO: unbind from JNDI
+      
+      // TODO: standby or shutdown?
+      scheduler.shutdown();
+      
+      scheduler = null;
+   }
+}

Copied: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java (from rev 56095, trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerImpl.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerImpl.java	2006-08-19 14:20:06 UTC (rev 56095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,152 @@
+/*
+  * 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.timerservice.quartz;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.Timer;
+import javax.ejb.TimerHandle;
+
+import org.jboss.logging.Logger;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+
+/**
+ * A view on an actual (persistent) timer.
+ * 
+ * This object must never be serializable (EJB3 18.4.1)
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+public class TimerImpl implements Timer
+{
+   private static final Logger log = Logger.getLogger(TimerImpl.class);
+   
+   private Scheduler scheduler;
+   private Trigger trigger;
+   private Serializable info;
+   
+   protected TimerImpl(Scheduler scheduler, Trigger trigger, Serializable info) {
+      assert scheduler != null;
+      assert trigger != null;
+      
+      this.scheduler = scheduler;
+      this.trigger = trigger;
+      this.info = info;
+   }
+   
+   protected void checkState()
+   {
+      // TODO: implement bean state checking to see if a call is allowed
+      
+      if(trigger.getNextFireTime() == null)
+         throw new NoSuchObjectLocalException("timer has expired");
+   }
+   
+   /**
+    * Cause the timer and all its associated expiration notifications to be cancelled.
+    * 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public void cancel() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      try {
+         // TODO: call TimerServiceImpl.cancelTimer instead
+         scheduler.unscheduleJob(trigger.getName(), trigger.getGroup());
+      }
+      catch(SchedulerException e) {
+         log.error("cancel failed", e);
+         throw new EJBException(e.getMessage());
+      }
+   }
+
+   /**
+    * Get the number of milliseconds that will elapse before the next scheduled timer expiration.
+    * 
+    * @return   The number of milliseconds that will elapse before the next scheduled timer expiration.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public long getTimeRemaining() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      // leave all checks to getNextTimeout
+      return getNextTimeout().getTime() - System.currentTimeMillis();
+   }
+
+   /**
+    * Get the point in time at which the next timer expiration is scheduled to occur.
+    * 
+    * @return   The point in time at which the next timer expiration is scheduled to occur.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Date getNextTimeout() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      Date nextTimeout = trigger.getNextFireTime();
+      if(nextTimeout == null)
+         throw new IllegalStateException("trigger does not have a next fire time"); // TODO: proper EJB3 state check & exception
+      return nextTimeout;
+   }
+
+   /**
+    * Get the information associated with the timer at the time of creation.
+    * 
+    * @return   The Serializable object that was passed in at timer creation, or null if the info argument passed in at timer creation was null.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Serializable getInfo() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      return info;
+   }
+
+   /**
+    * Get a serializable handle to the timer. This handle can be used at a later time to re-obtain the timer reference.
+    * 
+    * @return   A serializable handle to the timer.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      return null; // FIXME: implement getHandle
+   }
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java (from rev 56095, trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceImpl.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceImpl.java	2006-08-19 14:20:06 UTC (rev 56095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,233 @@
+/*
+  * 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.timerservice.quartz;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.logging.Logger;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+
+/**
+ * Implements the EJB3 Timer Service specification (EJB3 chapter 18).
+ * 
+ * Each bean container has its own job and trigger group.
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+public class TimerServiceImpl implements TimerService
+{
+   private static final Logger log = Logger.getLogger(TimerServiceImpl.class);
+   
+   private Scheduler scheduler;
+   private ObjectName objectName;
+   private String groupName;
+   private long jobNum = 0;
+   private long triggerNum = 0;
+   
+   protected TimerServiceImpl(Scheduler scheduler, ObjectName objectName, TimedObjectInvoker invoker) {
+      assert scheduler != null;
+      assert objectName != null;
+      assert invoker != null;
+      
+      this.scheduler = scheduler;
+      this.objectName = objectName;
+      this.groupName = objectName.getCanonicalName();
+   }
+   
+   protected Timer createTimer(Trigger trigger, Serializable info)
+   {
+      try {
+         String name = "myJob" + jobNum;
+         jobNum++;
+         
+         Class jobClass = QuartzTimerJob.class;
+         
+         Timer timer = new TimerImpl(scheduler, trigger, info);
+         
+         PersistentTimer persistentTimer = new PersistentTimer(trigger, objectName, info);
+         
+         JobDetail jobDetail = new JobDetail(name, groupName, jobClass);
+         jobDetail.getJobDataMap().put("timer", persistentTimer);
+         
+         scheduler.scheduleJob(jobDetail, trigger);
+         
+         return timer;
+      }
+      catch(SchedulerException e) {
+         // translate the exception, because the client might not have quartz
+         log.error("createTimer failed", e);
+         throw new EJBException(e.getMessage());
+      }
+      
+   }
+   
+   /**
+    * Create a single-action timer that expires after a specified duration.
+    * 
+    * @param    duration    The number of milliseconds that must elapse before the timer expires.
+    * @param    info        Application information to be delivered along with the timer expiration notification. This can be null.
+    * @return   The newly created Timer.
+    * @throws   IllegalArgumentException    If duration is negative.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method.
+    * @throws   EJBException                If this method fails due to a system-level failure.
+    */
+   public Timer createTimer(long duration, Serializable info) throws IllegalArgumentException, IllegalStateException,
+         EJBException
+   {
+      if(duration < 0) throw new IllegalArgumentException("duration must not be negative");
+      // TODO: check state
+      
+      Date expiration = new Date(System.currentTimeMillis() + duration);
+      return createTimer(expiration, info);
+   }
+
+   /**
+    * Create an interval timer whose first expiration occurs after a specified duration, 
+    * and whose subsequent expirations occur after a specified interval.
+    * 
+    * @param    initialDuration     The number of milliseconds that must elapse before the first timer expiration notification.
+    * @param    intervalDuration    The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
+    * @param    info                Application information to be delivered along with the timer expiration. This can be null.
+    * @return   The newly created Timer.
+    * @throws   IllegalArgumentException    If initialDuration is negative, or intervalDuration is negative. 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Timer createTimer(long initialDuration, long intervalDuration, Serializable info)
+         throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      if(initialDuration < 0) throw new IllegalArgumentException("initialDuration must not be negative");
+      if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
+      // TODO: check state
+      
+      Date initialExpiration = new Date(System.currentTimeMillis() + initialDuration);
+      
+      return createTimer(initialExpiration, intervalDuration, info);
+   }
+
+   /**
+    * Create a single-action timer that expires at a given point in time.
+    * 
+    * @param    expiration  The point in time at which the timer must expire.
+    * @param    info        Application information to be delivered along with the timer expiration notification. This can be null. 
+    * @return   The newly created Timer. 
+    * @throws   IllegalArgumentException    If expiration is null, or expiration.getTime() is negative. 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Timer createTimer(Date expiration, Serializable info) throws IllegalArgumentException, IllegalStateException,
+         EJBException
+   {
+      if(expiration == null) throw new IllegalArgumentException("expiration must not be null");
+      if(expiration.getTime() < 0) throw new IllegalArgumentException("expiration.time must not be negative");
+      // TODO: check state
+      
+      String triggerName = "myTrigger" + triggerNum;
+      triggerNum++;
+      
+      Trigger trigger = new SimpleTrigger(triggerName, groupName, expiration);
+      
+      return createTimer(trigger, info);
+   }
+
+   /**
+    * Create an interval timer whose first expiration occurs at a given point in time and whose subsequent expirations occur after a specified interval.
+    * 
+    * @param    initialExpiration   The point in time at which the first timer expiration must occur.
+    * @param    intervalDuration    The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
+    * @param    info                Application information to be delivered along with the timer expiration notification. This can be null. 
+    * @return   The newly created Timer. 
+    * @throws   IllegalArgumentException    If initialExpiration is null, or initialExpiration.getTime() is negative, or intervalDuration is negative. 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info)
+         throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      if(initialExpiration == null) throw new IllegalArgumentException("initialExpiration must not be null");
+      if(initialExpiration.getTime() < 0) throw new IllegalArgumentException("initialExpiration.time must not be negative");
+      if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
+      // TODO: check state
+      
+      String triggerName = "myTrigger" + triggerNum;
+      triggerNum++;
+      Date endTime = null;
+      
+      Trigger trigger = new SimpleTrigger(triggerName, groupName, initialExpiration, endTime, SimpleTrigger.REPEAT_INDEFINITELY, intervalDuration);
+      
+      return createTimer(trigger, info);
+   }
+
+   protected Scheduler getScheduler()
+   {
+      return scheduler;
+   }
+
+   /**
+    * Get all the active timers associated with this bean.
+    * 
+    * @return   A collection of javax.ejb.Timer objects.
+    * @throws   IllegalStateException   If this method is invoked while the instance is in a state that does not allow access to this method.
+    * @throws   EJBException            If this method could not complete due to a system-level failure.
+    */
+   public Collection getTimers() throws IllegalStateException, EJBException
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   protected void shutdown()
+   {
+      log.info("shutting down " + this);
+      try
+      {
+         String triggerNames[] = scheduler.getTriggerNames(groupName);
+         for(String triggerName : triggerNames)
+            scheduler.unscheduleJob(triggerName, groupName);
+         String jobNames[] = scheduler.getJobNames(groupName);
+         for(String jobName : jobNames)
+            scheduler.deleteJob(jobName, groupName);
+      }
+      catch(SchedulerException e)
+      {
+         log.error("shutdown failed", e);
+         // TODO: ignore?
+      }
+   }
+   
+   public String toString()
+   {
+      return "Timer Service " + objectName;
+   }
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx (from rev 56095, trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jmx)

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerService.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jmx/EJB3TimerService.java	2006-08-19 14:20:06 UTC (rev 56095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerService.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -19,13 +19,13 @@
   * 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.timerservice.jmx;
+package org.jboss.ejb3.timerservice.quartz.jmx;
 
 import java.util.Properties;
 
 import javax.management.ObjectName;
 
-import org.jboss.ejb3.timerservice.TimerServiceFactory;
+import org.jboss.ejb3.timerservice.quartz.QuartzTimerServiceFactory;
 import org.jboss.system.ServiceMBeanSupport;
 
 /**
@@ -37,12 +37,12 @@
 public class EJB3TimerService extends ServiceMBeanSupport
    implements EJB3TimerServiceMBean
 {
-   private TimerServiceFactory delegate;
+   private QuartzTimerServiceFactory delegate;
    private ObjectName dataSource;
    
    public EJB3TimerService()
    {
-      delegate = new TimerServiceFactory();
+      delegate = new QuartzTimerServiceFactory();
    }
    
    @Override

Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerServiceMBean.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/jmx/EJB3TimerServiceMBean.java	2006-08-19 14:20:06 UTC (rev 56095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerServiceMBean.java	2006-08-23 08:21:08 UTC (rev 56169)
@@ -19,7 +19,7 @@
   * 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.timerservice.jmx;
+package org.jboss.ejb3.timerservice.quartz.jmx;
 
 import java.util.Properties;
 

Copied: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html (from rev 56095, trunk/ejb3/src/main/org/jboss/ejb3/timerservice/package.html)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/package.html	2006-08-19 14:20:06 UTC (rev 56095)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html	2006-08-23 08:21:08 UTC (rev 56169)
@@ -0,0 +1,17 @@
+<head>
+	<body>
+		This package provides the EJB Timer Service to the EJB3 stack.
+		<p/>
+		It replaces the org.jboss.ejb.txtimer package.
+		<p/>
+		The Jboss EJB3 Timer Service package depends on:
+		<ul>
+			<li>EJB3 API</li>
+			<li>Quartz</li>
+			<li>JTA</li>
+		</ul>
+		<p/>
+		Note that almost all exceptions are caught and rethrown as EJBExceptions, thus
+		making sure that no Quartz API is exposed either compile time or run time.
+	</body>
+</head>
\ No newline at end of file


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/ejb3/src/resources/ejb3-timer-service.xml
===================================================================
--- trunk/ejb3/src/resources/ejb3-timer-service.xml	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/resources/ejb3-timer-service.xml	2006-08-23 08:21:08 UTC (rev 56169)
@@ -6,7 +6,7 @@
 	<!--  Defines the Quartz configuration for             -->
 	<!--  the EJB3 Timer Service                           -->
 	<!--  ================================================ -->
-	<mbean code="org.jboss.ejb3.timerservice.jmx.EJB3TimerService" name="jboss.ejb:service=EJB3TimerService">
+	<mbean code="org.jboss.ejb3.timerservice.quartz.jmx.EJB3TimerService" name="jboss.ejb:service=EJB3TimerService">
 		<depends>jboss:service=Naming</depends>
 		<depends>jboss:service=TransactionManager</depends>
 		<depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>

Modified: trunk/ejb3/src/resources/standalone/embedded-jboss-beans.xml
===================================================================
--- trunk/ejb3/src/resources/standalone/embedded-jboss-beans.xml	2006-08-23 08:20:24 UTC (rev 56168)
+++ trunk/ejb3/src/resources/standalone/embedded-jboss-beans.xml	2006-08-23 08:21:08 UTC (rev 56169)
@@ -92,7 +92,7 @@
       </constructor>
    </bean>
 
-   <bean name="TimerServiceFactory" class="org.jboss.ejb3.timerservice.TimerServiceFactory">
+   <bean name="TimerServiceFactory" class="org.jboss.ejb3.timerservice.quartz.QuartzTimerServiceFactory">
       <property name="properties">
         	org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreCMT
             org.quartz.jobStore.nonManagedTXDataSource=myDS




More information about the jboss-cvs-commits mailing list