You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/04/25 20:30:13 UTC

svn commit: r532435 - /incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java

Author: jsdelfino
Date: Wed Apr 25 11:30:12 2007
New Revision: 532435

URL: http://svn.apache.org/viewvc?view=rev&rev=532435
Log:
Changed the embedded tomcat server to use the regular Http11Protocol handler as the Nio-based protocol handler seems to cause problems in some environments. Customized the Tomcat JioEndpoint to make sure that Tomcat Acceptor threads are shut down before returning from the stop method, as this was contributing to cause address-in-use and connection-refused errors when repeatedly bringing Tomcat up/down.

Modified:
    incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java

Modified: incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java?view=diff&rev=532435&r1=532434&r2=532435
==============================================================================
--- incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java (original)
+++ incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java Wed Apr 25 11:30:12 2007
@@ -30,9 +30,10 @@
 import org.apache.catalina.core.StandardEngine;
 import org.apache.catalina.core.StandardHost;
 import org.apache.catalina.startup.ContextConfig;
-import org.apache.coyote.http11.Http11NioProtocol;
+import org.apache.coyote.http11.Http11Protocol;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.mapper.MappingData;
+import org.apache.tomcat.util.net.JIoEndpoint;
 import org.apache.tuscany.http.ServletHostExtension;
 import org.apache.tuscany.http.ServletMappingException;
 import org.apache.tuscany.spi.services.work.WorkScheduler;
@@ -55,24 +56,73 @@
      */
     private class CustomConnector extends Connector {
 
-        private class CustomHttpProtocolHandler extends Http11NioProtocol {
-        
+        private class CustomHttpProtocolHandler extends Http11Protocol {
+
+            /**
+             * An Executor wrappering our WorkScheduler
+             */
             private class WorkSchedulerExecutor implements Executor {
                 public void execute(Runnable command) {
                     workScheduler.scheduleWork(command);
                 }
             }
+
+            /**
+             * A custom Endpoint that waits for its acceptor thread to
+             * terminate before stopping.
+             */
+            private class CustomEndpoint extends JIoEndpoint {
+                private Thread acceptorThread;
+
+                private class CustomAcceptor extends Acceptor {
+                    CustomAcceptor() {
+                        super();
+                    }
+                }
+                
+                public void start() throws Exception {
+                    if (!initialized)
+                        init();
+                    if (!running) {
+                        running = true;
+                        paused = false;
+                        acceptorThread = new Thread(new CustomAcceptor(), getName() + "-Acceptor-" + 0);
+                        acceptorThread.setPriority(threadPriority);
+                        acceptorThread.setDaemon(daemon);
+                        acceptorThread.start();
+                    }
+                }
+                
+                public void stop() {
+                    super.stop();
+                    try {
+                        acceptorThread.join();
+                    } catch (InterruptedException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+                
+                public int getCurrentThreadsBusy() {
+                    return 0;
+                }
+            }
             
             CustomHttpProtocolHandler() {
-                ep.setExecutor(new WorkSchedulerExecutor());
+                endpoint = new CustomEndpoint();
+                endpoint.setExecutor(new WorkSchedulerExecutor());
             }
         }
         
         CustomConnector() throws Exception {
-            this.protocolHandler = new CustomHttpProtocolHandler();
+            protocolHandler = new CustomHttpProtocolHandler();
         }
     }
 
+    /**
+     * Constructs a new embedded Tomcat server.
+     * 
+     * @param workScheduler the WorkScheduler to use to process requests.
+     */
     public TomcatServer(WorkScheduler workScheduler) {
         this.workScheduler = workScheduler;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org