directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r441365 - in /directory/trunks/mina: core/src/main/java/org/apache/mina/common/ core/src/main/java/org/apache/mina/common/support/ core/src/main/java/org/apache/mina/filter/ core/src/main/java/org/apache/mina/filter/executor/ core/src/test/...
Date Fri, 08 Sep 2006 03:38:21 GMT
Author: trustin
Date: Thu Sep  7 20:38:20 2006
New Revision: 441365

URL: http://svn.apache.org/viewvc?view=rev&rev=441365
Log:
Resolved issue: DIRMINA-245 (MINA does not fire read events)
Resolved issue: DIRMINA-260 (Utilize backport-util-concurrent Executor)
* Renamed:
** ThreadPoolFilter -> ExecutorFilter
** PooledThreadModel -> ExecutorThreadModel
** org.apache.mina.filter.thread -> org.apache.mina.filter.executor


Added:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/ExecutorThreadModel.java
      - copied, changed from r441348, directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilter.java
      - copied, changed from r441348, directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilterMBean.java
      - copied, changed from r441348, directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilterMBean.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java
      - copied, changed from r441349, directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ThreadPoolFilterRegressionTest.java
    directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorExecutor.java
      - copied, changed from r441348, directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorThreadPool.java
Removed:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/LeaderFollowersThreadPool.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPool.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilterMBean.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ThreadPoolFilterRegressionTest.java
    directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorThreadPool.java
Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ReadThrottleFilterBuilder.java

Copied: directory/trunks/mina/core/src/main/java/org/apache/mina/common/ExecutorThreadModel.java
(from r441348, directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java)
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/ExecutorThreadModel.java?view=diff&rev=441365&p1=directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java&r1=441348&p2=directory/trunks/mina/core/src/main/java/org/apache/mina/common/ExecutorThreadModel.java&r2=441365
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/ExecutorThreadModel.java
Thu Sep  7 20:38:20 2006
@@ -22,62 +22,53 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.mina.filter.executor.ThreadPool;
-import org.apache.mina.filter.executor.ThreadPoolFilter;
+import org.apache.mina.filter.executor.ExecutorFilter;
+
+import edu.emory.mathcs.backport.java.util.concurrent.Executor;
+import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory;
+import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
 
 /**
- * A {@link ThreadModel} which represents a thread model with an independant
- * thread pool per service.
- * <p>
- * Please note that reusing an instance of this model means a thread pool
- * is shared among multiple services.  If don't want to shared a thread pool,
- * please create each instance of this model whenever you bind a service or
- * connect to a remote service.
- * </p>
+ * A {@link ThreadModel} which represents a thread model with an {@link Executor}
+ * (from <a href="http://dcl.mathcs.emory.edu/util/backport-util-concurrent/">backport-util-concurrent</a>)
+ * per service.  The default underlying {@link Executor} is {@link ThreadPoolExecutor},
+ * so you can safely downcast the returned {@link Executor} of {@link #getExecutor()} to
+ * {@link ThreadPoolExecutor} by default.
  * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class PooledThreadModel implements ThreadModel
+public class ExecutorThreadModel implements ThreadModel
 {
     /**
-     * @see ThreadPool#DEFAULT_MAXIMUM_POOL_SIZE
-     */
-    public static final int DEFAULT_MAXIMUM_POOL_SIZE = ThreadPool.DEFAULT_MAXIMUM_POOL_SIZE;
-
-    /**
-     * @see ThreadPool#DEFAULT_KEEP_ALIVE_TIME
-     */
-    public static final int DEFAULT_KEEP_ALIVE_TIME = ThreadPool.DEFAULT_KEEP_ALIVE_TIME;
-    
-    /**
      * Maps a service name to a PooledThreadModel instance.
      * Without this map, we might create extremely many thread pools that leads the system
to
      * coma. */
     private static final Map service2model = new HashMap();
     
     /**
-     * Returns a {@link PooledThreadModel} instance for the specified <tt>serviceName</tt>.
+     * Returns a {@link ExecutorThreadModel} instance for the specified <tt>serviceName</tt>.
      * Please note that all returned instances will be managed globally; the same instance
      * will be returned if you specified the same service name.  Please try to specify
      * different names for different services.
      * 
      * @param serviceName the name of the service that needs thread pooling
      */
-    public static PooledThreadModel getInstance( String serviceName )
+    public static ExecutorThreadModel getInstance( String serviceName )
     {
         if( serviceName == null )
         {
             throw new NullPointerException( "serviceName" );
         }
 
-        PooledThreadModel model;
+        ExecutorThreadModel model;
         synchronized( service2model )
         {
-            model = ( PooledThreadModel ) service2model.get( serviceName );
+            model = ( ExecutorThreadModel ) service2model.get( serviceName );
             if( model == null )
             {
-                model = new PooledThreadModel( serviceName );
+                model = new ExecutorThreadModel( serviceName );
                 service2model.put( serviceName, model );
             }
         }
@@ -85,42 +76,67 @@
         return model;
     }
     
-    private ThreadPoolFilter filter = new ThreadPoolFilter();
+    private final String threadNamePrefix;
+    private final ExecutorFilter defaultFilter;
+    private ExecutorFilter filter = new ExecutorFilter();
 
-    private PooledThreadModel( String threadNamePrefix )
+    private ExecutorThreadModel( String threadNamePrefix )
     {
-        this( threadNamePrefix, DEFAULT_MAXIMUM_POOL_SIZE );
-    }
+        this.threadNamePrefix = threadNamePrefix;
+        
+        // Create the default filter
+        defaultFilter = new ExecutorFilter();
+        ThreadPoolExecutor tpe = ( ThreadPoolExecutor ) defaultFilter.getExecutor();
+        final ThreadFactory originalThreadFactory = tpe.getThreadFactory();
+        ThreadFactory newThreadFactory = new ThreadFactory()
+        {
+            private final AtomicInteger threadId = new AtomicInteger( 0 );
 
-    private PooledThreadModel( String threadNamePrefix, int maxThreads )
-    {
-        getThreadPool().setMaximumPoolSize( maxThreads );
-        getThreadPool().setThreadNamePrefix( threadNamePrefix );
+            public Thread newThread( Runnable runnable )
+            {
+                Thread t = originalThreadFactory.newThread( runnable );
+                t.setName( ExecutorThreadModel.this.threadNamePrefix + '-' + threadId.incrementAndGet()
);
+                t.setDaemon( true );
+                return t;
+            }
+        };
+        tpe.setThreadFactory( newThreadFactory );
+        
+        // Set to default.
+        setExecutor( null );
     }
 
     /**
-     * Returns the underlying {@link ThreadPool} of this model.
+     * Returns the underlying {@link Executor} of this model.
      * You can change various properties such as the number of threads
-     * by calling methods of {@link ThreadPool}.
+     * by calling methods of the {@link Executor} implementation.
      */
-    public ThreadPool getThreadPool()
+    public Executor getExecutor()
     {
-        return filter.getThreadPool();
+        return filter.getExecutor();
     }
     
     /**
-     * Changes the underlying {@link ThreadPool} of this model.
-     * Previous settings such as thread name prefix and the number
-     * of threads should be configured again. Only newly created
-     * {@link IoSession}s will be affected.
+     * Changes the underlying {@link Executor} of this model.
+     * Previous settings such as the number of threads should be configured again.
+     * Only newly created {@link IoSession}s will be affected.
+     * 
+     * @param executor <tt>null</tt> to revert to the default setting
      */
-    public void setThreadPool( ThreadPool threadPool )
+    public void setExecutor( Executor executor )
     {
-        filter = new ThreadPoolFilter( threadPool );
+        if( executor == null )
+        {
+            filter = defaultFilter;
+        }
+        else
+        {
+            filter = new ExecutorFilter( executor );
+        }
     }
 
     public void buildFilterChain( IoFilterChain chain ) throws Exception
     {
-        chain.addFirst( PooledThreadModel.class.getName(), filter );
+        chain.addFirst( ExecutorThreadModel.class.getName(), filter );
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java?view=diff&rev=441365&r1=441364&r2=441365
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java Thu
Sep  7 20:38:20 2006
@@ -63,10 +63,10 @@
     
     /**
      * Returns the default {@link ThreadModel} of the {@link IoService}.
-     * The default value is a {@link PooledThreadModel}() whose service name is
+     * The default value is a {@link ExecutorThreadModel}() whose service name is
      * <tt>'AnonymousIoService'</tt> and which has 16 maximum active threads.
-     * It is strongly recommended to set a new {@link PooledThreadModel} by calling
-     * {@link PooledThreadModel#getInstance(String)}.
+     * It is strongly recommended to set a new {@link ExecutorThreadModel} by calling
+     * {@link ExecutorThreadModel#getInstance(String)}.
      */
     ThreadModel getThreadModel();
     
@@ -74,10 +74,10 @@
      * Sets the default {@link ThreadModel} of the {@link IoService}.
      * If you specify <tt>null</tt>, this property will be set to the
      * default value.
-     * The default value is a {@link PooledThreadModel}() whose service name is
+     * The default value is a {@link ExecutorThreadModel}() whose service name is
      * <tt>'AnonymousIoService'</tt> and which has 16 maximum active threads.
-     * It is strongly recommended to set a new {@link PooledThreadModel} by calling
-     * {@link PooledThreadModel#getInstance(String)}.
+     * It is strongly recommended to set a new {@link ExecutorThreadModel} by calling
+     * {@link ExecutorThreadModel#getInstance(String)}.
      */
     void setThreadModel( ThreadModel threadModel );
     

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java?view=diff&rev=441365&r1=441364&r2=441365
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
Thu Sep  7 20:38:20 2006
@@ -24,7 +24,7 @@
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoFilterChainBuilder;
 import org.apache.mina.common.IoServiceConfig;
-import org.apache.mina.common.PooledThreadModel;
+import org.apache.mina.common.ExecutorThreadModel;
 import org.apache.mina.common.ThreadModel;
 
 /**
@@ -43,7 +43,7 @@
     /**
      * The default thread model.
      */
-    private final ThreadModel defaultThreadModel = PooledThreadModel.getInstance("AnonymousIoService");
+    private final ThreadModel defaultThreadModel = ExecutorThreadModel.getInstance("AnonymousIoService");
     
     /**
      * Current thread model.

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ReadThrottleFilterBuilder.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ReadThrottleFilterBuilder.java?view=diff&rev=441365&r1=441364&r2=441365
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ReadThrottleFilterBuilder.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ReadThrottleFilterBuilder.java
Thu Sep  7 20:38:20 2006
@@ -27,7 +27,7 @@
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.executor.ThreadPoolFilter;
+import org.apache.mina.filter.executor.ExecutorFilter;
 
 /**
  * This filter will automatically disable reads on an <code>IoSession</code>
once the data batched for that session in
@@ -111,7 +111,7 @@
         {
             IoFilterChain.Entry entry = (IoFilterChain.Entry)i.next();
 
-            if( entry.getFilter().getClass().isAssignableFrom( ThreadPoolFilter.class ) )
+            if( entry.getFilter().getClass().isAssignableFrom( ExecutorFilter.class ) )
             {
                 return entry.getName();
             }

Copied: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilter.java
(from r441348, directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilter.java)
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilter.java?view=diff&rev=441365&p1=directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilter.java&r1=441348&p2=directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilter.java&r2=441365
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilter.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilter.java
Thu Sep  7 20:38:20 2006
@@ -25,77 +25,63 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.ThreadModel;
 import org.apache.mina.util.ByteBufferUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import edu.emory.mathcs.backport.java.util.concurrent.Executor;
+import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
+import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
+import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
+
 /**
- * A Thread-pooling filter.  This filter forwards {@link IoHandler} events to its thread
pool.
+ * A filter that forward events to {@link Executor} in
+ * <a href="http://dcl.mathcs.emory.edu/util/backport-util-concurrent/">backport-util-concurrent</a>.
+ * You can apply various thread model by inserting this filter to the {@link IoFilterChain}.
+ * This filter is usually inserted by {@link ThreadModel} automatically, so you don't need
+ * to add this filter in most cases.
  * <p>
- * Use the {@link #init()} and {@link #destroy()} methods to force this filter
- * to start/stop processing events. Alternatively, {@link #init()} will be
- * called automatically the first time an instance of this filter is added
- * to a filter chain. Calling {@link #destroy()} is not required either since
- * all workers are daemon threads which means that any workers still alive
- * when the JVM terminates will die automatically.
+ * Please note that this filter doesn't manage the life cycle of the underlying
+ * {@link Executor}.  You have to destroy or stop it by yourself.
  *
  * <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 350169 $, $Date: 2005-12-01 00:17:41 -0500 (Thu, 01 Dec 2005) $
  */
-public class ThreadPoolFilter extends IoFilterAdapter
+public class ExecutorFilter extends IoFilterAdapter
 {
-    private static final Logger logger = LoggerFactory.getLogger( ThreadPoolFilter.class.getName()
);
-    private final ThreadPool threadPool;
+    private static final Logger logger = LoggerFactory.getLogger( ExecutorFilter.class.getName()
);
+    private final Executor executor;
 
     /**
      * Creates a new instace with the default thread pool implementation
-     * (@link LeaderFollowersThreadPool}).
+     * (<tt>new ThreadPoolExecutor(16, 16, 60, TimeUnit.SECONDS, new LinkedBlockingQueue()
)</tt>).
      */
-    public ThreadPoolFilter()
+    public ExecutorFilter()
     {
-        this( new LeaderFollowersThreadPool() );
+        this( new ThreadPoolExecutor(16, 16, 60, TimeUnit.SECONDS, new LinkedBlockingQueue()
) );
     }
     
     /**
-     * Creates a new instance with the specified <tt>threadPool</tt>.
+     * Creates a new instance with the specified <tt>executor</tt>.
      */
-    public ThreadPoolFilter( ThreadPool threadPool )
+    public ExecutorFilter( Executor executor )
     {
-        if( threadPool == null )
+        if( executor == null )
         {
-            throw new NullPointerException( "threadPool" );
+            throw new NullPointerException( "executor" );
         }
 
-        this.threadPool = threadPool;
-    }
-
-    public void init()
-    {
-        threadPool.init();
-    }
-
-    public void destroy()
-    {
-        threadPool.destroy();
-    }
-    
-    public void onPreAdd( IoFilterChain parent, String name, NextFilter nextFilter )
-            throws Exception
-    {
-        if( !getThreadPool().isStarted() )
-        {
-            init();
-        }
+        this.executor = executor;
     }
 
     /**
-     * Returns the underlying {@link ThreadPool} instance this filter uses.
+     * Returns the underlying {@link Executor} instance this filter uses.
      */
-    public ThreadPool getThreadPool()
+    public Executor getExecutor()
     {
-        return threadPool;
+        return executor;
     }
 
     private void fireEvent( NextFilter nextFilter, IoSession session,
@@ -114,7 +100,7 @@
                     logger.debug( "Launching thread for " + session.getRemoteAddress() );
                 }
 
-                threadPool.submit( new ProcessEventsRunnable( buf ) );
+                executor.execute( new ProcessEventsRunnable( buf ) );
             }
         }
     }

Copied: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilterMBean.java
(from r441348, directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilterMBean.java)
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilterMBean.java?view=diff&rev=441365&p1=directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilterMBean.java&r1=441348&p2=directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilterMBean.java&r2=441365
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ThreadPoolFilterMBean.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/executor/ExecutorFilterMBean.java
Thu Sep  7 20:38:20 2006
@@ -19,7 +19,7 @@
  */
 package org.apache.mina.filter.executor;
 
-public interface ThreadPoolFilterMBean
+public interface ExecutorFilterMBean
 {
     String getThreadNamePrefix();
 

Copied: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java
(from r441349, directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ThreadPoolFilterRegressionTest.java)
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java?view=diff&rev=441365&p1=directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ThreadPoolFilterRegressionTest.java&r1=441349&p2=directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java&r2=441365
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ThreadPoolFilterRegressionTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java
Thu Sep  7 20:38:20 2006
@@ -33,42 +33,29 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.NextFilter;
 import org.apache.mina.common.IoFilter.WriteRequest;
-import org.apache.mina.common.support.AbstractIoFilterChain;
 import org.apache.mina.common.support.BaseIoSession;
-import org.apache.mina.common.support.DefaultWriteFuture;
-import org.apache.mina.filter.executor.ThreadPoolFilter;
 
-public class ThreadPoolFilterRegressionTest extends TestCase
-{
-    private static final IoFilterChain FILTER_PARENT = new AbstractIoFilterChain( new DummySession()
)
-    {
-        protected void doWrite( IoSession session, WriteRequest writeRequest )
-        {
-        }
-        protected void doClose( IoSession session )
-        {
-        }
-    };
+import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
+import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
 
-    private ThreadPoolFilter filter;
+public class ExecutorFilterRegressionTest extends TestCase
+{
+    private ExecutorFilter filter;
     
-    public ThreadPoolFilterRegressionTest()
+    public ExecutorFilterRegressionTest()
     {
     }
     
     public void setUp() throws Exception
     {
-        filter = new ThreadPoolFilter();
-        filter.init();
+        filter = new ExecutorFilter();
     }
     
     public void tearDown() throws Exception
     {
-        filter.destroy();
-        Assert.assertEquals( 0, filter.getThreadPool().getPoolSize() );
+        ( ( ThreadPoolExecutor ) filter.getExecutor() ).shutdown();
         filter = null;
     }
     
@@ -90,8 +77,8 @@
         };
         final int loop = 1000000;
         final int end = sessions.length - 1;
-        final ThreadPoolFilter filter = this.filter;
-        filter.getThreadPool().setKeepAliveTime( 3000 );
+        final ExecutorFilter filter = this.filter;
+        ( ( ThreadPoolExecutor ) filter.getExecutor() ).setKeepAliveTime( 3, TimeUnit.SECONDS
);
         
         for( int i = 0; i < loop ; i++ )
         {
@@ -108,54 +95,14 @@
             }
         }
         
-        Thread.sleep( 3500 );
+        Thread.sleep( 1000 );
         
-        Assert.assertEquals( 1, filter.getThreadPool().getPoolSize() );
         for( int i = end; i >= 0; i-- )
         {
             Assert.assertEquals( loop - 1, sessions[ i ].lastCount.intValue() );
         }
     }
     
-    public void testShutdown() throws Exception
-    {
-        final IoSession[] sessions = new IoSession[]
-        {
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-            new DummySession(),
-        };
-        final int end = sessions.length - 1;
-        final NextFilter nextFilter = new DummyNextFilter();
-
-        for( int i = 0; i < 100000; i ++ )
-        {
-            if( i % 1000 == 0 )
-            {
-                System.out.println( "Shutdown: " + i );
-            }
-            
-            WriteFuture future = null;
-            for( int j = end; j >= 0; j-- )
-            {
-                future = new DefaultWriteFuture( sessions[ j ] );
-                filter.messageReceived( nextFilter, sessions[ j ], future );
-            }
-            
-            future.join();
-            
-            filter.onPostRemove( FILTER_PARENT, "", null );
-            filter.onPostAdd( FILTER_PARENT, "", null );
-        }
-    }
-    
     private static class EventOrderCounter extends BaseIoSession
     {
         private Integer lastCount = null;
@@ -292,120 +239,8 @@
         }
     }
     
-    private static class DummySession extends BaseIoSession
-    {
-        protected void updateTrafficMask()
-        {
-        }
-
-        public IoHandler getHandler()
-        {
-            return null;
-        }
-
-        public IoFilterChain getFilterChain()
-        {
-            return null;
-        }
-
-        public CloseFuture close()
-        {
-            return null;
-        }
-
-        public TransportType getTransportType()
-        {
-            return null;
-        }
-
-        public SocketAddress getRemoteAddress()
-        {
-            return null;
-        }
-
-        public SocketAddress getLocalAddress()
-        {
-            return null;
-        }
-
-        public int getScheduledWriteRequests()
-        {
-            return 0;
-        }
-
-        public boolean isClosing()
-        {
-            return false;
-        }
-
-        public IoService getService()
-        {
-            return null;
-        }
-
-        public IoServiceConfig getServiceConfig()
-        {
-            return null;
-        }
-
-        public IoSessionConfig getConfig()
-        {
-            return null;
-        }
-
-        public SocketAddress getServiceAddress()
-        {
-            return null;
-        }
-
-        public int getScheduledWriteBytes()
-        {
-            return 0;
-        }
-    }
-    
-    private static class DummyNextFilter implements NextFilter
-    {
-        public void sessionCreated( IoSession session )
-        {
-        }
-
-        public void sessionOpened( IoSession session )
-        {
-        }
-
-        public void sessionClosed( IoSession session )
-        {
-        }
-
-        public void sessionIdle( IoSession session, IdleStatus status )
-        {
-        }
-
-        public void exceptionCaught( IoSession session, Throwable cause )
-        {
-        }
-
-        public void messageReceived( IoSession session, Object message )
-        {
-            ( ( DefaultWriteFuture ) message ).setWritten( true );
-        }
-
-        public void messageSent( IoSession session, Object message )
-        {
-        }
-
-        public void filterWrite( IoSession session, WriteRequest writeRequest )
-        {
-        }
-
-        public void filterClose( IoSession session )
-        {
-        }
-    }
-    
     public static void main( String[] args )
     {
-        junit.textui.TestRunner.run( ThreadPoolFilterRegressionTest.class );
+        junit.textui.TestRunner.run( ExecutorFilterRegressionTest.class );
     }
 }

Copied: directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorExecutor.java
(from r441348, directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorThreadPool.java)
URL: http://svn.apache.org/viewvc/directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorExecutor.java?view=diff&rev=441365&p1=directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorThreadPool.java&r1=441348&p2=directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorExecutor.java&r2=441365
==============================================================================
--- directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorThreadPool.java
(original)
+++ directory/trunks/mina/java5/src/main/java/org/apache/mina/filter/executor/ExecutorExecutor.java
Thu Sep  7 20:38:20 2006
@@ -19,29 +19,23 @@
  */
 package org.apache.mina.filter.executor;
 
-import java.util.concurrent.Executor;
-
-import org.apache.mina.filter.executor.ThreadPool;
+import edu.emory.mathcs.backport.java.util.concurrent.Executor;
 
 /**
- * {@link ThreadPool} implementation that hands excecution off to an
- * {@link Executor}.  This pool doesn't manage the life cycle of the
- * underlying {@link Executor} at all.  {@link #isStarted()} will always
- * return <tt>true</tt>.  Other properties won't be supported, either.
- * Please get the underlying {@link Executor} by calling {@link #getExecutor()}
- * to adjust implementation-specific parameters.
+ * A <a href="http://dcl.mathcs.emory.edu/util/backport-util-concurrent/">backport-util-concurrent</a>
+ * {@link Executor} which adapts Java 5 <tt>java.util.concurrent.</tt>{@link
java.util.concurrent.Executor}.
  *
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev: 400068 $, $Date: 2006-05-05 12:56:58Z $
  */
-public class ExecutorThreadPool implements ThreadPool
+public class ExecutorExecutor implements Executor
 {
-    private final Executor executor;
+    private final java.util.concurrent.Executor executor;
 
     /**
      * Creates a new instance with the specified <tt>executor</tt>.
      */
-    public ExecutorThreadPool( Executor executor )
+    public ExecutorExecutor( java.util.concurrent.Executor executor )
     {
         this.executor = executor;
     }
@@ -49,58 +43,13 @@
     /**
      * Returns the underlying executor this thread pool wraps.
      */
-    public Executor getExecutor()
+    public java.util.concurrent.Executor getExecutor()
     {
         return executor;
     }
 
-    public void init()
-    {
-    }
-
-    public void destroy()
-    {
-    }
-
-    public void submit( Runnable runnable )
+    public void execute( Runnable runnable )
     {
         executor.execute( runnable );
-    }
-
-    public boolean isStarted()
-    {
-        return true;
-    }
-
-    public String getThreadNamePrefix()
-    {
-        return null;
-    }
-
-    public void setThreadNamePrefix( String threadNamePrefix )
-    {
-    }
-
-    public int getPoolSize()
-    {
-        return -1;
-    }
-
-    public int getMaximumPoolSize()
-    {
-        return -1;
-    }
-
-    public int getKeepAliveTime()
-    {
-        return -1;
-    }
-
-    public void setMaximumPoolSize( int maximumPoolSize )
-    {
-    }
-
-    public void setKeepAliveTime( int keepAliveTime )
-    {
     }
 }



Mime
View raw message