axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r328464 - in /webservices/axis2/trunk/java/modules/core: src/org/apache/axis2/clientapi/ src/org/apache/axis2/context/ src/org/apache/axis2/transport/mail/ src/org/apache/axis2/transport/tcp/ src/org/apache/axis2/util/threadpool/ test/org/a...
Date Tue, 25 Oct 2005 19:54:45 GMT
Author: dims
Date: Tue Oct 25 12:54:36 2005
New Revision: 328464

URL: http://svn.apache.org/viewcvs?rev=328464&view=rev
Log:
Introduce our own ThreadFactory, makes it real easy to write a wrapper around other Thread
pool implementations.

(based on Doug Lea's concurrent package - http://gee.cs.oswego.edu/dl/classes/index.html?EDU/oswego/cs/dl/util/concurrent/ThreadFactory.html)

TODO:
- need to pick up a config param and use that to instantiate the pool in ConfigurationContext



Added:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java
Removed:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/AxisWorker.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java
    webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/threadpool/TestThreadPool.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/InOutMEPClient.java
Tue Oct 25 12:54:36 2005
@@ -18,26 +18,22 @@
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
-import org.apache.axis2.deployment.util.PhasesInfo;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.context.OperationContextFactory;
 import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.description.OperationDescription;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisEngine;
-import org.apache.axis2.engine.AxisConfigurationImpl;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.om.OMException;
 import org.apache.axis2.soap.SOAPBody;
 import org.apache.axis2.soap.SOAPEnvelope;
 import org.apache.axis2.soap.SOAPFault;
 import org.apache.axis2.transport.TransportListener;
-import org.apache.axis2.util.threadpool.AxisWorker;
 import org.apache.axis2.util.UUIDGenerator;
 import org.apache.wsdl.WSDLConstants;
 
@@ -251,7 +247,7 @@
             } else {
                 //here a bloking invocation happens in a new thrad, so the progamming model
is
                 //non blocking
-                serviceContext.getEngineContext().getThreadPool().addWorker(new NonBlockingInvocationWorker(callback,
axisop, msgctx));
+                serviceContext.getEngineContext().getThreadPool().newThread(new NonBlockingInvocationWorker(callback,
axisop, msgctx));
             }
 
         } catch (OMException e) {
@@ -387,7 +383,7 @@
      * This Class is the workhorse for a Non Blocking invocation that uses a
      * two way transport
      */
-    private class NonBlockingInvocationWorker implements AxisWorker {
+    private class NonBlockingInvocationWorker implements Runnable {
 
         private Callback callback;
         private OperationDescription axisop;
@@ -401,12 +397,9 @@
             this.msgctx = msgctx;
         }
 
-        public void doWork() {
+        public void run() {
             try {
                 OperationContext opcontxt = new OperationContext(axisop,serviceContext);
-//                msgctx.setOperationContext(OperationContextFactory.createOperationContext(WSDLConstants.MEP_CONSTANT_IN_OUT,
-//                        axisop,
-//                        serviceContext));
                 msgctx.setOperationContext(opcontxt);
                 msgctx.setServiceContext(serviceContext);
                 //send the request and wait for reponse

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
Tue Oct 25 12:54:36 2005
@@ -22,6 +22,7 @@
 import org.apache.axis2.storage.AxisStorage;
 import org.apache.axis2.util.UUIDGenerator;
 import org.apache.axis2.util.threadpool.ThreadPool;
+import org.apache.axis2.util.threadpool.ThreadFactory;
 
 import javax.xml.namespace.QName;
 import java.io.File;
@@ -45,7 +46,7 @@
     private Map sessionContextMap;
     private Map moduleContextMap;
 
-    private transient ThreadPool threadPool;
+    private transient ThreadFactory threadPool;
 
     private File rootDir;
 
@@ -180,13 +181,22 @@
 
 
     /**
-     * @return the Gloal ThradPool
+     * Returns the thread factory
+     * @return configuration specific thread pool
      */
-    public ThreadPool getThreadPool() {
+    public ThreadFactory getThreadPool() {
         if (threadPool == null) {
             threadPool = new ThreadPool();
         }
         return threadPool;
+    }
+
+    /**
+     * Sets the thread factory
+     * @param pool
+     */
+    public void setThreadPool(ThreadFactory pool) {
+        threadPool = pool; 
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java
Tue Oct 25 12:54:36 2005
@@ -31,7 +31,6 @@
 import org.apache.axis2.soap.SOAPEnvelope;
 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.transport.mail.server.MailSrvConstants;
-import org.apache.axis2.util.threadpool.AxisWorker;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -45,7 +44,7 @@
 import java.io.ByteArrayInputStream;
 import java.util.Properties;
 
-public class MailWorker implements AxisWorker {
+public class MailWorker implements Runnable {
     protected static Log log = LogFactory.getLog(MailWorker.class.getName());
 
     private String contentType = "text/xml";
@@ -72,7 +71,7 @@
     /**
      * The main workhorse method.
      */
-    public void doWork() {
+    public void run() {
         AxisEngine engine = new AxisEngine(reg);
         MessageContext msgContext = null;
         // create and initialize a message context

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java
Tue Oct 25 12:54:36 2005
@@ -155,7 +155,7 @@
                         if (msg != null) {
                             MailWorker worker =
                                 new MailWorker(msg, configurationContext);
-                            worker.doWork();
+                            worker.run();
                         }
                         msg.setFlag(Flags.Flag.DELETED, true);
                     }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java
Tue Oct 25 12:54:36 2005
@@ -77,19 +77,15 @@
         while (started) {
             Socket socket = null;
             try {
-                try {
-                    socket = serversocket.accept();
-                } catch (java.io.InterruptedIOException iie) {
-                } catch (Exception e) {
-                    log.debug(e);
-                    break;
-                }
-                if (socket != null) {
-                    configContext.getThreadPool().addWorker(
-                            new TCPWorker(configContext, socket));
-                }
-            } catch (AxisFault e) {
-                log.error(e);
+                socket = serversocket.accept();
+            } catch (java.io.InterruptedIOException iie) {
+            } catch (Exception e) {
+                log.debug(e);
+                break;
+            }
+            if (socket != null) {
+                configContext.getThreadPool().newThread(
+                        new TCPWorker(configContext, socket));
             }
         }
 

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java
Tue Oct 25 12:54:36 2005
@@ -28,7 +28,6 @@
 import org.apache.axis2.om.impl.llom.builder.StAXBuilder;
 import org.apache.axis2.soap.SOAPEnvelope;
 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
-import org.apache.axis2.util.threadpool.AxisWorker;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -43,7 +42,7 @@
 /**
  * This Class is the work hoarse of the TCP request, this process the incomming SOAP Message.
 
  */
-public class TCPWorker implements AxisWorker {
+public class TCPWorker implements Runnable {
     protected Log log = LogFactory.getLog(getClass().getName());
     private ConfigurationContext configurationContext;
     private Socket socket;
@@ -53,7 +52,7 @@
         this.socket = socket;
     }
 
-    public void doWork() {
+    public void run() {
         MessageContext msgContext = null;
         try {
             AxisEngine engine = new AxisEngine(configurationContext);

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java?rev=328464&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java
(added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java
Tue Oct 25 12:54:36 2005
@@ -0,0 +1,5 @@
+package org.apache.axis2.util.threadpool;
+
+public interface ThreadFactory {
+    public void newThread(java.lang.Runnable runnable);
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java
Tue Oct 25 12:54:36 2005
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.util.threadpool;
 
 import org.apache.axis2.AxisFault;
@@ -12,11 +28,11 @@
 /**
  * This the thread pool for axis2. This class will be used a singleton
  * across axis2 engine. <code>ThreadPool</code> is accepts <code>AxisWorkers</code>
which has
- * doWork method on them and execute this method, using one of the threads
+ * run method on them and execute this method, using one of the threads
  * in the thread pool.
  */
 
-public class ThreadPool {
+public class ThreadPool implements ThreadFactory {
 
     protected static Log log = LogFactory.getLog(ThreadPool.class.getName());
 
@@ -24,7 +40,7 @@
     protected static long SLEEP_INTERVAL = 1000;
     private static List threads;
     private static List tasks;
-    private static boolean shoutDown;
+    private static boolean shutDown;
 
     public ThreadPool() {
         threads = new ArrayList();
@@ -39,15 +55,15 @@
 
     }
 
-    public void addWorker(AxisWorker worker) throws AxisFault {
-        if (shoutDown)
-            throw new AxisFault(Messages.getMessage("threadpoolshutdown"));
+    public void newThread(Runnable worker) {
+        if (shutDown)
+            throw new RuntimeException(Messages.getMessage("threadpoolshutdown"));
         tasks.add(worker);
     }
 
-    public synchronized AxisWorker getWorker() {
+    public synchronized Runnable getWorker() {
         if (!tasks.isEmpty()) {
-            AxisWorker worker = (AxisWorker) tasks.get(0);
+            Runnable worker = (Runnable) tasks.get(0);
             tasks.remove(worker);
             return worker;
         } else
@@ -63,7 +79,7 @@
      */
     public void safeShutDown() throws AxisFault {
         synchronized (this) {
-            shoutDown = true;
+            shutDown = true;
         }
         while (!tasks.isEmpty()) {
             try {

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java
Tue Oct 25 12:54:36 2005
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.util.threadpool;
 
 import org.apache.commons.logging.Log;
@@ -6,7 +22,7 @@
 /**
  * This is the thread worker for the Axis2's thread pool
  * This will pick a worker from the thread pool and executes its
- * <code>doWork()</code> method of the particular worker.
+ * <code>run()</code> method of the particular worker.
  */
 public class ThreadWorker extends Thread {
     protected static Log log = LogFactory.getLog(ThreadWorker.class.getName());
@@ -27,11 +43,11 @@
 
     public void run() {
         while (!stop) {
-            AxisWorker axisWorker = null;
+            Runnable axisWorker = null;
             try {
                 axisWorker = pool.getWorker();
                 if (axisWorker != null)
-                    axisWorker.doWork();
+                    axisWorker.run();
                 sleep(ThreadPool.SLEEP_INTERVAL);
             } catch (InterruptedException e) {
                 log.error(e);

Modified: webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/threadpool/TestThreadPool.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/threadpool/TestThreadPool.java?rev=328464&r1=328463&r2=328464&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/threadpool/TestThreadPool.java
(original)
+++ webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/util/threadpool/TestThreadPool.java
Tue Oct 25 12:54:36 2005
@@ -14,10 +14,10 @@
         super(testName);
     }
 
-    class TestWorker implements AxisWorker {
+    class TestWorker implements Runnable {
         private boolean workDone;
 
-        public void doWork() {
+        public void run() {
             workDone = true;
         }
 
@@ -34,7 +34,7 @@
         for (int i = 0; i < 5; i++) {
             TestWorker worker = new TestWorker();
             workerList.add(worker);
-            tPool.addWorker(worker);
+            tPool.newThread(worker);
         }
 
         tPool.safeShutDown();



Mime
View raw message