cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1360864 - in /cxf/trunk: api/src/main/java/org/apache/cxf/ api/src/main/java/org/apache/cxf/endpoint/ api/src/main/java/org/apache/cxf/interceptor/ api/src/main/java/org/apache/cxf/transport/ rt/bindings/coloc/src/main/java/org/apache/cxf/...
Date Thu, 12 Jul 2012 19:16:35 GMT
Author: dkulp
Date: Thu Jul 12 19:16:34 2012
New Revision: 1360864

URL: http://svn.apache.org/viewvc?rev=1360864&view=rev
Log:
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/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
    cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
    cxf/trunk/api/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
    cxf/trunk/api/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java
    cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
    cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
    cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/OSGiJaxwsEndpointManager.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java Thu Jul 12 19:16:34 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/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Thu Jul 12 19:16:34
2012
@@ -469,10 +469,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);
@@ -544,7 +543,9 @@ public class ClientImpl
             if (origLoader != null) {
                 origLoader.reset();
             }
-            BusFactory.setThreadDefaultBus(origBus);
+            if (origBus != bus) {
+                BusFactory.setThreadDefaultBus(origBus);
+            }
         }
     }
 
@@ -749,8 +750,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 {
@@ -822,7 +822,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/trunk/api/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
Thu Jul 12 19:16:34 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/trunk/api/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/transport/ChainInitiationObserver.java Thu
Jul 12 19:16:34 2012
@@ -61,8 +61,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) {
@@ -122,7 +121,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/trunk/api/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/transport/MultipleEndpointObserver.java Thu
Jul 12 19:16:34 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/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
(original)
+++ cxf/trunk/rt/bindings/coloc/src/main/java/org/apache/cxf/binding/coloc/ColocMessageObserver.java
Thu Jul 12 19:16:34 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/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
Thu Jul 12 19:16:34 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/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/transport/http_jaxws_spi/JAXWSHttpSpiDestination.java
Thu Jul 12 19:16:34 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/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
Thu Jul 12 19:16:34 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/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
Thu Jul 12 19:16:34 2012
@@ -121,19 +121,22 @@ public class CXFNonSpringServlet extends
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
         throws IOException, ServletException {
         ClassLoaderHolder origLoader = null;
+        Bus origBus = null;
         if (request instanceof HttpServletRequest && response instanceof HttpServletResponse)
{
             try {
                 if (loader != null) {
                     origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
                 }
                 if (bus != null) {
-                    BusFactory.setThreadDefaultBus(bus);
+                    origBus = BusFactory.getAndSetThreadDefaultBus(bus);
                 }
                 if (controller.filter((HttpServletRequest)request, (HttpServletResponse)response))
{
                     return;
                 }
             } finally {
-                BusFactory.setThreadDefaultBus(null);
+                if (origBus != bus) {
+                    BusFactory.setThreadDefaultBus(origBus);
+                }
                 if (origLoader != null) {
                     origLoader.reset();
                 }
@@ -144,16 +147,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/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
Thu Jul 12 19:16:34 2012
@@ -194,6 +194,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);
@@ -218,7 +219,7 @@ public class JMSDestination extends Abst
                                                           jmsConfig));
             }
             
-            BusFactory.setThreadDefaultBus(bus);
+            origBus = BusFactory.getAndSetThreadDefaultBus(bus);
 
             
             Map<Class<?>, ?> mp = JCATransactionalMessageListenerContainer.ENDPOINT_LOCAL.get();
@@ -263,7 +264,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/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
Thu Jul 12 19:16:34 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();
             }

Modified: cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/OSGiJaxwsEndpointManager.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/OSGiJaxwsEndpointManager.java?rev=1360864&r1=1360863&r2=1360864&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/OSGiJaxwsEndpointManager.java
(original)
+++ cxf/trunk/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/services/OSGiJaxwsEndpointManager.java
Thu Jul 12 19:16:34 2012
@@ -91,9 +91,7 @@ public class OSGiJaxwsEndpointManager ex
     }
 
     private Object setCXFBusInternal() {
-        Object o = BusFactory.getThreadDefaultBus(false);
-        BusFactory.setThreadDefaultBus((Bus)cxfBus);
-        return o;
+        return BusFactory.getAndSetThreadDefaultBus((Bus)cxfBus);
     }
     private void createCXFBus() {
         BlueprintBus bp = new BlueprintBus();



Mime
View raw message