cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r577477 - /incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
Date Wed, 19 Sep 2007 23:59:25 GMT
Author: ningjiang
Date: Wed Sep 19 16:59:24 2007
New Revision: 577477

URL: http://svn.apache.org/viewvc?rev=577477&view=rev
Log:
CXF-1034 shutdown the JettyEngine when bus shutdown is called

Modified:
    incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java?rev=577477&r1=577476&r2=577477&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
(original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
Wed Sep 19 16:59:24 2007
@@ -30,6 +30,8 @@
 import javax.annotation.Resource;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.configuration.jsse.TLSServerParameters;
 
@@ -42,31 +44,19 @@
  * caches the JettyHTTPServerEngines so that they may be 
  * retrieved if already previously configured.
  */
-public class JettyHTTPServerEngineFactory {
+public class JettyHTTPServerEngineFactory implements BusLifeCycleListener {
     private static final Logger LOG =
         LogUtils.getL7dLogger(JettyHTTPServerEngineFactory.class);    
     
     /**
      * This map holds references for allocated ports.
      */
-    // All system tests do not shut down bus correctly,
-    // or the bus does not shutdown all endpoints correctly,
-    // so that these server endings are actuall shared amongst busses
-    // within the same JVM.
-    
-    // We will keep it static until we can resolve the problems 
-    // in the System tests.
-    // TODO: Fix the System Tests so that they shutdown the 
-    // buses that they are using and that the buses actually
-    // shutdown the destinations and their server engines
-    // properly. This will require a bit of lifecyle and reference
-    // counting on Destinations to server engines, if they are 
-    // going to be shared, but they should by no means be 
-    // shared accross buses, right?
+    // Still use the static map to hold the port information
+    // in the same JVM
     private static Map<Integer, JettyHTTPServerEngine> portMap =
         new HashMap<Integer, JettyHTTPServerEngine>();
    
-    
+    private BusLifeCycleManager lifeCycleManager;
     /**
      * This map holds the threading parameters that are to be applied
      * to new Engines when bound to the reference id.
@@ -89,7 +79,8 @@
     
     public JettyHTTPServerEngineFactory() {
         // Empty
-    }
+    }    
+    
     
     /**
      * This call is used to set the bus. It should only be called once.
@@ -104,7 +95,13 @@
     
     @PostConstruct
     public void registerWithBus() {
-        bus.setExtension(this, JettyHTTPServerEngineFactory.class);
+        if (bus != null) {
+            bus.setExtension(this, JettyHTTPServerEngineFactory.class);
+        }
+        lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
+        if (null != lifeCycleManager) {
+            lifeCycleManager.registerLifeCycleListener(this);
+        }        
     }
     
     
@@ -200,6 +197,29 @@
     @PostConstruct
     public void finalizeConfig() {
         registerWithBus();
+    }
+
+    public void initComplete() {
+        // do nothing here
+        
+    }
+
+    public void postShutdown() {
+        // clean up the collections       
+        portMap.clear();
+        threadingParametersMap.clear();
+        tlsParametersMap.clear();
+    }
+
+    public void preShutdown() {
+        // shut down the jetty server in the portMap
+        // To avoid the CurrentModificationException, 
+        // do not use portMap.vaules directly
+       
+        JettyHTTPServerEngine[] engines = portMap.values().toArray(new JettyHTTPServerEngine[0]);
+        for (JettyHTTPServerEngine engine : engines) {
+            engine.shutdown();
+        }
     }
     
 }



Mime
View raw message