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

Gavin King gavin.king at jboss.com
Wed May 30 21:17:15 EDT 2007


  User: gavin   
  Date: 07/05/30 21:17:15

  Modified:    src/main/org/jboss/seam/core      AbstractDispatcher.java
                        Dispatcher.java ThreadPoolDispatcher.java
                        TimerServiceDispatcher.java
  Added:       src/main/org/jboss/seam/core     
                        LocalTimerServiceDispatcher.java
  Log:
  improvements
  
  Revision  Changes    Path
  1.2       +0 -18     jboss-seam/src/main/org/jboss/seam/core/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/core/AbstractDispatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- AbstractDispatcher.java	31 May 2007 00:55:40 -0000	1.1
  +++ AbstractDispatcher.java	31 May 2007 01:17:15 -0000	1.2
  @@ -2,7 +2,6 @@
   
   import java.io.Serializable;
   import java.lang.reflect.Method;
  -import java.util.concurrent.Callable;
   
   import org.jboss.seam.Component;
   import org.jboss.seam.contexts.Contexts;
  @@ -137,21 +136,4 @@
         
      }
      
  -    //TODO: move down to TimerServiceDispatcher!
  -    public Object call(Callable task) 
  -    {
  -        try 
  -        {
  -            return task.call();
  -        } 
  -        catch (RuntimeException e) 
  -        {
  -            // just pass along runtime exceptions
  -            throw e;
  -        } 
  -        catch (Exception e) 
  -        {
  -            throw new RuntimeException(e);
  -        }
  -    }
   }
  
  
  
  1.20      +0 -7      jboss-seam/src/main/org/jboss/seam/core/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/core/Dispatcher.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- Dispatcher.java	31 May 2007 00:55:40 -0000	1.19
  +++ Dispatcher.java	31 May 2007 01:17:15 -0000	1.20
  @@ -1,9 +1,5 @@
   package org.jboss.seam.core;
   
  -import java.util.concurrent.Callable;
  -
  -import javax.ejb.Local;
  -
   import org.jboss.seam.Component;
   import org.jboss.seam.intercept.InvocationContext;
   
  @@ -15,7 +11,6 @@
    *
    * @param <T> the type of the timer object
    */
  - at Local
   public interface Dispatcher<T, S>
   {
      /**
  @@ -38,6 +33,4 @@
       */
      public T scheduleAsynchronousEvent(String type, Object... parameters);
      
  -   //TODO: move somewhere else!
  -   public Object call(Callable task);
   }
  
  
  
  1.2       +7 -9      jboss-seam/src/main/org/jboss/seam/core/ThreadPoolDispatcher.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ThreadPoolDispatcher.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ThreadPoolDispatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- ThreadPoolDispatcher.java	31 May 2007 00:55:40 -0000	1.1
  +++ ThreadPoolDispatcher.java	31 May 2007 01:17:15 -0000	1.2
  @@ -4,8 +4,8 @@
   
   import java.util.concurrent.ExecutorService;
   import java.util.concurrent.Executors;
  +import java.util.concurrent.Future;
   
  -import javax.ejb.Timer;
   import javax.interceptor.Interceptors;
   
   import org.jboss.seam.Component;
  @@ -27,41 +27,39 @@
   @Name("org.jboss.seam.core.dispatcher")
   @Interceptors(SeamInterceptor.class)
   @Install(value=false, precedence=BUILT_IN)
  -public class ThreadPoolDispatcher extends AbstractDispatcher
  +public class ThreadPoolDispatcher extends AbstractDispatcher<Future, Object>
   {
      private ExecutorService executor = Executors.newCachedThreadPool();
       
  -   public Object scheduleTimedEvent(String type, Object schedule, Object... parameters)
  +   public Future scheduleTimedEvent(String type, Object schedule, Object... parameters)
      {
         throw new UnsupportedOperationException();
      }
      
  -   public Object scheduleAsynchronousEvent(String type, Object... parameters)
  +   public Future scheduleAsynchronousEvent(String type, Object... parameters)
      {  
         final Asynchronous event = new AsynchronousEvent(type, parameters);
  -      executor.execute( new Runnable() {
  +      return executor.submit( new Runnable() {
            public void run()
            {
               event.execute(null);
            }
         } );
  -      return null;
      }
       
  -   public Timer scheduleInvocation(InvocationContext invocation, Component component)
  +   public Future scheduleInvocation(InvocationContext invocation, Component component)
      {
         final Asynchronous call = new AsynchronousInvocation( 
                  invocation.getMethod(),
                  component.getName(),
                  invocation.getParameters() 
               );
  -      executor.execute( new Runnable() {
  +      return executor.submit( new Runnable() {
            public void run()
            {
               call.execute(null);
            }
         } );
  -      return null;
      }
      
   }
  
  
  
  1.2       +56 -44    jboss-seam/src/main/org/jboss/seam/core/TimerServiceDispatcher.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TimerServiceDispatcher.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/TimerServiceDispatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- TimerServiceDispatcher.java	31 May 2007 00:55:40 -0000	1.1
  +++ TimerServiceDispatcher.java	31 May 2007 01:17:15 -0000	1.2
  @@ -40,7 +40,7 @@
   @Install(value=false, precedence=BUILT_IN)
   public class TimerServiceDispatcher 
      extends AbstractDispatcher<Timer, TimerServiceSchedule>
  -   implements Dispatcher<Timer, TimerServiceSchedule> //workaround a bug in JBoss EJB3
  +   implements LocalTimerServiceDispatcher
   {
      
      @Resource TimerService timerService;
  @@ -150,18 +150,13 @@
               this.timer = timer;
           }
           
  -        private Object callInContext(Callable callable) 
  -        {
  -            return TimerServiceDispatcher.instance().call(callable);
  -        }
  -
           public void cancel() 
               throws
                   IllegalStateException,
                   NoSuchObjectLocalException,
                   EJBException
           {
  -            callInContext(new Callable() {
  +            instance().call(new Callable() {
                       public Object call() 
                       {
                           timer.cancel();
  @@ -177,7 +172,7 @@
                   EJBException
           {
               TimerHandle handle = (TimerHandle) 
  -                callInContext(new Callable() {
  +                instance().call(new Callable() {
                           public Object call() 
                           {
                               return timer.getHandle();
  @@ -193,7 +188,7 @@
                   EJBException
           {
               return (Serializable) 
  -                callInContext(new Callable() {
  +                instance().call(new Callable() {
                           public Object call() 
                           {
                               return timer.getInfo();
  @@ -207,7 +202,7 @@
                   EJBException
           {
               return (Date) 
  -                callInContext(new Callable() {
  +                instance().call(new Callable() {
                           public Object call() 
                           {
                               return timer.getNextTimeout();
  @@ -221,7 +216,7 @@
                      EJBException
           {
               return (Long) 
  -                callInContext(new Callable() {
  +                instance().call(new Callable() {
                           public Object call() 
                           {
                               return timer.getTimeRemaining();
  @@ -243,17 +238,12 @@
               this.handle = handle;
           }
           
  -        private Object callInContext(Callable callable) 
  -        {
  -            return TimerServiceDispatcher.instance().call(callable);
  -        }
  -
           public Timer getTimer() 
               throws IllegalStateException,
                      NoSuchObjectLocalException,
                      EJBException 
           {
  -            Timer timer = (Timer) callInContext( new Callable() {
  +            Timer timer = (Timer) instance().call(new Callable() {
                   public Object call() 
                   {
                       try
  @@ -265,7 +255,7 @@
                           return null;
                       }           
                   }
  -            } );
  +            });
               if (timer==null)
               {
                  throw new NoSuchObjectLocalException();
  @@ -276,4 +266,26 @@
               }
           }
       }
  +
  +    public Object call(Callable task) 
  +    {
  +        try 
  +        {
  +            return task.call();
  +        } 
  +        catch (RuntimeException e) 
  +        {
  +            // just pass along runtime exceptions
  +            throw e;
  +        } 
  +        catch (Exception e) 
  +        {
  +            throw new RuntimeException(e);
  +        }
  +    }
  +    public static LocalTimerServiceDispatcher instance()
  +    {
  +       return ( (LocalTimerServiceDispatcher) AbstractDispatcher.instance() );
  +    }
  +
   }
  
  
  
  1.1      date: 2007/05/31 01:17:15;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/core/LocalTimerServiceDispatcher.java
  
  Index: LocalTimerServiceDispatcher.java
  ===================================================================
  package org.jboss.seam.core;
  
  import java.util.concurrent.Callable;
  
  import javax.ejb.Local;
  import javax.ejb.Timer;
  
  /**
   * Local interface for TimerServiceDispatcher.
   * 
   * @author Gavin King
   *
   */
  @Local
  public interface LocalTimerServiceDispatcher extends Dispatcher<Timer, TimerServiceSchedule>
  {   
     public Object call(Callable task);
  }
  
  
  



More information about the jboss-cvs-commits mailing list