Author: scheu Date: Wed Oct 24 02:41:40 2007 New Revision: 587836 URL: http://svn.apache.org/viewvc?rev=587836&view=rev Log: AXIS2-3298 Contributor:Nick Gallardo Corrections to the Async Endpoint threadswitch code (see AXIS2-3202)
Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ServerConstants.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SingleThreadedExecutor.java Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/ExecutorFactory.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSExecutorFactory.java Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ServerConstants.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ServerConstants.java?rev=587836&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ServerConstants.java (added) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/ServerConstants.java Wed Oct 24 02:41:40 2007 @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axis2.jaxws.server; + +public class ServerConstants { + + /** + * A constant for the property used to disable the server side + * thread switch on async and one way requests. This property + * must be set on the MessageContext for the request. + */ + public static final String SERVER_DISABLE_THREAD_SWITCH = "serverDisableThreadSwitch"; + +} Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java?rev=587836&r1=587835&r2=587836&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java Wed Oct 24 02:41:40 2007 @@ -33,9 +33,11 @@ import org.apache.axis2.jaxws.registry.FactoryRegistry; import org.apache.axis2.jaxws.server.EndpointCallback; import org.apache.axis2.jaxws.server.EndpointInvocationContext; +import org.apache.axis2.jaxws.server.ServerConstants; import org.apache.axis2.jaxws.server.endpoint.Utils; import org.apache.axis2.jaxws.spi.Constants; import org.apache.axis2.jaxws.utility.ExecutorFactory; +import org.apache.axis2.jaxws.utility.SingleThreadedExecutor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -129,17 +131,32 @@ log.debug("JavaBeanDispatcher about to invoke using OperationDesc: " + operationDesc.toString()); } - - ExecutorFactory ef = (ExecutorFactory) FactoryRegistry.getFactory(ExecutorFactory.class); - Executor executor = ef.getExecutorInstance(); EndpointInvocationContext eic = (EndpointInvocationContext) request.getInvocationContext(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); - AsyncInvocationWorker worker = new AsyncInvocationWorker(target, methodInputParams, cl, eic); + AsyncInvocationWorker worker = new AsyncInvocationWorker(target, + methodInputParams, + cl, eic); FutureTask task = new FutureTask<AsyncInvocationWorker>(worker); - executor.execute(task); + ExecutorFactory ef = (ExecutorFactory) FactoryRegistry.getFactory(ExecutorFactory.class); + Executor executor = ef.getExecutorInstance(ExecutorFactory.SERVER_EXECUTOR); + + // If the property has been set to disable thread switching, then we can + // do so by using a SingleThreadedExecutor instance to continue processing + // work on the existing thread. + Boolean disable = (Boolean) + request.getProperty(ServerConstants.SERVER_DISABLE_THREAD_SWITCH); + if (disable != null && disable.booleanValue()) { + if (log.isDebugEnabled()) { + log.debug("Server side thread switch disabled. " + + "Setting Executor to the SingleThreadedExecutor."); + } + executor = new SingleThreadedExecutor(); + } + + executor.execute(task); return; } @@ -162,14 +179,25 @@ log.debug("JavaBeanDispatcher about to invoke using OperationDesc: " + operationDesc.toString()); } - ExecutorFactory ef = (ExecutorFactory) FactoryRegistry.getFactory(ExecutorFactory.class); - Executor executor = ef.getExecutorInstance(); EndpointInvocationContext eic = (EndpointInvocationContext) request.getInvocationContext(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); AsyncInvocationWorker worker = new AsyncInvocationWorker(target, methodInputParams, cl, eic); FutureTask task = new FutureTask<AsyncInvocationWorker>(worker); + + ExecutorFactory ef = (ExecutorFactory) FactoryRegistry.getFactory(ExecutorFactory.class); + Executor executor = ef.getExecutorInstance(ExecutorFactory.SERVER_EXECUTOR); + // If the property has been set to disable thread switching, then we can + // do so by using a SingleThreadedExecutor instance to continue processing + // work on the existing thread. + Boolean disable = (Boolean) request.getProperty(ServerConstants.SERVER_DISABLE_THREAD_SWITCH); + if (disable != null && disable.booleanValue()) { + if (log.isDebugEnabled()) { + log.debug("Server side thread switch disabled. Setting Executor to the SingleThreadedExecutor."); + } + executor = new SingleThreadedExecutor(); + } executor.execute(task); return; Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java?rev=587836&r1=587835&r2=587836&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java Wed Oct 24 02:41:40 2007 @@ -23,6 +23,7 @@ import org.apache.axis2.jaxws.server.EndpointCallback; import org.apache.axis2.jaxws.server.EndpointInvocationContext; import org.apache.axis2.jaxws.utility.ClassUtils; +import org.apache.axis2.transport.TransportUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -107,7 +108,7 @@ // Set the proper class loader so that we can properly marshall the // outbound response. ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader != null) { + if (classLoader != null && (classLoader != currentLoader)) { Thread.currentThread().setContextClassLoader(classLoader); if (log.isDebugEnabled()) { log.debug("Context ClassLoader set to:" + classLoader); @@ -131,8 +132,8 @@ if (eic.isOneWay()) { if (log.isDebugEnabled()) { log.debug("Invocation pattern was one way, work complete."); - return null; } + return null; } // Create the response MessageContext @@ -173,10 +174,15 @@ // Set the thread's ClassLoader back to what it originally was. Thread.currentThread().setContextClassLoader(currentLoader); + // Clean up the cached attachments from the request and the response. + TransportUtils.deleteAttachments(eic.getRequestMessageContext().getAxisMessageContext()); + TransportUtils.deleteAttachments(eic.getResponseMessageContext().getAxisMessageContext()); } catch (Throwable e) { // Exceptions are swallowed, there is no reason to rethrow them - log.error("AN UNEXPECTED ERROR OCCURRED IN THE ASYNC WORKER THREAD"); - log.error("Exception is:" + e); + if (log.isDebugEnabled()) { + log.debug("AN UNEXPECTED ERROR OCCURRED IN THE ASYNC WORKER THREAD"); + log.debug("Exception is:" + e, e); + } } return null; Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java?rev=587836&r1=587835&r2=587836&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java Wed Oct 24 02:41:40 2007 @@ -36,8 +36,10 @@ import org.apache.axis2.jaxws.registry.FactoryRegistry; import org.apache.axis2.jaxws.server.EndpointCallback; import org.apache.axis2.jaxws.server.EndpointInvocationContext; +import org.apache.axis2.jaxws.server.ServerConstants; import org.apache.axis2.jaxws.utility.ClassUtils; import org.apache.axis2.jaxws.utility.ExecutorFactory; +import org.apache.axis2.jaxws.utility.SingleThreadedExecutor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -159,7 +161,18 @@ } ExecutorFactory ef = (ExecutorFactory) FactoryRegistry.getFactory(ExecutorFactory.class); - Executor executor = ef.getExecutorInstance(); + Executor executor = ef.getExecutorInstance(ExecutorFactory.SERVER_EXECUTOR); + + // If the property has been set to disable thread switching, then we can + // do so by using a SingleThreadedExecutor instance to continue processing + // work on the existing thread. + Boolean disable = (Boolean) request.getProperty(ServerConstants.SERVER_DISABLE_THREAD_SWITCH); + if (disable != null && disable.booleanValue()) { + if (log.isDebugEnabled()) { + log.debug("Server side thread switch disabled. Setting Executor to the SingleThreadedExecutor."); + } + executor = new SingleThreadedExecutor(); + } Method m = getJavaMethod(); Object[] params = new Object[] {param}; @@ -197,7 +210,18 @@ } ExecutorFactory ef = (ExecutorFactory) FactoryRegistry.getFactory(ExecutorFactory.class); - Executor executor = ef.getExecutorInstance(); + Executor executor = ef.getExecutorInstance(ExecutorFactory.SERVER_EXECUTOR); + + // If the property has been set to disable thread switching, then we can + // do so by using a SingleThreadedExecutor instance to continue processing + // work on the existing thread. + Boolean disable = (Boolean) request.getProperty(ServerConstants.SERVER_DISABLE_THREAD_SWITCH); + if (disable != null && disable.booleanValue()) { + if (log.isDebugEnabled()) { + log.debug("Server side thread switch disabled. Setting Executor to the SingleThreadedExecutor."); + } + executor = new SingleThreadedExecutor(); + } Method m = getJavaMethod(); Object[] params = new Object[] {param}; Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java?rev=587836&r1=587835&r2=587836&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java Wed Oct 24 02:41:40 2007 @@ -359,7 +359,7 @@ private Executor getDefaultExecutor() { ExecutorFactory executorFactory = (ExecutorFactory) FactoryRegistry.getFactory( ExecutorFactory.class); - return executorFactory.getExecutorInstance(); + return executorFactory.getExecutorInstance(ExecutorFactory.CLIENT_EXECUTOR); } private boolean isValidServiceName() { Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/ExecutorFactory.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/ExecutorFactory.java?rev=587836&r1=587835&r2=587836&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/ExecutorFactory.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/ExecutorFactory.java Wed Oct 24 02:41:40 2007 @@ -30,6 +30,20 @@ */ public interface ExecutorFactory { - public Executor getExecutorInstance(); + public static final int CLIENT_EXECUTOR = 0; + public static final int SERVER_EXECUTOR = 1; + + /** + * + * @return + */ + public Executor getExecutorInstance(); + + /** + * + * @param executorType + * @return + */ + public Executor getExecutorInstance(int executorType); } Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSExecutorFactory.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSExecutorFactory.java?rev=587836&r1=587835&r2=587836&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSExecutorFactory.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSExecutorFactory.java Wed Oct 24 02:41:40 2007 @@ -30,8 +30,14 @@ */ public class JAXWSExecutorFactory implements ExecutorFactory { - public Executor getExecutorInstance() { - return Executors.newFixedThreadPool(3, new JAXWSThreadFactory()); - } + public Executor getExecutorInstance() { + return Executors.newFixedThreadPool(3, new JAXWSThreadFactory()); + } + + public Executor getExecutorInstance(int executorType) { + return getExecutorInstance(); + } + + } Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SingleThreadedExecutor.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SingleThreadedExecutor.java?rev=587836&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SingleThreadedExecutor.java (added) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SingleThreadedExecutor.java Wed Oct 24 02:41:40 2007 @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axis2.jaxws.utility; + +import org.apache.axis2.jaxws.ExceptionFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.concurrent.Executor; + +/** + * A simple Executor implementation that does not create a new thread + * for processing work, but just borrows the current thread. + */ +public class SingleThreadedExecutor implements Executor { + + public static final Log log = LogFactory.getLog(SingleThreadedExecutor.class); + + public void execute(Runnable command) { + if (log.isDebugEnabled()) { + log.debug("JAX-WS work on SingleThreadedExector started."); + } + + if (command == null) { + throw ExceptionFactory.makeWebServiceException("The Runnable command provided " + + "was null. A non-null instance is required."); + } + + command.run(); + + if (log.isDebugEnabled()) { + log.debug("JAX-WS work on SingleThreadedExectuor complete."); + } + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]