directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r350130 - in /directory/network/branches/chain_refactor/src/java/org/apache/mina: common/ common/support/ filter/ filter/codec/
Date Thu, 01 Dec 2005 03:36:28 GMT
Author: trustin
Date: Wed Nov 30 19:36:21 2005
New Revision: 350130

URL: http://svn.apache.org/viewcvs?rev=350130&view=rev
Log:
* Added IoFilterChain.contains()
* Added DefaultIoFilterChainBuilder.contains()
* Prevented ProtocolCodecFilter and SSLFilter from duplicate addition

Modified:
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.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/SSLFilter.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java?rev=350130&r1=350129&r2=350130&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
Wed Nov 30 19:36:21 2005
@@ -106,6 +106,50 @@
     }
 
     /**
+     * Returns <tt>true</tt> if this chain contains an {@link IoFilter} with
the
+     * specified <tt>name</tt>.
+     */
+    public boolean contains( String name )
+    {
+        return getEntry( name ) != null;
+    }
+    
+    /**
+     * Returns <tt>true</tt> if this chain contains the specified <tt>filter</tt>.
+     */
+    public boolean contains( IoFilter filter )
+    {
+        for( Iterator i = entries.iterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            if( e.getFilter() == filter )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    /**
+     * Returns <tt>true</tt> if this chain contains an {@link IoFilter} of the
+     * specified <tt>filterType</tt>.
+     */
+    public boolean contains( Class filterType )
+    {
+        for( Iterator i = entries.iterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            if( filterType.isAssignableFrom( e.getFilter().getClass() ) )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    /**
      * Adds the specified filter with the specified name at the beginning
      * of the filter list.
      */

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=350130&r1=350129&r2=350130&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 19:36:21 2005
@@ -65,7 +65,24 @@
      * Returns the reversed list of all {@link Entry}s this chain contains.
      */
     List getAllReversed();
-
+    
+    /**
+     * Returns <tt>true</tt> if this chain contains an {@link IoFilter} with
the
+     * specified <tt>name</tt>.
+     */
+    boolean contains( String name );
+    
+    /**
+     * Returns <tt>true</tt> if this chain contains the specified <tt>filter</tt>.
+     */
+    boolean contains( IoFilter filter );
+    
+    /**
+     * Returns <tt>true</tt> if this chain contains an {@link IoFilter} of the
+     * specified <tt>filterType</tt>.
+     */
+    boolean contains( Class filterType );
+    
     /**
      * Adds the specified filter with the specified name at the beginning of this chain.
      * @throws IoFilterLifeCycleException

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=350130&r1=350129&r2=350130&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 19:36:21 2005
@@ -20,7 +20,6 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -54,7 +53,6 @@
     private final IoSession session;
 
     private final Map name2entry = new HashMap();
-    private final Map filter2entry = new IdentityHashMap();
     
     private final EntryImpl head;
     private final EntryImpl tail;
@@ -351,7 +349,6 @@
             prevEntry.nextEntry.prevEntry = newEntry;
             prevEntry.nextEntry = newEntry;
             name2entry.put( name, newEntry );
-            filter2entry.put( filter, newEntry );
 
             try
             {
@@ -394,8 +391,6 @@
         nextEntry.prevEntry = prevEntry;
 
         name2entry.remove( entry.name );
-        IoFilter filter = entry.getFilter();
-        filter2entry.remove( filter );
     }
 
     /**
@@ -630,6 +625,39 @@
         return list;
     }
     
+    public boolean contains( String name )
+    {
+        return getEntry( name ) != null;
+    }
+
+    public boolean contains( IoFilter filter )
+    {
+        EntryImpl e = head.nextEntry;
+        while( e != tail )
+        {
+            if( e.getFilter() == filter )
+            {
+                return true;
+            }
+            e = e.nextEntry;
+        }
+        return false;
+    }
+
+    public boolean contains( Class filterType )
+    {
+        EntryImpl e = head.nextEntry;
+        while( e != tail )
+        {
+            if( filterType.isAssignableFrom( e.getFilter().getClass() ) )
+            {
+                return true;
+            }
+            e = e.nextEntry;
+        }
+        return false;
+    }
+
     public String toString()
     {
         StringBuffer buf = new StringBuffer();

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=350130&r1=350129&r2=350130&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 19:36:21 2005
@@ -332,6 +332,11 @@
     
     public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
SSLException
     {
+        if( parent.contains( SSLFilter.class ) )
+        {
+            throw new IllegalStateException( "A filter chain cannot contain more than one
SSLFilter." );
+        }
+
         // 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();

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=350130&r1=350129&r2=350130&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 19:36:21 2005
@@ -3,6 +3,7 @@
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.ByteBufferProxy;
 import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
 import org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput;
@@ -28,6 +29,14 @@
         this.factory = factory;
     }
     
+    public void onAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
+    {
+        if( parent.contains( ProtocolCodecFilter.class ) )
+        {
+            throw new IllegalStateException( "A filter chain cannot contain more than one
ProtocolCodecFilter." );
+        }
+    }
+
     public void messageReceived( NextFilter nextFilter, IoSession session, Object message
) throws Exception
     {
         if( !( message instanceof ByteBuffer ) )



Mime
View raw message