You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2011/07/28 23:46:51 UTC

svn commit: r1152012 - in /cxf/branches/2.4.x-fixes: ./ rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/ rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/

Author: dkulp
Date: Thu Jul 28 21:46:51 2011
New Revision: 1152012

URL: http://svn.apache.org/viewvc?rev=1152012&view=rev
Log:
Merged revisions 1152010 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1152010 | dkulp | 2011-07-28 17:40:13 -0400 (Thu, 28 Jul 2011) | 1 line
  
  [CXF-3695] Thread safety of Jetty transport
........

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
    cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
    cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1152010

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java?rev=1152012&r1=1152011&r2=1152012&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java Thu Jul 28 21:46:51 2011
@@ -68,12 +68,6 @@ public class JettyHTTPServerEngine
     private static final Logger LOG =
         LogUtils.getL7dLogger(JettyHTTPServerEngine.class);
    
-
-    /**
-     * The bus.
-     */
-    protected Bus bus;
-    
     /**
      * This is the Jetty HTTP Server Engine Factory. This factory caches some 
      * engines based on port numbers.
@@ -132,10 +126,8 @@ public class JettyHTTPServerEngine
      */
     public JettyHTTPServerEngine(
         JettyHTTPServerEngineFactory fac, 
-        Bus bus,
         String host,
         int port) {
-        this.bus     = bus;
         this.factory = fac;
         this.host    = host;
         this.port    = port;
@@ -169,15 +161,12 @@ public class JettyHTTPServerEngine
      * The bus.
      */
     @Resource(name = "cxf")
-    public void setBus(Bus b) {
-        bus = b;
-    }
-    
-    public Bus getBus() {
-        return bus;
+    public void setBus(Bus bus) {
+        if (null != bus && null == factory) {
+            factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
+        }        
     }
     
-    
     /**
      * Returns the protocol "http" or "https" for which this engine
      * was configured.
@@ -657,18 +646,11 @@ public class JettyHTTPServerEngine
     public void finalizeConfig() 
         throws GeneralSecurityException,
                IOException {
-        retrieveEngineFactory();
         retrieveListenerFactory();
         checkConnectorPort();
         this.configFinalized = true;
     }
     
-    protected void retrieveEngineFactory() {
-        if (null != bus && null == factory) {
-            factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
-        }        
-    }
-
     private void checkConnectorPort() throws IOException {
         if (null != connector && port != connector.getPort()) {
             throw new IOException("Error: Connector port " + connector.getPort() + " does not match"

Modified: cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java?rev=1152012&r1=1152011&r2=1152012&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java Thu Jul 28 21:46:51 2011
@@ -20,10 +20,10 @@ package org.apache.cxf.transport.http_je
 
 import java.io.IOException;
 import java.security.GeneralSecurityException;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -57,8 +57,10 @@ public class JettyHTTPServerEngineFactor
      */
     // 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 static ConcurrentHashMap<Integer, JettyHTTPServerEngine> portMap =
+        new ConcurrentHashMap<Integer, JettyHTTPServerEngine>();
+    
+    
    
     private BusLifeCycleManager lifeCycleManager;
     /**
@@ -102,6 +104,23 @@ public class JettyHTTPServerEngineFactor
         setBus(b);
     }    
     
+    private static synchronized JettyHTTPServerEngine getOrCreate(JettyHTTPServerEngineFactory factory,
+                    String host,
+                    int port,
+                    TLSServerParameters tlsParams) throws IOException, GeneralSecurityException {
+        
+        JettyHTTPServerEngine ref = portMap.get(port);
+        if (ref == null) {
+            ref = new JettyHTTPServerEngine(factory, host, port);
+            if (tlsParams != null) {
+                ref.setTlsServerParameters(tlsParams);
+            }
+            portMap.put(port, ref);
+            ref.finalizeConfig();
+        }
+        return ref;
+    }
+
     
     /**
      * This call is used to set the bus. It should only be called once.
@@ -144,7 +163,7 @@ public class JettyHTTPServerEngineFactor
             if (engine.getPort() == FALLBACK_THREADING_PARAMS_KEY) {
                 fallbackThreadingParameters = engine.getThreadingParameters();
             }
-            portMap.put(engine.getPort(), engine);
+            portMap.putIfAbsent(engine.getPort(), engine);
         }    
     }
     
@@ -182,10 +201,7 @@ public class JettyHTTPServerEngineFactor
         }
         JettyHTTPServerEngine ref = retrieveJettyHTTPServerEngine(port);
         if (null == ref) {
-            ref = new JettyHTTPServerEngine(this, bus, host, port);
-            ref.setTlsServerParameters(tlsParams);
-            portMap.put(port, ref);
-            ref.finalizeConfig();
+            ref = getOrCreate(this, host, port, tlsParams);
         } else {
             if (ref.getConnector() != null && ref.getConnector().isRunning()) {
                 throw new IOException("can't set the TLS params on the opened connector");
@@ -232,12 +248,7 @@ public class JettyHTTPServerEngineFactor
     public synchronized JettyHTTPServerEngine createJettyHTTPServerEngine(String host, int port, 
         String protocol) throws GeneralSecurityException, IOException {
         LOG.fine("Creating Jetty HTTP Server Engine for port " + port + ".");        
-        JettyHTTPServerEngine ref = retrieveJettyHTTPServerEngine(port);
-        if (null == ref) {
-            ref = new JettyHTTPServerEngine(this, bus, host, port);            
-            portMap.put(port, ref);
-            ref.finalizeConfig();
-        } 
+        JettyHTTPServerEngine ref = getOrCreate(this, host, port, null);
         // checking the protocol    
         if (!protocol.equals(ref.getProtocol())) {
             throw new IOException("Protocol mismatch for port " + port + ": "

Modified: cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java?rev=1152012&r1=1152011&r2=1152012&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java Thu Jul 28 21:46:51 2011
@@ -160,13 +160,15 @@ public class JettyHTTPServerEngineBeanDe
         
         String threadingRef;
         String tlsRef;
+        Bus bus;
         
         public SpringJettyHTTPServerEngine(
-            JettyHTTPServerEngineFactory fac, 
-            Bus bus,
+            JettyHTTPServerEngineFactory fac,
+            Bus b,
             String host,
             int port) {
-            super(fac, bus, host, port);
+            super(fac, host, port);
+            bus = b;
         }
         
         public SpringJettyHTTPServerEngine() {
@@ -175,7 +177,7 @@ public class JettyHTTPServerEngineBeanDe
         
         
         public void setApplicationContext(ApplicationContext ctx) throws BeansException {
-            if (getBus() == null) {
+            if (bus == null) {
                 setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));
             }
         }
@@ -192,7 +194,9 @@ public class JettyHTTPServerEngineBeanDe
             throws GeneralSecurityException,
                    IOException {
             if (tlsRef != null || threadingRef != null) {
-                retrieveEngineFactory();
+                if (bus != null) {
+                    setBus(bus);
+                }
                 if (threadingRef != null) {
                     setThreadingParameters(factory.getThreadingParametersMap().get(threadingRef));
                 }