[jboss-cvs] jboss-seam/src/main/org/jboss/seam/async ...

Gavin King gavin.king at jboss.com
Sun Jun 24 02:34:30 EDT 2007


  User: gavin   
  Date: 07/06/24 02:34:30

  Modified:    src/main/org/jboss/seam/async      AbstractDispatcher.java
                        Asynchronous.java Dispatcher.java
  Added:       src/main/org/jboss/seam/async     
                        TransactionCompletionEvent.java
                        TransactionSuccessEvent.java
  Log:
  got rid of TransactionListener, merged with the Transaction package, for more consistent behavior across diff types of tx management
  
  Revision  Changes    Path
  1.4       +11 -0     jboss-seam/src/main/org/jboss/seam/async/AbstractDispatcher.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AbstractDispatcher.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/async/AbstractDispatcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- AbstractDispatcher.java	20 Jun 2007 15:53:32 -0000	1.3
  +++ AbstractDispatcher.java	24 Jun 2007 06:34:30 -0000	1.4
  @@ -11,6 +11,7 @@
   import org.jboss.seam.annotations.timer.IntervalDuration;
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.intercept.InvocationContext;
  +import org.jboss.seam.transaction.Transaction;
   
   /**
    * Abstract Dispatcher implementation
  @@ -32,6 +33,16 @@
         return (Dispatcher) Component.getInstance("org.jboss.seam.async.dispatcher");         
      }
   
  +   public void scheduleTransactionSuccessEvent(String type, Object... parameters)
  +   {
  +      Transaction.instance().registerSynchronization( new TransactionSuccessEvent(type, parameters) );
  +   }
  +
  +   public void scheduleTransactionCompletionEvent(String type, Object... parameters)
  +   {
  +      Transaction.instance().registerSynchronization( new TransactionCompletionEvent(type, parameters) );
  +   }
  +
      // TODO: Throw exception when there are multiple interval params
      //       Make use of finalExpiration
      //       Make use of NthBusinessDay
  
  
  
  1.3       +23 -18    jboss-seam/src/main/org/jboss/seam/async/Asynchronous.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Asynchronous.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/async/Asynchronous.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- Asynchronous.java	22 Jun 2007 09:18:40 -0000	1.2
  +++ Asynchronous.java	24 Jun 2007 06:34:30 -0000	1.3
  @@ -34,13 +34,23 @@
      
      public void execute(Object timer)
      {
  -      
  -      //TODO: shouldn't this take place in a Seam context anyway??!? (bug in EJB3?)
  -      
  -      Lifecycle.beginCall();
  +      boolean createContexts = !Contexts.isEventContextActive() && !Contexts.isApplicationContextActive();
  +      if (createContexts) Lifecycle.beginCall();
         Contexts.getEventContext().set(AbstractDispatcher.EXECUTING_ASYNCHRONOUS_CALL, true);
         try
         {
  +         executeInContexts(timer);         
  +      }
  +      finally
  +      {
  +         Contexts.getEventContext().remove(AbstractDispatcher.EXECUTING_ASYNCHRONOUS_CALL);
  +         if (createContexts) Lifecycle.endCall();
  +      }
  +      
  +   }
  +
  +   private void executeInContexts(Object timer)
  +   {
            if (taskId!=null)
            {
               BusinessProcess.instance().resumeTask(taskId);
  @@ -50,17 +60,12 @@
               BusinessProcess.instance().resumeProcess(processId);
            }
            
  -         Contexts.getEventContext().set("timer", timer);
  -      
  -         call();
  -         
  -      }
  -      finally
  +      if (timer!=null)
         {
  -         Contexts.getEventContext().remove(AbstractDispatcher.EXECUTING_ASYNCHRONOUS_CALL);
  -         Lifecycle.endCall();
  +         Contexts.getEventContext().set("timer", timer);
         }
         
  +      call();
      }
      
      protected abstract void call();
  
  
  
  1.2       +22 -0     jboss-seam/src/main/org/jboss/seam/async/Dispatcher.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Dispatcher.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/async/Dispatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Dispatcher.java	19 Jun 2007 19:08:46 -0000	1.1
  +++ Dispatcher.java	24 Jun 2007 06:34:30 -0000	1.2
  @@ -23,6 +23,9 @@
      /**
       * Schedule a timed (delayed and/or periodic) event
       * 
  +    * @param type the event type
  +    * @param schedule the schedule
  +    * @param parameters parameters to pass to the event listener method
       * @return some kind of timer object, or null
       */
      public T scheduleTimedEvent(String type, S schedule, Object... parameters);
  @@ -30,8 +33,27 @@
      /**
       * Schedule an immediate asynchronous event
       * 
  +    * @param type the event type
  +    * @param parameters parameters to pass to the event listener method
       * @return some kind of timer object, or null
       */
      public T scheduleAsynchronousEvent(String type, Object... parameters);
      
  +   /**
  +    * Schedule an event to be processed if and when the current transaction 
  +    * completes successfully
  +    * 
  +    * @param type the event type
  +    * @param parameters parameters to pass to the event listener method
  +    */
  +   public void scheduleTransactionSuccessEvent(String type, Object... parameters);
  +   
  +   /**
  +    * Schedule an event to be processed when the current transaction ends
  +    * 
  +    * @param type the event type
  +    * @param parameters parameters to pass to the event listener method
  +    */
  +   public void scheduleTransactionCompletionEvent(String type, Object... parameters);
  +   
   }
  
  
  
  1.1      date: 2007/06/24 06:34:30;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/async/TransactionCompletionEvent.java
  
  Index: TransactionCompletionEvent.java
  ===================================================================
  package org.jboss.seam.async;
  
  import javax.transaction.Synchronization;
  
  /**
   * An event that is processed when a transaction ends
   * 
   * @author Gavin King
   *
   */
  public class TransactionCompletionEvent extends AsynchronousEvent implements Synchronization
  {
     public TransactionCompletionEvent(String type, Object... params)
     {
        super(type, params);
     }
     
     public void afterCompletion(int status)
     {
        execute(null); 
     }
     
     public void beforeCompletion() {}
     
  }
  
  
  
  1.1      date: 2007/06/24 06:34:30;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/async/TransactionSuccessEvent.java
  
  Index: TransactionSuccessEvent.java
  ===================================================================
  package org.jboss.seam.async;
  
  import javax.transaction.Status;
  import javax.transaction.Synchronization;
  
  /**
   * An event that is processed when a transaction completes
   * succesfully
   * 
   * @author Gavin King
   *
   */
  public class TransactionSuccessEvent extends AsynchronousEvent implements Synchronization
  {
     public TransactionSuccessEvent(String type, Object... params)
     {
        super(type, params);
     }
     
     public void afterCompletion(int status)
     {
        if (status==Status.STATUS_COMMITTED)
        {
           execute(null); 
        }
     }
     
     public void beforeCompletion() {}
     
  }
  
  
  



More information about the jboss-cvs-commits mailing list