directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r350147 - in /directory/network/branches/chain_refactor/src: java/org/apache/mina/common/ java/org/apache/mina/common/support/ java/org/apache/mina/filter/ java/org/apache/mina/filter/codec/ test/org/apache/mina/common/ test/org/apache/mina...
Date Thu, 01 Dec 2005 04:06:22 GMT
Author: trustin
Date: Wed Nov 30 20:06:11 2005
New Revision: 350147

URL: http://svn.apache.org/viewcvs?rev=350147&view=rev
Log:
Resolved issue: DIRMINA-123 Race condition in AbstractIoFilterChain
* Now IoFilter has both pre and post hook methods, so we can avoid the race condition.

Modified:
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilter.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterAdapter.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterChain.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/LoggingFilter.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/SSLFilter.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/ThreadPoolFilter.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java
    directory/network/branches/chain_refactor/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilter.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilter.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilter.java
Wed Nov 30 20:06:11 2005
@@ -43,20 +43,24 @@
  * <ol>
  *   <li>{@link #init()} is invoked by {@link IoFilterChain} if the filter is
  *       added at the first time.</li>
+ *   <li>{@link #onPreAdd(IoFilterChain, String, NextFilter)} is invoked to notify
+ *       that the filter will be added to the chain.</li>
  *   <li>The filter is added to the chain, and all events and I/O requests
  *       pass through the filter from now.</li>
- *   <li>{@link #onAdd(IoFilterChain, String, NextFilter)} is invoked to notify
+ *   <li>{@link #onPostAdd(IoFilterChain, String, NextFilter)} is invoked to notify
  *       that the filter is added to the chain.</li>
- *   <li>The filter is removed from the chain if {@link #onAdd(IoFilterChain, String,
org.apache.mina.common.IoFilter.NextFilter)}
+ *   <li>The filter is removed from the chain if {@link #onPostAdd(IoFilterChain, String,
org.apache.mina.common.IoFilter.NextFilter)}
  *       threw an exception.  {@link #destroy()} is also invoked if the filter
  *       is the last filter which was added to {@link IoFilterChain}s.</li>
  * </ol>
  * <p>
  * When you remove an {@link IoFilter} from an {@link IoFilterChain}:
  * <ol>
+ *   <li>{@link #onPreRemove(IoFilterChain, String, NextFilter)} is invoked to
+ *       notify that the filter will be removed from the chain.</li>
  *   <li>The filter is removed from the chain, and any events and I/O requests
  *       don't pass through the filter from now.</li>
- *   <li>{@link #onRemove(IoFilterChain, String, NextFilter)} is invoked to
+ *   <li>{@link #onPostRemove(IoFilterChain, String, NextFilter)} is invoked to
  *       notify that the filter is removed from the chain.</li>
  *   <li>{@link #destroy()} is invoked if the removed filter was the last one.</li>
  * </ol>      
@@ -81,7 +85,7 @@
     void destroy() throws Exception;
     
     /**
-     * Invoked when this filter is added to the specified <tt>parent</tt>.
+     * Invoked before this filter is added to the specified <tt>parent</tt>.
      * Please note that this method can be invoked more than once if
      * this filter is added to more than one parents.  This method is not
      * invoked before {@link #init()} is invoked. 
@@ -91,10 +95,36 @@
      * @param nextFilter the {@link NextFilter} for this filter.  You can reuse
      *                   this object until this filter is removed from the chain.
      */
-    void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
+    void onPreAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
     
     /**
-     * Invoked when this filter is removed from the specified <tt>parent</tt>.
+     * Invoked after this filter is added to the specified <tt>parent</tt>.
+     * Please note that this method can be invoked more than once if
+     * this filter is added to more than one parents.  This method is not
+     * invoked before {@link #init()} is invoked. 
+     *
+     * @param parent the parent who called this method
+     * @param name the name assigned to this filter
+     * @param nextFilter the {@link NextFilter} for this filter.  You can reuse
+     *                   this object until this filter is removed from the chain.
+     */
+    void onPostAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
+    
+    /**
+     * Invoked before this filter is removed from the specified <tt>parent</tt>.
+     * Please note that this method can be invoked more than once if
+     * this filter is removed from more than one parents.
+     * This method is always invoked before {@link #destroy()} is invoked.
+     *  
+     * @param parent the parent who called this method
+     * @param name the name assigned to this filter
+     * @param nextFilter the {@link NextFilter} for this filter.  You can reuse
+     *                   this object until this filter is removed from the chain.
+     */
+    void onPreRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
+    
+    /**
+     * Invoked after this filter is removed from the specified <tt>parent</tt>.
      * Please note that this method can be invoked more than once if
      * this filter is removed from more than one parents.
      * This method is always invoked before {@link #destroy()} is invoked.
@@ -104,7 +134,7 @@
      * @param nextFilter the {@link NextFilter} for this filter.  You can reuse
      *                   this object until this filter is removed from the chain.
      */
-    void onRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
+    void onPostRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception;
     
     /**
      * Filters {@link IoHandler#sessionCreated(IoSession)} event.

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterAdapter.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterAdapter.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterAdapter.java
Wed Nov 30 20:06:11 2005
@@ -36,11 +36,19 @@
     {
     }
 
-    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    public void onPreAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
     {
     }
     
-    public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    public void onPostAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    {
+    }
+    
+    public void onPreRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    {
+    }
+    
+    public void onPostRemove( IoFilterChain parent, String name, NextFilter nextFilter )
throws Exception
     {
     }
     

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterChain.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterChain.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterChain.java
Wed Nov 30 20:06:11 2005
@@ -86,7 +86,7 @@
     /**
      * Adds the specified filter with the specified name at the beginning of this chain.
      * @throws IoFilterLifeCycleException
-     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             if {@link IoFilter#onPostAdd(IoFilterChain, String, NextFilter)} or
      *             {@link IoFilter#init()} throws an exception.
      */
     void addFirst( String name, IoFilter filter );
@@ -94,7 +94,7 @@
     /**
      * Adds the specified filter with the specified name at the end of this chain.
      * @throws IoFilterLifeCycleException
-     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             if {@link IoFilter#onPostAdd(IoFilterChain, String, NextFilter)} or
      *             {@link IoFilter#init()} throws an exception.
      */
     void addLast( String name, IoFilter filter );
@@ -103,7 +103,7 @@
      * Adds the specified filter with the specified name just before the filter whose name
is
      * <code>baseName</code> in this chain.
      * @throws IoFilterLifeCycleException
-     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             if {@link IoFilter#onPostAdd(IoFilterChain, String, NextFilter)} or
      *             {@link IoFilter#init()} throws an exception.
      */
     void addBefore( String baseName, String name, IoFilter filter );
@@ -112,7 +112,7 @@
      * Adds the specified filter with the specified name just after the filter whose name
is
      * <code>baseName</code> in this chain.
      * @throws IoFilterLifeCycleException
-     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             if {@link IoFilter#onPostAdd(IoFilterChain, String, NextFilter)} or
      *             {@link IoFilter#init()} throws an exception.
      */
     void addAfter( String baseName, String name, IoFilter filter );
@@ -120,14 +120,14 @@
     /**
      * Removes the filter with the specified name from this chain.
      * @throws IoFilterLifeCycleException
-     *             if {@link IoFilter#onRemove(IoFilterChain, String, NextFilter)} or
+     *             if {@link IoFilter#onPostRemove(IoFilterChain, String, NextFilter)} or
      *             {@link IoFilter#destroy()} throws an exception.
      */
     IoFilter remove( String name );
 
     /**
      * Removes all filters added to this chain.
-     * @throws Exception if {@link IoFilter#onRemove(IoFilterChain, String, NextFilter)}
thrown an exception.
+     * @throws Exception if {@link IoFilter#onPostRemove(IoFilterChain, String, NextFilter)}
thrown an exception.
      */
     void clear() throws Exception;
     

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
Wed Nov 30 20:06:11 2005
@@ -20,7 +20,7 @@
 
 /**
  * A {@link RuntimeException} which is thrown when {@link IoFilter#init()}
- * or {@link IoFilter#onAdd(IoFilterChain, String, org.apache.mina.common.IoFilter.NextFilter)}
+ * or {@link IoFilter#onPostAdd(IoFilterChain, String, org.apache.mina.common.IoFilter.NextFilter)}
  * failed.
  *
  * @author The Apache Directory Project (dev@directory.apache.org)

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Wed Nov 30 20:06:11 2005
@@ -27,6 +27,7 @@
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoFilterLifeCycleException;
 import org.apache.mina.common.IoSession;
@@ -75,24 +76,8 @@
      */
     protected IoFilter createHeadFilter()
     {
-        return new IoFilter()
+        return new IoFilterAdapter()
         {
-            public void init()
-            {
-            }
-            
-            public void destroy()
-            {
-            }
-
-            public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter )
-            {
-            }
-            
-            public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter
)
-            {
-            }
-            
             public void sessionCreated( NextFilter nextFilter, IoSession session )
             {
                 nextFilter.sessionCreated( session );
@@ -160,24 +145,8 @@
      */
     protected IoFilter createTailFilter()
     {
-        return new IoFilter()
+        return new IoFilterAdapter()
         {
-            public void init()
-            {
-            }
-            
-            public void destroy()
-            {
-            }
-
-            public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter )
-            {
-            }
-            
-            public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter
)
-            {
-            }
-           
             public void sessionCreated( NextFilter nextFilter, IoSession session ) throws
Exception
             {
                 session.getHandler().sessionCreated( session );

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
Wed Nov 30 20:06:11 2005
@@ -78,7 +78,7 @@
 
         try
         {
-            filter.onAdd( chain, name, nextFilter );
+            filter.onPostAdd( chain, name, nextFilter );
         }
         catch( Throwable t )
         {
@@ -101,7 +101,7 @@
 
         try
         {
-            filter.onRemove( chain, name, nextFilter);
+            filter.onPostRemove( chain, name, nextFilter);
         }
         catch( Throwable t )
         {

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/LoggingFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/LoggingFilter.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/LoggingFilter.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/LoggingFilter.java
Wed Nov 30 20:06:11 2005
@@ -20,8 +20,7 @@
 
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoFilter;
-import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.SessionLog;
 import org.slf4j.Logger;
@@ -34,7 +33,7 @@
  * 
  * @see SessionLog
  */
-public class LoggingFilter implements IoFilter
+public class LoggingFilter extends IoFilterAdapter
 {
     /**
      * Session attribute key: prefix string
@@ -53,22 +52,6 @@
     {
     }
     
-    public void init()
-    {
-    }
-    
-    public void destroy()
-    {
-    }
-    
-    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
-    {
-    }
-
-    public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
-    {
-    }
-
     public void sessionCreated( NextFilter nextFilter, IoSession session )
     {
         nextFilter.sessionCreated( session );

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/SSLFilter.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/SSLFilter.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/SSLFilter.java
Wed Nov 30 20:06:11 2005
@@ -330,7 +330,7 @@
         this.enabledProtocols = protocols;
     }
     
-    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
SSLException
+    public void onPostAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
SSLException
     {
         if( parent.contains( SSLFilter.class ) )
         {
@@ -345,7 +345,7 @@
         }
     }
     
-    public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter )
+    public void onPostRemove( IoFilterChain parent, String name, NextFilter nextFilter )
     {
     }
 

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/ThreadPoolFilter.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/ThreadPoolFilter.java
Wed Nov 30 20:06:11 2005
@@ -27,8 +27,7 @@
 
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoFilter;
-import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.BlockingQueue;
@@ -48,7 +47,7 @@
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class ThreadPoolFilter implements IoFilter
+public class ThreadPoolFilter extends IoFilterAdapter
 {
     /**
      * Default maximum size of thread pool (2G).
@@ -221,15 +220,6 @@
         this.buffers.clear();
         this.followers.clear();
         this.leader = null;
-    }
-
-
-    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
-    {
-    }
-
-    public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
-    {
     }
 
     private void increasePoolSize( Worker worker )

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Wed Nov 30 20:06:11 2005
@@ -29,7 +29,7 @@
         this.factory = factory;
     }
     
-    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    public void onPostAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
     {
         if( parent.contains( ProtocolCodecFilter.class ) )
         {

Modified: directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java
(original)
+++ directory/network/branches/chain_refactor/src/test/org/apache/mina/common/IoFilterChainTest.java
Wed Nov 30 20:06:11 2005
@@ -368,12 +368,12 @@
 
     private class AddRemoveTestFilter extends IoFilterAdapter
     {
-        public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter )
+        public void onPostAdd( IoFilterChain parent, String name, NextFilter nextFilter )
         {
             result += "ADDED";
         }
         
-        public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter )
+        public void onPostRemove( IoFilterChain parent, String name, NextFilter nextFilter
)
         {
             result += "REMOVED";
         }

Modified: directory/network/branches/chain_refactor/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java?rev=350147&r1=350146&r2=350147&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
(original)
+++ directory/network/branches/chain_refactor/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
Wed Nov 30 20:06:11 2005
@@ -123,8 +123,8 @@
             
             future.join();
             
-            filter.onRemove( FILTER_PARENT, "", null );
-            filter.onAdd( FILTER_PARENT, "", null );
+            filter.onPostRemove( FILTER_PARENT, "", null );
+            filter.onPostAdd( FILTER_PARENT, "", null );
         }
     }
     



Mime
View raw message