cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1360870 - in /cxf/branches/2.5.x-fixes: api/src/main/java/org/apache/cxf/ rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/cor...
Date Thu, 12 Jul 2012 19:24:27 GMT
Author: dkulp
Date: Thu Jul 12 19:24:27 2012
New Revision: 1360870

URL: http://svn.apache.org/viewvc?rev=1360870&view=rev
Log:
Merged revisions 1360865 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

........
  r1360865 | dkulp | 2012-07-12 15:21:11 -0400 (Thu, 12 Jul 2012) | 12 lines

  Merged revisions 1360864 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1360864 | dkulp | 2012-07-12 15:16:34 -0400 (Thu, 12 Jul 2012) | 4 lines

    Update how the thread default bus is handled to reduce calls into the
    synchronized block.  (in some cases drops from 3 or more calls per
    request to one).

  ........

........

Modified:
    cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java
    cxf/branches/2.5.x-fixes/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
    cxf/branches/2.5.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
    cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
    cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
    cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java

Modified: cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java (original)
+++ cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java Thu Jul 12 19:24:27
2012
@@ -127,8 +127,33 @@ public abstract class BusFactory {
      */
     public static void setThreadDefaultBus(Bus bus) {
         Thread cur = Thread.currentThread();
-        synchronized (threadBusses) {
-            threadBusses.put(cur, bus);
+        if (bus == null) {
+            synchronized (threadBusses) {
+                threadBusses.remove(cur);
+            }
+        } else {
+            synchronized (threadBusses) {
+                threadBusses.put(cur, bus);
+            }
+        }
+    }
+    
+    /**
+     * Sets the default bus for the thread.
+     *
+     * @param bus the new thread default bus.
+     * @return the old thread default bus or null
+     */
+    public static Bus getAndSetThreadDefaultBus(Bus bus) {
+        Thread cur = Thread.currentThread();
+        if (bus == null) {
+            synchronized (threadBusses) {
+                return threadBusses.remove(cur);
+            }
+        } else {
+            synchronized (threadBusses) {
+                return threadBusses.put(cur, bus);
+            }
         }
     }
 

Modified: cxf/branches/2.5.x-fixes/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
Thu Jul 12 19:24:27 2012
@@ -60,13 +60,12 @@ public class ColocMessageObserver extend
     }
 
     public void onMessage(Message m) {
-        Bus origBus = BusFactory.getThreadDefaultBus(false);
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
                 origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
-            BusFactory.setThreadDefaultBus(bus);
             if (LOG.isLoggable(Level.FINER)) {
                 LOG.finer("Processing Message at collocated endpoint.  Request message: "
+ m);
             }
@@ -131,7 +130,9 @@ public class ColocMessageObserver extend
             //Set Server OutBound Message onto InBound Exchange.
             setOutBoundMessage(ex, m.getExchange());
         } finally {
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) {
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
Thu Jul 12 19:24:27 2012
@@ -468,10 +468,9 @@ public class ClientImpl
                               Object[] params,
                               Map<String, Object> context,
                               Exchange exchange) throws Exception {
-        Bus origBus = BusFactory.getThreadDefaultBus(false);
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         ClassLoaderHolder origLoader = null;
         try {
-            BusFactory.setThreadDefaultBus(bus);
             ClassLoader loader = bus.getExtension(ClassLoader.class);
             if (loader != null) {
                 origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
@@ -545,7 +544,9 @@ public class ClientImpl
             if (origLoader != null) {
                 origLoader.reset();
             }
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
         }
     }
 
@@ -750,8 +751,7 @@ public class ClientImpl
         modifyChain(chain, message, true);
         modifyChain(chain, message.getExchange().getOutMessage(), true);
         
-        Bus origBus = BusFactory.getThreadDefaultBus(false);
-        BusFactory.setThreadDefaultBus(bus);
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         // execute chain
         ClientCallback callback = message.getExchange().get(ClientCallback.class);
         try {
@@ -823,7 +823,9 @@ public class ClientImpl
                 }
             }
         } finally {
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             synchronized (message.getExchange()) {
                 if (!isPartialResponse(message) 
                     || message.getContent(Exception.class) != null) {

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
Thu Jul 12 19:24:27 2012
@@ -54,8 +54,7 @@ public abstract class AbstractFaultChain
       
         assert null != message;
         
-        Bus origBus = BusFactory.getThreadDefaultBus(false);
-        BusFactory.setThreadDefaultBus(bus);
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
@@ -116,7 +115,9 @@ public abstract class AbstractFaultChain
                 throw new RuntimeException(exc);
             }
         } finally {
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) {
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
Thu Jul 12 19:24:27 2012
@@ -62,8 +62,7 @@ public class ChainInitiationObserver imp
     }
 
     public void onMessage(Message m) {
-        Bus origBus = BusFactory.getThreadDefaultBus(false);
-        BusFactory.setThreadDefaultBus(bus);
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
@@ -123,7 +122,9 @@ public class ChainInitiationObserver imp
             phaseChain.doIntercept(message);
             
         } finally {
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) {
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java
Thu Jul 12 19:24:27 2012
@@ -61,8 +61,7 @@ public class MultipleEndpointObserver im
     }
 
     public void onMessage(Message message) {
-        Bus origBus = BusFactory.getThreadDefaultBus(false);
-        BusFactory.setThreadDefaultBus(bus);
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
@@ -98,7 +97,9 @@ public class MultipleEndpointObserver im
             
             chain.doIntercept(message);
         } finally {
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) {
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
Thu Jul 12 19:24:27 2012
@@ -45,8 +45,8 @@ class ClientMessageObserver implements M
         PhaseInterceptorChain chain = AbstractClient.setupInInterceptorChain(cfg);
         message.setInterceptorChain(chain);
         message.getExchange().setInMessage(message);
-        Bus origBus = BusFactory.getThreadDefaultBus(false);
-        BusFactory.setThreadDefaultBus(cfg.getBus());
+        Bus bus = cfg.getBus();
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
@@ -55,7 +55,9 @@ class ClientMessageObserver implements M
             // execute chain
             chain.doIntercept(message);
         } finally {
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) {
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
Thu Jul 12 19:24:27 2012
@@ -116,13 +116,15 @@ public class JAXWSHttpSpiDestination ext
             }
         }
         
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); 
         try {
-            BusFactory.setThreadDefaultBus(bus);
             serviceRequest(req, resp);
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
-            BusFactory.setThreadDefaultBus(null);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
         }
     }
 

Modified: cxf/branches/2.5.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
Thu Jul 12 19:24:27 2012
@@ -304,14 +304,16 @@ public class JettyHTTPDestination extend
 
         // REVISIT: service on executor if associated with endpoint
         ClassLoaderHolder origLoader = null;
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         try {
             if (loader != null) {
                 origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
-            BusFactory.setThreadDefaultBus(bus); 
             serviceRequest(context, req, resp);
         } finally {
-            BusFactory.setThreadDefaultBus(null);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) { 
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
Thu Jul 12 19:24:27 2012
@@ -118,16 +118,19 @@ public class CXFNonSpringServlet extends
     @Override
     protected void invoke(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
         ClassLoaderHolder origLoader = null;
+        Bus origBus = null;
         try {
             if (loader != null) {
                 origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             if (bus != null) {
-                BusFactory.setThreadDefaultBus(bus);
+                origBus = BusFactory.getAndSetThreadDefaultBus(bus);
             }
             controller.invoke(request, response);
         } finally {
-            BusFactory.setThreadDefaultBus(null);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(null);
+            }
             if (origLoader != null) {
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
Thu Jul 12 19:24:27 2012
@@ -191,6 +191,7 @@ public class JMSDestination extends Abst
     }
     public void onMessage(javax.jms.Message message, Session session) {
         ClassLoaderHolder origLoader = null;
+        Bus origBus = null;
         try {
             if (loader != null) {
                 origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
@@ -215,7 +216,7 @@ public class JMSDestination extends Abst
                                                           jmsConfig));
             }
             
-            BusFactory.setThreadDefaultBus(bus);
+            origBus = BusFactory.getAndSetThreadDefaultBus(bus);
 
             
             Map<Class<?>, ?> mp = JCATransactionalMessageListenerContainer.ENDPOINT_LOCAL.get();
@@ -260,7 +261,9 @@ public class JMSDestination extends Abst
         } catch (UnsupportedEncodingException ex) {
             getLogger().log(Level.WARNING, "can't get the right encoding information. " +
ex);
         } finally {
-            BusFactory.setThreadDefaultBus(null);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) { 
                 origLoader.reset();
             }

Modified: cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java?rev=1360870&r1=1360869&r2=1360870&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
Thu Jul 12 19:24:27 2012
@@ -112,15 +112,17 @@ public class JMSContinuation implements 
     protected void doResume() {
         updateContinuations(true);
         ClassLoaderHolder origLoader = null;
+        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
         try {
-            BusFactory.setThreadDefaultBus(bus);
             if (loader != null) {
                 origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             incomingObserver.onMessage(inMessage);
         } finally {
             isPending = false;
-            BusFactory.setThreadDefaultBus(null);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
             if (origLoader != null) { 
                 origLoader.reset();
             }



Mime
View raw message