geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r650745 - in /geronimo/sandbox/concurrent: geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/ geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ geronimo-concurrent-core/src/test/java/...
Date Wed, 23 Apr 2008 05:04:08 GMT
Author: gawor
Date: Tue Apr 22 22:04:04 2008
New Revision: 650745

URL: http://svn.apache.org/viewvc?rev=650745&view=rev
Log:
refactor managed thread factory a bit

Added:
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/BasicManagedThreadFactory.java
  (with props)
Modified:
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/AbstractManagedThreadFactory.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedExecutorServiceTest.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedScheduledExecutorServiceTest.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedExecutorServiceTest.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedScheduledExecutorServiceTest.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryTest.java
    geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/thread/GeronimoManagedThreadFactory.java

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/AbstractManagedThreadFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/AbstractManagedThreadFactory.java?rev=650745&r1=650744&r2=650745&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/AbstractManagedThreadFactory.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/AbstractManagedThreadFactory.java
Tue Apr 22 22:04:04 2008
@@ -16,9 +16,6 @@
  */
 package org.apache.geronimo.concurrent.thread;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.util.concurrent.ManagedThreadFactory;
@@ -26,17 +23,13 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public class AbstractManagedThreadFactory 
+public abstract class AbstractManagedThreadFactory 
     implements ManagedThreadFactory, ThreadLifecycleListener {
 
     private final static Log LOG = LogFactory.getLog(AbstractManagedThreadFactory.class);
     
     private static final AtomicInteger groupNumber = new AtomicInteger(1);
-    
-    protected List<ManagedThread> threads = 
-        Collections.synchronizedList(new ArrayList<ManagedThread>());
-    protected boolean stopped = false;
-    
+        
     private final AtomicInteger threadNumber = new AtomicInteger(1);    
     private int threadPriority = Thread.NORM_PRIORITY;   
     private boolean daemonThread = false;
@@ -96,7 +89,8 @@
         
     public Thread newThread(Runnable runnable) {
         if (!isRunning()) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException(
+                  "Component that created this thread factory is no longer running");
         }
         
         String name = this.threadGroup.getName() + "-t" + this.threadNumber.getAndIncrement();
       
@@ -104,11 +98,9 @@
         thread.setPriority(this.threadPriority);
         thread.setDaemon(this.daemonThread);
         thread.setHungTaskThreshold(this.hungTaskThreshold);
+                        
+        LOG.debug("Created thread: " + thread);
         
-        this.threads.add(thread);
-        
-        LOG.debug("Added thread: " + thread);
-                
         return thread;
     }
 
@@ -120,35 +112,10 @@
     }
     
     public void threadStopped(Thread thread) {        
-        this.threads.remove(thread);
-        
-        LOG.debug("Removed thread: " + thread);
-    }
-    
-    protected void updateStatus() {
-        List<ManagedThread> threadList = getThreadList();
-        for (ManagedThread thread : threadList) {
-            thread.updateState();
-        }
-    }
-    
-    protected List<ManagedThread> getThreadList() {
-        synchronized(this.threads) {
-            return new ArrayList<ManagedThread>(this.threads);
-        }
-    }
-    
-    public boolean isRunning() {
-        return !this.stopped;
-    }
-    
-    public void shutdown() {
-        this.stopped = true;
-        synchronized(this.threads) {
-            for (Thread thread : this.threads) {
-                thread.interrupt();               
-            }
-        }
     }
+        
+    public abstract boolean isRunning();
+            
+    public abstract void shutdown(); 
         
 }

Added: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/BasicManagedThreadFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/BasicManagedThreadFactory.java?rev=650745&view=auto
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/BasicManagedThreadFactory.java
(added)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/BasicManagedThreadFactory.java
Tue Apr 22 22:04:04 2008
@@ -0,0 +1,78 @@
+/**
+ *  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.geronimo.concurrent.thread;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class BasicManagedThreadFactory extends AbstractManagedThreadFactory {
+   
+    private final static Log LOG = LogFactory.getLog(BasicManagedThreadFactory.class);
+          
+    protected List<ManagedThread> threads = 
+        Collections.synchronizedList(new ArrayList<ManagedThread>());
+    protected boolean stopped = false;
+                             
+    @Override
+    public Thread newThread(Runnable runnable) {
+        ManagedThread thread = (ManagedThread)super.newThread(runnable);
+                
+        this.threads.add(thread);
+        
+        LOG.debug("Added thread: " + thread);
+                
+        return thread;
+    }
+    
+    @Override
+    public void threadStopped(Thread thread) {        
+        this.threads.remove(thread);
+        
+        LOG.debug("Removed thread: " + thread);
+    }
+    
+    protected void updateStatus() {
+        List<ManagedThread> threadList = getThreadList();
+        for (ManagedThread thread : threadList) {
+            thread.updateState();
+        }
+    }
+    
+    protected List<ManagedThread> getThreadList() {
+        synchronized(this.threads) {
+            return new ArrayList<ManagedThread>(this.threads);
+        }
+    }
+    
+    public boolean isRunning() {
+        return !this.stopped;
+    }
+    
+    public void shutdown() {
+        this.stopped = true;
+        synchronized(this.threads) {
+            for (Thread thread : this.threads) {
+                thread.interrupt();               
+            }
+        }
+    }
+        
+}

Propchange: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/BasicManagedThreadFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedExecutorServiceTest.java?rev=650745&r1=650744&r2=650745&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedExecutorServiceTest.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedExecutorServiceTest.java
Tue Apr 22 22:04:04 2008
@@ -24,8 +24,7 @@
 import org.apache.geronimo.concurrent.ManagedContextHandler;
 import org.apache.geronimo.concurrent.ManagedContextHandlerChain;
 import org.apache.geronimo.concurrent.TestContextHandler;
-import org.apache.geronimo.concurrent.executor.ComponentManagedExecutorService;
-import org.apache.geronimo.concurrent.thread.AbstractManagedThreadFactory;
+import org.apache.geronimo.concurrent.thread.BasicManagedThreadFactory;
 
 public class ComponentManagedExecutorServiceTest extends BasicManagedExecutorServiceTest
{
            
@@ -49,7 +48,7 @@
                   getManagedContextHandler());
         }
         private static ManagedThreadFactory getManagedThreadFactory() {
-            AbstractManagedThreadFactory factory = new AbstractManagedThreadFactory();
+            ManagedThreadFactory factory = new BasicManagedThreadFactory();
             return factory;
         }
         private static ManagedContextHandler getManagedContextHandler() {

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedScheduledExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedScheduledExecutorServiceTest.java?rev=650745&r1=650744&r2=650745&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedScheduledExecutorServiceTest.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ComponentManagedScheduledExecutorServiceTest.java
Tue Apr 22 22:04:04 2008
@@ -21,8 +21,7 @@
 import org.apache.geronimo.concurrent.ManagedContextHandler;
 import org.apache.geronimo.concurrent.ManagedContextHandlerChain;
 import org.apache.geronimo.concurrent.TestContextHandler;
-import org.apache.geronimo.concurrent.executor.ComponentManagedScheduledExecutorService;
-import org.apache.geronimo.concurrent.thread.AbstractManagedThreadFactory;
+import org.apache.geronimo.concurrent.thread.BasicManagedThreadFactory;
 
 public class ComponentManagedScheduledExecutorServiceTest extends BasicManagedScheduledExecutorServiceTest
{
            
@@ -46,7 +45,7 @@
                   getManagedContextHandler());
         }
         private static ManagedThreadFactory getManagedThreadFactory() {
-            AbstractManagedThreadFactory factory = new AbstractManagedThreadFactory();
+            ManagedThreadFactory factory = new BasicManagedThreadFactory();
             return factory;
         }
         private static ManagedContextHandler getManagedContextHandler() {

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedExecutorServiceTest.java?rev=650745&r1=650744&r2=650745&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedExecutorServiceTest.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedExecutorServiceTest.java
Tue Apr 22 22:04:04 2008
@@ -24,8 +24,7 @@
 import org.apache.geronimo.concurrent.ManagedContextHandler;
 import org.apache.geronimo.concurrent.ManagedContextHandlerChain;
 import org.apache.geronimo.concurrent.TestContextHandler;
-import org.apache.geronimo.concurrent.executor.ServerManagedExecutorService;
-import org.apache.geronimo.concurrent.thread.AbstractManagedThreadFactory;
+import org.apache.geronimo.concurrent.thread.BasicManagedThreadFactory;
 
 public class ServerManagedExecutorServiceTest extends BasicManagedExecutorServiceTest {
                
@@ -49,7 +48,7 @@
                   getManagedContextHandler());
         }
         private static ManagedThreadFactory getManagedThreadFactory() {
-            AbstractManagedThreadFactory factory = new AbstractManagedThreadFactory();
+            ManagedThreadFactory factory = new BasicManagedThreadFactory();
             return factory;
         }
         private static ManagedContextHandler getManagedContextHandler() {

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedScheduledExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedScheduledExecutorServiceTest.java?rev=650745&r1=650744&r2=650745&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedScheduledExecutorServiceTest.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/ServerManagedScheduledExecutorServiceTest.java
Tue Apr 22 22:04:04 2008
@@ -21,8 +21,7 @@
 import org.apache.geronimo.concurrent.ManagedContextHandler;
 import org.apache.geronimo.concurrent.ManagedContextHandlerChain;
 import org.apache.geronimo.concurrent.TestContextHandler;
-import org.apache.geronimo.concurrent.executor.ServerManagedScheduledExecutorService;
-import org.apache.geronimo.concurrent.thread.AbstractManagedThreadFactory;
+import org.apache.geronimo.concurrent.thread.BasicManagedThreadFactory;
 
 public class ServerManagedScheduledExecutorServiceTest extends BasicManagedScheduledExecutorServiceTest
{
                
@@ -46,7 +45,7 @@
                   getManagedContextHandler());
         }
         private static ManagedThreadFactory getManagedThreadFactory() {
-            AbstractManagedThreadFactory factory = new AbstractManagedThreadFactory();
+            ManagedThreadFactory factory = new BasicManagedThreadFactory();
             return factory;
         }
         private static ManagedContextHandler getManagedContextHandler() {

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryTest.java?rev=650745&r1=650744&r2=650745&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryTest.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryTest.java
Tue Apr 22 22:04:04 2008
@@ -26,7 +26,6 @@
 
 import org.apache.geronimo.concurrent.ManagedContextHandlerChain;
 import org.apache.geronimo.concurrent.TestContextHandler;
-import org.apache.geronimo.concurrent.thread.AbstractManagedThreadFactory;
 import org.apache.geronimo.concurrent.thread.ManagedThread;
 import org.apache.geronimo.concurrent.thread.ManagedThreadFactoryUtils;
 
@@ -35,7 +34,7 @@
 public class ManagedThreadFactoryTest extends TestCase {
     
     private ManagedThreadFactory getManagedThreadFactory() {
-        AbstractManagedThreadFactory factory = new AbstractManagedThreadFactory();
+        ManagedThreadFactory factory = new BasicManagedThreadFactory();
         ManagedContextHandlerChain chain = new ManagedContextHandlerChain();
         chain.addManagedContextHandler(new TestContextHandler());
         return ManagedThreadFactoryUtils.createStandaloneThreadFactory(factory, chain); 
  

Modified: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/thread/GeronimoManagedThreadFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/thread/GeronimoManagedThreadFactory.java?rev=650745&r1=650744&r2=650745&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/thread/GeronimoManagedThreadFactory.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/thread/GeronimoManagedThreadFactory.java
Tue Apr 22 22:04:04 2008
@@ -19,10 +19,10 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.geronimo.concurrent.thread.AbstractManagedThreadFactory;
+import org.apache.geronimo.concurrent.thread.BasicManagedThreadFactory;
 import org.apache.geronimo.concurrent.thread.ManagedThread;
 
-public class GeronimoManagedThreadFactory extends AbstractManagedThreadFactory {
+public class GeronimoManagedThreadFactory extends BasicManagedThreadFactory {
     
     // gbean that manages this object
     private ManagedThreadFactoryGBean factoryGBean;



Mime
View raw message