directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r385262 - in /directory/trunks/mina/core/src/main/java/org/apache/mina: common/ common/support/ filter/ transport/socket/nio/support/ transport/vmpipe/ transport/vmpipe/support/
Date Sun, 12 Mar 2006 09:26:42 GMT
Author: trustin
Date: Sun Mar 12 01:26:39 2006
New Revision: 385262

URL: http://svn.apache.org/viewcvs?rev=385262&view=rev
Log:
* Resolved issue: DIRMINA-190 (ThreadModel interface which encapsulates ThreadPoolFilter composition.)
** Added ThreadModel
** Added PooledThreadModel
** Adjusted default maximum pool size to 16

Added:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
  (with props)
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/ThreadModel.java   (with
props)
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/ThreadPoolFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- 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 Sun
Mar 12 01:26:39 2006
@@ -61,6 +61,16 @@
     DefaultIoFilterChainBuilder getFilterChain();
     
     /**
+     * Returns the default {@link ThreadModel} of the {@link IoService}.
+     */
+    ThreadModel getThreadModel();
+    
+    /**
+     * Sets the default {@link ThreadModel} of the {@link IoService}.
+     */
+    void setThreadModel( ThreadModel threadModel );
+    
+    /**
      * Returns a deep clone of this configuration.
      */
     Object clone();

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java?rev=385262&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
(added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
Sun Mar 12 01:26:39 2006
@@ -0,0 +1,77 @@
+package org.apache.mina.common;
+
+import org.apache.mina.filter.ThreadPoolFilter;
+
+public class PooledThreadModel implements ThreadModel
+{
+    /**
+     * @see ThreadPoolFilter#DEFAULT_MAXIMUM_POOL_SIZE
+     */
+    public static final int DEFAULT_MAXIMUM_POOL_SIZE = ThreadPoolFilter.DEFAULT_MAXIMUM_POOL_SIZE;
+
+    /**
+     * @see ThreadPoolFilter#DEFAULT_KEEP_ALIVE_TIME
+     */
+    public static final int DEFAULT_KEEP_ALIVE_TIME = ThreadPoolFilter.DEFAULT_KEEP_ALIVE_TIME;
+    
+    private static int id = 1;
+
+    private final ThreadPoolFilter filter;
+    
+    public PooledThreadModel()
+    {
+        this( "AnonymousIoService-" + id++, DEFAULT_MAXIMUM_POOL_SIZE );
+    }
+
+    public PooledThreadModel( String threadNamePrefix )
+    {
+        this( threadNamePrefix, DEFAULT_MAXIMUM_POOL_SIZE );
+    }
+
+    public PooledThreadModel( String threadNamePrefix, int maxThreads )
+    {
+        filter = new ThreadPoolFilter();
+        setMaximumPoolSize( maxThreads );
+        setThreadNamePrefix( threadNamePrefix );
+    }
+
+    public String getThreadNamePrefix()
+    {
+        return filter.getThreadNamePrefix();
+    }
+
+    public void setThreadNamePrefix( String threadNamePrefix )
+    {
+        filter.setThreadNamePrefix( threadNamePrefix );
+    }
+    
+    public int getPoolSize()
+    {
+        return filter.getPoolSize();
+    }
+
+    public int getMaximumPoolSize()
+    {
+        return filter.getMaximumPoolSize();
+    }
+
+    public int getKeepAliveTime()
+    {
+        return filter.getKeepAliveTime();
+    }
+
+    public void setMaximumPoolSize( int maximumPoolSize )
+    {
+        filter.setMaximumPoolSize( maximumPoolSize );
+    }
+
+    public void setKeepAliveTime( int keepAliveTime )
+    {
+        filter.setKeepAliveTime( keepAliveTime );
+    }
+
+    public void buildFilterChain( IoFilterChain chain ) throws Exception
+    {
+        chain.addFirst( PooledThreadModel.class.getName(), filter );
+    }
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/ThreadModel.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/ThreadModel.java?rev=385262&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/ThreadModel.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/ThreadModel.java Sun Mar
12 01:26:39 2006
@@ -0,0 +1,43 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 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.mina.common;
+
+/**
+ * Represents a thread model of an {@link IoService}.  There's no essential
+ * difference from {@link IoFilterChainBuilder}.  The only difference is that
+ * {@link ThreadModel} is executed later than the {@link IoFilterChainBuilder}
+ * you specified.  However, please don't abuse this internal behavior; it can
+ * change.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ThreadModel extends IoFilterChainBuilder
+{
+    /**
+     * A {@link ThreadModel} which make MINA not manage a thread model at all.
+     */
+    static final ThreadModel MANUAL = new ThreadModel()
+    {
+        public void buildFilterChain( IoFilterChain chain ) throws Exception
+        {
+            // Do nothing.
+        }
+    };
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/ThreadModel.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- 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
Sun Mar 12 01:26:39 2006
@@ -23,6 +23,8 @@
 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.ThreadModel;
 
 /**
  * A base implementation of {@link IoServiceConfig}.
@@ -36,6 +38,11 @@
      * Current filter chain builder.
      */
     private IoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
+    
+    /**
+     * Current thread model.
+     */
+    private ThreadModel threadModel = new PooledThreadModel();
 
     public BaseIoServiceConfig()
     {
@@ -69,6 +76,20 @@
         }
     }
     
+    public ThreadModel getThreadModel()
+    {
+        return threadModel;
+    }
+
+    public void setThreadModel( ThreadModel threadModel )
+    {
+        if( threadModel == null )
+        {
+            throw new NullPointerException( "threadModel" );
+        }
+        this.threadModel = threadModel;
+    }
+
     public Object clone()
     {
         BaseIoServiceConfig ret;

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ThreadPoolFilter.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/ThreadPoolFilter.java
Sun Mar 12 01:26:39 2006
@@ -59,9 +59,9 @@
 public class ThreadPoolFilter extends IoFilterAdapter
 {
     /**
-     * Default maximum size of thread pool (2G).
+     * Default maximum size of thread pool (16).
      */
-    public static final int DEFAULT_MAXIMUM_POOL_SIZE = Integer.MAX_VALUE;
+    public static final int DEFAULT_MAXIMUM_POOL_SIZE = 16;
 
     /**
      * Default keep-alive time of thread pool (1 min).

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
Sun Mar 12 01:26:39 2006
@@ -227,6 +227,7 @@
         {
             this.getFilterChainBuilder().buildFilterChain( s.getFilterChain() );
             req.config.getFilterChainBuilder().buildFilterChain( s.getFilterChain() );
+            req.config.getThreadModel().buildFilterChain( s.getFilterChain() );
             ( ( DatagramFilterChain ) s.getFilterChain() ).sessionCreated( s );
         }
         catch( Throwable t )

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
Sun Mar 12 01:26:39 2006
@@ -551,6 +551,7 @@
             {
                 getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
                 req.config.getFilterChainBuilder().buildFilterChain( session.getFilterChain()
);
+                req.config.getThreadModel().buildFilterChain( session.getFilterChain() );
                 ( ( DatagramFilterChain ) session.getFilterChain() ).sessionCreated( session
);
 
                 SelectionKey key = req.channel.register( selector,

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
Sun Mar 12 01:26:39 2006
@@ -410,6 +410,7 @@
                             req.address );
                     getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
                     req.config.getFilterChainBuilder().buildFilterChain( session.getFilterChain()
);
+                    req.config.getThreadModel().buildFilterChain( session.getFilterChain()
);
                     ( ( SocketFilterChain ) session.getFilterChain() ).sessionCreated( session
);
                     session.getManagedSessions().add( session );
                     session.getIoProcessor().addNew( session );

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
Sun Mar 12 01:26:39 2006
@@ -287,6 +287,7 @@
         {
             getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
             config.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
+            config.getThreadModel().buildFilterChain( session.getFilterChain() );
             ( ( SocketFilterChain ) session.getFilterChain() ).sessionCreated( session );
         }
         catch( Throwable e )

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
Sun Mar 12 01:26:39 2006
@@ -72,6 +72,7 @@
                         AnonymousSocketAddress.INSTANCE,
                         handler,
                         config.getFilterChainBuilder(),
+                        config.getThreadModel(),
                         entry );
             future.setSession( session );
         }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java?rev=385262&r1=385261&r2=385262&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
Sun Mar 12 01:26:39 2006
@@ -14,6 +14,7 @@
 import org.apache.mina.common.IoService;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.ThreadModel;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
@@ -45,7 +46,7 @@
      * Constructor for client-side session.
      */
     public VmPipeSessionImpl( IoService manager, Object lock, SocketAddress localAddress,
-                   IoHandler handler, IoFilterChainBuilder filterChainBuilder,
+                   IoHandler handler, IoFilterChainBuilder filterChainBuilder, ThreadModel
threadModel,
                    VmPipe remoteEntry ) throws IOException
     {
         this.manager = manager;
@@ -65,6 +66,7 @@
         {
             remoteEntry.getAcceptor().getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain()
);
             remoteEntry.getConfig().getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain()
);
+            remoteEntry.getConfig().getThreadModel().buildFilterChain( remoteSession.getFilterChain()
);
             ( ( VmPipeFilterChain ) remoteSession.getFilterChain() ).sessionCreated( remoteSession
);
         }
         catch( Throwable t )
@@ -80,6 +82,7 @@
         {
             manager.getFilterChainBuilder().buildFilterChain( filterChain );
             filterChainBuilder.buildFilterChain( filterChain );
+            threadModel.buildFilterChain( filterChain );
             handler.sessionCreated( this );
         }
         catch( Throwable t )



Mime
View raw message