You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by xu...@apache.org on 2010/08/09 04:55:20 UTC

svn commit: r983509 - in /geronimo/server/trunk: framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/ plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/

Author: xuhaihong
Date: Mon Aug  9 02:55:19 2010
New Revision: 983509

URL: http://svn.apache.org/viewvc?rev=983509&view=rev
Log:
GERONIMO-5491 Implement org.apache.catalina.Executor interface in TomcatExecutorWrapper Patch from Han Hong Fang

Modified:
    geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/GeronimoExecutor.java
    geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/ThreadPool.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatExecutorWrapper.java

Modified: geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/GeronimoExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/GeronimoExecutor.java?rev=983509&r1=983508&r2=983509&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/GeronimoExecutor.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/GeronimoExecutor.java Mon Aug  9 02:55:19 2010
@@ -17,6 +17,8 @@
 package org.apache.geronimo.pool;
 
 import java.util.concurrent.Executor;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.TimeUnit;
 
 /**
  * A Geronimo-specific extension that contributes a little extra manageability
@@ -37,4 +39,17 @@ public interface GeronimoExecutor extend
      * @return the unique name of this object within the server
      */
     String getObjectName();
+    
+    /**
+     * Executes the given command at some time in the future, if it can not be started within the given timeout,
+     * RejectedExecutionException will be thrown. The command may execute in a new thread, in a pooled thread, or in the
+     * calling thread, at the discretion of the <tt>Executor</tt> implementation.
+     * 
+     * @param command the runnable task
+     * @param timeout duration of timeout
+     * @param unit TimeUnit of timeout
+     * @throws RejectedExecutionException if this task cannot be accepted for execution.
+     * @throws NullPointerException if command is null
+     */
+    public void execute(Runnable runnable, long timeout, TimeUnit unit);
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/ThreadPool.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/ThreadPool.java?rev=983509&r1=983508&r2=983509&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/ThreadPool.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-core/src/main/java/org/apache/geronimo/pool/ThreadPool.java Mon Aug  9 02:55:19 2010
@@ -203,6 +203,33 @@ public class ThreadPool implements Geron
     public void execute(Runnable command) {
         execute("Unknown", command);
     }
+    
+    public void execute(Runnable command, long timeout, TimeUnit unit) {
+        execute("Unknown", command, timeout, unit);
+    }
+    
+    public void execute(final String consumerName, final Runnable command, long timeout, TimeUnit unit) {
+        if (waitWhenBlocked) {
+            addToQueue(command, timeout, unit);
+        } else {
+            try {
+                execute(consumerName, command);
+            } catch (RejectedExecutionException e) {
+                addToQueue(command, timeout, unit);
+            }
+        }
+    }
+    
+    private void addToQueue(Runnable command, long timeout, TimeUnit unit) {
+        try {
+            boolean added = executor.getQueue().offer(command, timeout, unit);
+            if (!added) {
+                throw new RejectedExecutionException();
+            }
+        } catch (InterruptedException e) {
+            throw new RejectedExecutionException(e);
+        }
+    }
 
     public void execute(final String consumerName, final Runnable runnable) {
         Runnable command;

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatExecutorWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatExecutorWrapper.java?rev=983509&r1=983508&r2=983509&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatExecutorWrapper.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatExecutorWrapper.java Mon Aug  9 02:55:19 2010
@@ -58,8 +58,7 @@ public class TomcatExecutorWrapper exten
 
     @Override
     public void execute(Runnable runnable, long timeout, TimeUnit unit) {
-        executor.execute(runnable);
-        // FIXME Figure out how to implement it
+        executor.execute(runnable, timeout, unit);
     }
 
     @Override