directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r350111 - in /directory/network/branches/chain_refactor/src: java/org/apache/mina/common/ java/org/apache/mina/common/support/ java/org/apache/mina/filter/ test/org/apache/mina/common/ test/org/apache/mina/filter/
Date Thu, 01 Dec 2005 02:46:01 GMT
Author: trustin
Date: Wed Nov 30 18:45:48 2005
New Revision: 350111

URL: http://svn.apache.org/viewcvs?rev=350111&view=rev
Log:
Related issue: DIRMINA-40 Filter API needs callback for enabled notification
* Renamed init and destroy to onAdd and onRemove
* Added new init() and destroy() method which is invoked differently.
* Added IoFilterLifeCycleManager and extracted lifecycle control code from AbstractIoFilterChain
* Added IoFilterLifeCycleException; IoFilterChain now doesn't throw an Exception directly.

Added:
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
  (with props)
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
  (with props)
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/support/AbstractIoFilterChain.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/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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -40,32 +40,48 @@
  * @version $Rev$, $Date$
  * 
  * @see IoFilterAdapter
+ * 
+ * TODO The better life cycle management (util class)
  */
 public interface IoFilter
 {
     /**
+     * Invoked when this filter is added to a {@link IoFilterChain}
+     * at the first time, so you can initialize shared resources.
+     */
+    void init() throws Exception;
+
+    /**
+     * Invoked when this filter is not used by any {@link IoFilterChain}
+     * anymore, so you can destroy shared resources.
+     */
+    void destroy() throws Exception;
+    
+    /**
      * Invoked when 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 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 init( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
+    void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
     
     /**
      * Invoked when 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 destroy( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception;
+    void onRemove( 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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -28,11 +28,19 @@
  */
 public class IoFilterAdapter implements IoFilter
 {
-    public void init( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception
+    public void init() throws Exception
     {
     }
     
-    public void destroy( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    public void destroy() throws Exception
+    {
+    }
+
+    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    {
+    }
+    
+    public void onRemove( 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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -67,39 +67,49 @@
 
     /**
      * Adds the specified filter with the specified name at the beginning of this chain.
-     * @throws Exception if {@link IoFilter#init(IoFilterChain, String, NextFilter)} thrown
an exception.
+     * @throws IoFilterLifeCycleException
+     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             {@link IoFilter#init()} throws an exception.
      */
-    void addFirst( String name, IoFilter filter ) throws Exception;
+    void addFirst( String name, IoFilter filter );
 
     /**
      * Adds the specified filter with the specified name at the end of this chain.
-     * @throws Exception if {@link IoFilter#init(IoFilterChain, String, NextFilter)} thrown
an exception.
+     * @throws IoFilterLifeCycleException
+     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             {@link IoFilter#init()} throws an exception.
      */
-    void addLast( String name, IoFilter filter ) throws Exception;
+    void addLast( String name, IoFilter filter );
 
     /**
      * Adds the specified filter with the specified name just before the filter whose name
is
      * <code>baseName</code> in this chain.
-     * @throws Exception if {@link IoFilter#init(IoFilterChain, String, NextFilter)} thrown
an exception.
+     * @throws IoFilterLifeCycleException
+     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             {@link IoFilter#init()} throws an exception.
      */
-    void addBefore( String baseName, String name, IoFilter filter ) throws Exception;
+    void addBefore( String baseName, String name, IoFilter filter );
 
     /**
      * Adds the specified filter with the specified name just after the filter whose name
is
      * <code>baseName</code> in this chain.
-     * @throws Exception if {@link IoFilter#init(IoFilterChain, String, NextFilter)} thrown
an exception.
+     * @throws IoFilterLifeCycleException
+     *             if {@link IoFilter#onAdd(IoFilterChain, String, NextFilter)} or
+     *             {@link IoFilter#init()} throws an exception.
      */
-    void addAfter( String baseName, String name, IoFilter filter ) throws Exception;
+    void addAfter( String baseName, String name, IoFilter filter );
 
     /**
      * Removes the filter with the specified name from this chain.
-     * @throws Exception if {@link IoFilter#destroy(IoFilterChain, String, NextFilter)} thrown
an exception.
+     * @throws IoFilterLifeCycleException
+     *             if {@link IoFilter#onRemove(IoFilterChain, String, NextFilter)} or
+     *             {@link IoFilter#destroy()} throws an exception.
      */
-    IoFilter remove( String name ) throws Exception;
+    IoFilter remove( String name );
 
     /**
      * Removes all filters added to this chain.
-     * @throws Exception if {@link IoFilter#destroy(IoFilterChain, String, NextFilter)} thrown
an exception.
+     * @throws Exception if {@link IoFilter#onRemove(IoFilterChain, String, NextFilter)}
thrown an exception.
      */
     void clear() throws Exception;
     

Added: 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=350111&view=auto
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
(added)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
Wed Nov 30 18:45:48 2005
@@ -0,0 +1,51 @@
+/*
+ *   @(#) $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;
+
+/**
+ * A {@link RuntimeException} which is thrown when {@link IoFilter#init()}
+ * or {@link IoFilter#onAdd(IoFilterChain, String, org.apache.mina.common.IoFilter.NextFilter)}
+ * failed.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoFilterLifeCycleException extends RuntimeException
+{
+    private static final long serialVersionUID = -5542098881633506449L;
+
+    public IoFilterLifeCycleException()
+    {
+    }
+
+    public IoFilterLifeCycleException( String message )
+    {
+        super( message );
+    }
+
+    public IoFilterLifeCycleException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public IoFilterLifeCycleException( Throwable cause )
+    {
+        super( cause );
+    }
+}

Propchange: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoFilterLifeCycleException.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -29,6 +29,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoFilter;
 import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFilterLifeCycleException;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoFilter.NextFilter;
 import org.apache.mina.common.IoFilter.WriteRequest;
@@ -78,11 +79,19 @@
     {
         return new IoFilter()
         {
-            public void init( IoFilterChain parent, String name, NextFilter nextFilter )
+            public void init()
             {
             }
             
-            public void destroy( IoFilterChain parent, String name, NextFilter nextFilter
)
+            public void destroy()
+            {
+            }
+
+            public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter )
+            {
+            }
+            
+            public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter
)
             {
             }
             
@@ -155,11 +164,19 @@
     {
         return new IoFilter()
         {
-            public void init( IoFilterChain parent, String name, NextFilter nextFilter )
+            public void init()
+            {
+            }
+            
+            public void destroy()
+            {
+            }
+
+            public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter )
             {
             }
             
-            public void destroy( IoFilterChain parent, String name, NextFilter nextFilter
)
+            public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter
)
             {
             }
            
@@ -274,14 +291,14 @@
     }
     
     public synchronized void addFirst( String name,
-                                       IoFilter filter ) throws Exception
+                                       IoFilter filter )
     {
         checkAddable( name );
         register( head, name, filter );
     }
 
     public synchronized void addLast( String name,
-                                      IoFilter filter ) throws Exception
+                                      IoFilter filter )
     {
         checkAddable( name );
         register( tail.prevEntry, name, filter );
@@ -289,7 +306,7 @@
 
     public synchronized void addBefore( String baseName,
                                         String name,
-                                        IoFilter filter ) throws Exception
+                                        IoFilter filter )
     {
         EntryImpl baseEntry = checkOldName( baseName );
         checkAddable( name );
@@ -298,14 +315,14 @@
 
     public synchronized void addAfter( String baseName,
                                        String name,
-                                       IoFilter filter ) throws Exception
+                                       IoFilter filter )
     {
         EntryImpl baseEntry = checkOldName( baseName );
         checkAddable( name );
         register( baseEntry, name, filter );
     }
 
-    public synchronized IoFilter remove( String name ) throws Exception
+    public synchronized IoFilter remove( String name )
     {
         EntryImpl entry = checkOldName( name );
         deregister( entry );
@@ -321,19 +338,55 @@
         }
     }
 
-    private void register( EntryImpl prevEntry, String name, IoFilter filter ) throws Exception
+    private void register( EntryImpl prevEntry, String name, IoFilter filter )
     {
         EntryImpl newEntry = new EntryImpl( prevEntry, prevEntry.nextEntry, name, filter
);
 
-        filter.init( this, name, newEntry.getNextFilter() );
+        IoFilterLifeCycleManager lifeCycleManager = IoFilterLifeCycleManager.getInstance();
         
-        prevEntry.nextEntry.prevEntry = newEntry;
-        prevEntry.nextEntry = newEntry;
-        name2entry.put( name, newEntry );
-        filter2entry.put( filter, newEntry );
+        synchronized( lifeCycleManager )
+        {
+            lifeCycleManager.initIfNeeded( filter );
+
+            prevEntry.nextEntry.prevEntry = newEntry;
+            prevEntry.nextEntry = newEntry;
+            name2entry.put( name, newEntry );
+            filter2entry.put( filter, newEntry );
+
+            try
+            {
+                lifeCycleManager.add( this, name, filter, newEntry.getNextFilter() );
+            }
+            catch( IoFilterLifeCycleException e )
+            {
+                deregister0( newEntry );
+                throw e;
+            }
+            finally
+            {
+                lifeCycleManager.destroyIfNeeded( filter );
+            }
+        }
     }
     
-    private void deregister( EntryImpl entry ) throws Exception
+    private void deregister( EntryImpl entry )
+    {
+        deregister0( entry );
+
+        IoFilter filter = entry.getFilter();
+        IoFilterLifeCycleManager lifeCycleManager = IoFilterLifeCycleManager.getInstance();
+        try
+        {
+            lifeCycleManager.remove(
+                    this, entry.getName(), filter, entry.getNextFilter() );
+        }
+        finally
+        {
+            lifeCycleManager.destroyIfNeeded( filter );
+        }
+    }
+
+    private void deregister0( EntryImpl entry )
     {
         EntryImpl prevEntry = entry.prevEntry;
         EntryImpl nextEntry = entry.nextEntry;
@@ -343,8 +396,6 @@
         name2entry.remove( entry.name );
         IoFilter filter = entry.getFilter();
         filter2entry.remove( filter );
-        
-        filter.destroy( this, entry.getName(), entry.getNextFilter() );
     }
 
     /**

Added: 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=350111&view=auto
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
(added)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
Wed Nov 30 18:45:48 2005
@@ -0,0 +1,153 @@
+/*
+ *   @(#) $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.support;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFilterLifeCycleException;
+import org.apache.mina.common.IoFilter.NextFilter;
+
+public class IoFilterLifeCycleManager
+{
+    private static final IoFilterLifeCycleManager INSTANCE = new IoFilterLifeCycleManager();
+    
+    public static IoFilterLifeCycleManager getInstance()
+    {
+        return INSTANCE;
+    }
+    
+    private Map counts = new IdentityHashMap();
+    
+    private IoFilterLifeCycleManager()
+    {
+    }
+    
+    public synchronized void initIfNeeded( IoFilter filter )
+    {
+        ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+        if( count == null )
+        {
+            count = new ReferenceCount();
+            counts.put( filter, count );
+            try
+            {
+                filter.init();
+            }
+            catch( Throwable t )
+            {
+                throw new IoFilterLifeCycleException(
+                        "Failed to initilize: " + filter, t );
+            }
+        }
+    }
+    
+    public synchronized void add( IoFilterChain chain, String name, IoFilter filter, NextFilter
nextFilter )
+    {
+        ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+        if( count == null )
+        {
+            throw new IllegalStateException();
+        }
+        
+        count.increase();
+
+        try
+        {
+            filter.onAdd( chain, name, nextFilter );
+        }
+        catch( Throwable t )
+        {
+            // Revert back the reference count.
+            count.decrease();
+
+            throw new IoFilterLifeCycleException(
+                    "Failed to add: " + name + ':' + filter + " in " +
+                    chain.getSession(), t );
+        }
+    }
+
+    public synchronized void remove( IoFilterChain chain, String name, IoFilter filter, NextFilter
nextFilter )
+    {
+        ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+        if( count == null || count.get() == 0 )
+        {
+            return;
+        }
+
+        try
+        {
+            filter.onRemove( chain, name, nextFilter);
+        }
+        catch( Throwable t )
+        {
+            throw new IoFilterLifeCycleException(
+                    "Failed to remove: " + name + ':' + filter + " in " +
+                    chain.getSession(), t );
+        }
+        finally
+        {
+            count.decrease();
+        }
+    }
+
+    public synchronized void destroyIfNeeded( IoFilter filter )
+    {
+        ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+        if( count == null )
+        {
+            return;
+        }
+        
+        if( count.get() == 0 )
+        {
+            counts.remove( filter );
+            try
+            {
+                filter.destroy();
+            }
+            catch( Throwable t2 )
+            {
+                throw new IoFilterLifeCycleException( "Failed to destroy: " + filter, t2
);
+            }
+        }
+    }
+    
+    private static class ReferenceCount
+    {
+        private int count;
+        
+        public int get()
+        {
+            return count;
+        }
+        
+        public int increase()
+        {
+            return count ++;
+        }
+        
+        public int decrease()
+        {
+            return -- count;
+        }
+    }
+}

Propchange: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -53,6 +53,22 @@
     {
     }
     
+    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 );
@@ -104,13 +120,5 @@
     {
         SessionLog.info( session, "CLOSE" );
         nextFilter.filterClose( session, closeFuture );
-    }
-
-    public void init( IoFilterChain parent, String name, NextFilter nextFilter ) throws Exception
-    {
-    }
-
-    public void destroy( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
-    {
     }
 }

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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -330,8 +330,9 @@
         this.enabledProtocols = protocols;
     }
     
-    public void init( IoFilterChain parent, String name, NextFilter nextFilter ) throws SSLException
+    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
SSLException
     {
+        // FIXME This filter should work fine even if it is added more than once to one chain.
         parent.getSession().setAttribute( NEXT_FILTER, nextFilter );
         Object managerOrSession = parent.getSession();
         if( managerOrSession instanceof IoSession )
@@ -340,9 +341,8 @@
         }
     }
     
-    public void destroy( IoFilterChain parent, String name, NextFilter nextFilter )
+    public void onRemove( IoFilterChain parent, String name, NextFilter nextFilter )
     {
-        
     }
 
     // IoFilter impl.

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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -93,7 +93,6 @@
     }
 
     private final String threadNamePrefix;
-    private final Map parents = new IdentityHashMap(); 
     private final Map buffers = new IdentityHashMap();
     private final BlockingQueue unfetchedSessionBuffers = new BlockingQueue();
     private final Set allSessionBuffers = new IdentityHashSet();
@@ -172,6 +171,67 @@
         this.keepAliveTime = keepAliveTime;
     }
 
+    public void init()
+    {
+        shuttingDown = false;
+        leader = new Worker();
+        leader.start();
+        leader.lead();
+    }
+
+    public void destroy()
+    {
+        shuttingDown = true;
+        int expectedPoolSize = 0;
+        while( getPoolSize() != expectedPoolSize )
+        {
+            List allWorkers;
+            synchronized( poolSizeLock )
+            {
+                allWorkers = new ArrayList( this.allWorkers );
+            }
+            
+            // You may not interrupt the current thread.
+            if( allWorkers.remove( Thread.currentThread() ) )
+            {
+                expectedPoolSize = 1;
+            }
+            
+            for( Iterator i = allWorkers.iterator(); i.hasNext(); )
+            {
+                Worker worker = ( Worker ) i.next();
+                while( worker.isAlive() )
+                {
+                    worker.interrupt();
+                    try
+                    {
+                        // This timeout will help us from 
+                        // infinite lock-up and interrupt workers again.
+                        worker.join( 100 );
+                    }
+                    catch( InterruptedException e )
+                    {
+                    }
+                }
+            }
+        }
+        
+        this.allSessionBuffers.clear();
+        this.unfetchedSessionBuffers.clear();
+        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 )
     {
         synchronized( poolSizeLock )
@@ -646,70 +706,5 @@
     public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture
) throws Exception
     {
         nextFilter.filterClose( session, closeFuture );
-    }
-
-    public synchronized void init( IoFilterChain parent, String name, NextFilter nextFilter
)
-    {
-        if( parents.size() > 0 )
-        {
-            return;
-        }
-
-        parents.put( parent, Boolean.TRUE );
-
-        shuttingDown = false;
-        leader = new Worker();
-        leader.start();
-        leader.lead();
-    }
-
-    public synchronized void destroy( IoFilterChain parent, String name, NextFilter nextFilter
)
-    {
-        parents.remove( parent );
-        if( parents.size() > 0 )
-        {
-            return;
-        }
-
-        shuttingDown = true;
-        int expectedPoolSize = 0;
-        while( getPoolSize() != expectedPoolSize )
-        {
-            List allWorkers;
-            synchronized( poolSizeLock )
-            {
-                allWorkers = new ArrayList( this.allWorkers );
-            }
-            
-            // You may not interrupt the current thread.
-            if( allWorkers.remove( Thread.currentThread() ) )
-            {
-                expectedPoolSize = 1;
-            }
-            
-            for( Iterator i = allWorkers.iterator(); i.hasNext(); )
-            {
-                Worker worker = ( Worker ) i.next();
-                while( worker.isAlive() )
-                {
-                    worker.interrupt();
-                    try
-                    {
-                        // This timeout will help us from 
-                        // infinite lock-up and interrupt workers again.
-                        worker.join( 100 );
-                    }
-                    catch( InterruptedException e )
-                    {
-                    }
-                }
-            }
-        }
-        
-        this.allSessionBuffers.clear();
-        this.unfetchedSessionBuffers.clear();
-        this.buffers.clear();
-        this.followers.clear();
-        this.leader = null;
     }
 }

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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -309,7 +309,7 @@
         }
     }
 
-    private class EventOrderTestFilter implements IoFilter
+    private class EventOrderTestFilter extends IoFilterAdapter
     {
         private final char id;
 
@@ -364,24 +364,16 @@
         {
             nextFilter.filterClose( session, closeFuture );
         }
-
-        public void init( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
-        {
-        }
-
-        public void destroy( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
-        {
-        }
     }
 
     private class AddRemoveTestFilter extends IoFilterAdapter
     {
-        public void init( IoFilterChain parent, String name, NextFilter nextFilter )
+        public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter )
         {
             result += "ADDED";
         }
         
-        public void destroy( IoFilterChain parent, String name, NextFilter nextFilter )
+        public void onRemove( 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=350111&r1=350110&r2=350111&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 18:45:48 2005
@@ -36,15 +36,15 @@
     {
     }
     
-    public void setUp()
+    public void setUp() throws Exception
     {
         filter = new ThreadPoolFilter();
-        filter.init( FILTER_PARENT, "", null );
+        filter.onAdd( FILTER_PARENT, "", null );
     }
     
-    public void tearDown()
+    public void tearDown() throws Exception
     {
-        filter.destroy( FILTER_PARENT, "", null );
+        filter.onRemove( FILTER_PARENT, "", null );
         Assert.assertEquals( 0, filter.getPoolSize() );
         filter = null;
     }
@@ -123,8 +123,8 @@
             
             future.join();
             
-            filter.destroy( FILTER_PARENT, "", null );
-            filter.init( FILTER_PARENT, "", null );
+            filter.onRemove( FILTER_PARENT, "", null );
+            filter.onAdd( FILTER_PARENT, "", null );
         }
     }
     



Mime
View raw message