You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2007/06/22 04:58:19 UTC

svn commit: r549678 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: registry/FactoryRegistry.java spi/ServiceDelegate.java utility/ExecutorFactory.java utility/JAXWSExecutorFactory.java utility/JAXWSThreadFactory.java

Author: dims
Date: Thu Jun 21 19:58:18 2007
New Revision: 549678

URL: http://svn.apache.org/viewvc?view=rev&rev=549678
Log:
Fix for AXIS2-2836 - Allow a thread factory to be registered with the JAX-WS layer

Added:
    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
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSThreadFactory.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java?view=diff&rev=549678&r1=549677&r2=549678
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java Thu Jun 21 19:58:18 2007
@@ -36,6 +36,8 @@
 import org.apache.axis2.jaxws.message.util.impl.SAAJConverterFactoryImpl;
 import org.apache.axis2.jaxws.server.dispatcher.factory.EndpointDispatcherFactory;
 import org.apache.axis2.jaxws.server.endpoint.lifecycle.factory.EndpointLifecycleManagerFactory;
+import org.apache.axis2.jaxws.utility.ExecutorFactory;
+import org.apache.axis2.jaxws.utility.JAXWSExecutorFactory;
 
 import java.util.Hashtable;
 import java.util.Map;
@@ -58,6 +60,7 @@
         table.put(EndpointLifecycleManagerFactory.class, new EndpointLifecycleManagerFactory());
         table.put(ClassFinderFactory.class, new ClassFinderFactory());
         table.put(EndpointDispatcherFactory.class, new EndpointDispatcherFactory());
+        table.put(ExecutorFactory.class, new JAXWSExecutorFactory());
     }
 
     /** FactoryRegistry is currently a static singleton */

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?view=diff&rev=549678&r1=549677&r2=549678
==============================================================================
--- 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 Thu Jun 21 19:58:18 2007
@@ -34,8 +34,10 @@
 import org.apache.axis2.jaxws.description.ServiceDescriptionWSDL;
 import org.apache.axis2.jaxws.handler.HandlerResolverImpl;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.spi.migrator.ApplicationContextMigratorUtil;
 import org.apache.axis2.jaxws.util.WSDLWrapper;
+import org.apache.axis2.jaxws.utility.ExecutorFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -352,7 +354,9 @@
 
     //TODO: Need to make the default number of threads configurable
     private Executor getDefaultExecutor() {
-        return Executors.newFixedThreadPool(20, new JAXWSThreadFactory());
+    	ExecutorFactory executorFactory = (ExecutorFactory) FactoryRegistry.getFactory(
+    			ExecutorFactory.class);
+    	return executorFactory.getExecutorInstance();
     }
 
     private boolean isValidServiceName() {
@@ -482,59 +486,4 @@
         return classes;
     }
     
-}
-
-/**
- * Factory to create threads in the ThreadPool Executor.  We provide a factory so the threads can be
- * set as daemon threads so that they do not prevent the JVM from exiting normally when the main
- * client thread is finished.
- */
-class JAXWSThreadFactory implements ThreadFactory {
-    private static final Log log = LogFactory.getLog(JAXWSThreadFactory.class);
-    private static int groupNumber = 0;
-    private int threadNumber = 0;
-    // We put the threads into a unique thread group only for ease of identifying them
-    private ThreadGroup threadGroup = null;
-
-    public Thread newThread(final Runnable r) {
-        if (threadGroup == null) {
-            try {
-                threadGroup = (ThreadGroup)AccessController.doPrivileged(
-                        new PrivilegedExceptionAction() {
-                            public Object run() {
-                                return new ThreadGroup(
-                                        "JAX-WS Default Executor Group " + groupNumber++);
-                            }
-                        }
-                );
-            } catch (PrivilegedActionException e) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Exception thrown from AccessController: " + e);
-                }
-                throw ExceptionFactory.makeWebServiceException(e.getException());
-            }
-        }
-
-        threadNumber++;
-        Thread returnThread = null;
-        try {
-            returnThread = (Thread)AccessController.doPrivileged(
-                    new PrivilegedExceptionAction() {
-                        public Object run() {
-                            Thread newThread = new Thread(threadGroup, r);
-                            newThread.setDaemon(true);
-                            return newThread;
-                        }
-                    }
-            );
-        } catch (PrivilegedActionException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Exception thrown from AccessController: " + e);
-            }
-            throw ExceptionFactory.makeWebServiceException(e.getException());
-        }
-
-        return returnThread;
-    }
-
 }

Added: 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?view=auto&rev=549678
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/ExecutorFactory.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/ExecutorFactory.java Thu Jun 21 19:58:18 2007
@@ -0,0 +1,35 @@
+/*
+ * 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 java.util.concurrent.Executor;
+
+/**
+ * This is the interface that should be implemented by classes that wish to
+ * provide Executor instances to the JAX-WS runtime. When the runtime needs an
+ * Executor instance it will look in the FactoryRegistry for an implementation
+ * of this factory and retrieve the instance.
+ *
+ */
+public interface ExecutorFactory {
+
+	public Executor getExecutorInstance();
+	
+}

Added: 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?view=auto&rev=549678
==============================================================================
--- 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/utility/JAXWSExecutorFactory.java Thu Jun 21 19:58:18 2007
@@ -0,0 +1,37 @@
+/*
+ * 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 java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+/**
+ * This is an implementation of the ExecutorFactory interface. It is used
+ * to provide an Executor to a ServiceDelegate instance. The Executor instance
+ * will be backed by the JAXWSThreadFactory.
+ *
+ */
+public class JAXWSExecutorFactory implements ExecutorFactory {
+
+	public Executor getExecutorInstance() {
+		return Executors.newFixedThreadPool(3, new JAXWSThreadFactory());
+	}
+
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSThreadFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSThreadFactory.java?view=auto&rev=549678
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSThreadFactory.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JAXWSThreadFactory.java Thu Jun 21 19:58:18 2007
@@ -0,0 +1,81 @@
+/*
+ * 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 java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.concurrent.ThreadFactory;
+
+import org.apache.axis2.java.security.AccessController;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Factory to create threads in the ThreadPool Executor.  We provide a factory so 
+ * the threads can be set as daemon threads so that they do not prevent the JVM from 
+ * exiting normally when the main client thread is finished.
+ *
+ */
+public class JAXWSThreadFactory implements ThreadFactory {
+	private static final Log log = LogFactory.getLog(JAXWSThreadFactory.class);
+    private static int groupNumber = 0;
+    private int threadNumber = 0;
+    // We put the threads into a unique thread group only for ease of identifying them
+    private ThreadGroup threadGroup = null;
+
+    public Thread newThread(final Runnable r) {
+        if (threadGroup == null) {
+            try {
+                threadGroup =
+                        (ThreadGroup) AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                            public Object run() {
+                                return new ThreadGroup("JAX-WS Default Executor Group "
+                                        + groupNumber++);
+                            }
+                        });
+            } catch (PrivilegedActionException e) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Exception thrown from AccessController: " + e);
+                }
+                throw ExceptionFactory.makeWebServiceException(e.getException());
+            }
+        }
+
+        threadNumber++;
+        Thread returnThread = null;
+        try {
+            returnThread = (Thread) AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                public Object run() {
+                    Thread newThread = new Thread(threadGroup, r);
+                    newThread.setDaemon(true);
+                    return newThread;
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            throw ExceptionFactory.makeWebServiceException(e.getException());
+        }
+
+        return returnThread;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org