directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r158802 [1/2] - in directory/network/trunk/src: examples/org/apache/mina/examples/echoserver/ examples/org/apache/mina/examples/netcat/ examples/org/apache/mina/examples/reverser/ examples/org/apache/mina/examples/sumup/ examples/org/apache/mina/examples/tennis/ java/org/apache/mina/common/ java/org/apache/mina/io/ java/org/apache/mina/io/datagram/ java/org/apache/mina/io/filter/ java/org/apache/mina/io/socket/ java/org/apache/mina/protocol/ java/org/apache/mina/protocol/filter/ java/org/apache/mina/protocol/io/ java/org/apache/mina/protocol/vmpipe/ java/org/apache/mina/registry/ java/org/apache/mina/util/ test/org/apache/mina/examples/echoserver/ test/org/apache/mina/util/
Date Wed, 23 Mar 2005 17:21:47 GMT
Author: trustin
Date: Wed Mar 23 09:21:35 2005
New Revision: 158802

URL: http://svn.apache.org/viewcvs?view=rev&rev=158802
Log:
=== Revamped filter chain interface ===
Please note that this change will break your MINA application!
JavaDocs are not available for new classes yet.
I'll fill them in soon.

* Removed all filter chain manipulation methods from acceptors and connectors.
* Added newFilterChain(...) and getFilterChain() method to all acceptors and connectors.
* Added IoHandlerFilterChain and ProtocolHandlerFilterChain
* Updated ServiceRegistry and SimpleServiceRegistry following all of the above changes
* IoHandlerFilterManager and ProtocolHandlerFilterManager has been removed.

Added:
    directory/network/trunk/src/java/org/apache/mina/common/FilterChainType.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterChain.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramFilterChain.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketFilterChain.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilterChain.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilterChain.java   (with props)
Removed:
    directory/network/trunk/src/java/org/apache/mina/util/IoHandlerFilterManager.java
    directory/network/trunk/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java
    directory/network/trunk/src/test/org/apache/mina/util/IoHandlerFilterManagerTest.java
    directory/network/trunk/src/test/org/apache/mina/util/ProtocolHandlerFilterManagerTest.java
Modified:
    directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java
    directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java
    directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java
    directory/network/trunk/src/examples/org/apache/mina/examples/tennis/Main.java
    directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java
    directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilter.java
    directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterAdapter.java
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java
    directory/network/trunk/src/java/org/apache/mina/io/filter/BlacklistFilter.java
    directory/network/trunk/src/java/org/apache/mina/io/filter/IoThreadPoolFilter.java
    directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnector.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
    directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConnector.java
    directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolThreadPoolFilter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
    directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java
    directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java Wed Mar 23 09:21:35 2005
@@ -52,7 +52,7 @@
 
         // Add thread pool filter
         // MINA runs in a single thread if you don't add this filter.
-        acceptor.addFilter( Integer.MAX_VALUE, threadPoolFilter );
+        acceptor.getFilterChain().addFirst( "threadPool", threadPoolFilter );
 
         // Add SSL filter if SSL is enabled.
         if( USE_SSL )
@@ -60,7 +60,7 @@
             System.out.println( "SSL is enabled." );
             SSLFilter sslFilter = new SSLFilter( BogusSSLContextFactory
                     .getInstance( true ) );
-            acceptor.addFilter( Integer.MAX_VALUE - 1, sslFilter );
+            acceptor.getFilterChain().addLast( "sslFilter", sslFilter );
         }
 
         // Bind
@@ -71,7 +71,7 @@
         IoAcceptor datagramAcceptor = new DatagramAcceptor();
 
         // Add thread pool filter
-        datagramAcceptor.addFilter( Integer.MAX_VALUE, threadPoolFilter );
+        datagramAcceptor.getFilterChain().addFirst( "threadPool", threadPoolFilter );
 
         // Bind
         datagramAcceptor.bind( new InetSocketAddress( PORT ),

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java Wed Mar 23 09:21:35 2005
@@ -46,7 +46,8 @@
 
         // Add I/O thread pool filter.
         // MINA runs in a single thread if you don't add this filter.
-        connector.addFilter( Integer.MAX_VALUE, new IoThreadPoolFilter() );
+        connector.getFilterChain().addFirst(
+                "threadPool", new IoThreadPoolFilter() );
 
         // Start communication.
         connector.connect( new InetSocketAddress( args[ 0 ], Integer

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java Wed Mar 23 09:21:35 2005
@@ -53,8 +53,10 @@
                 new SocketAcceptor() );
 
         // Add both thread pool filters.
-        acceptor.getIoAcceptor().addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        acceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+        acceptor.getIoAcceptor().getFilterChain().addFirst(
+                "threadPool", ioThreadPoolFilter );
+        acceptor.getFilterChain().addFirst(
+                "threadPool", protocolThreadPoolFilter );
 
         // Bind
         acceptor.bind( new InetSocketAddress( PORT ),

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java Wed Mar 23 09:21:35 2005
@@ -54,8 +54,10 @@
 
         IoProtocolConnector connector = new IoProtocolConnector(
                 new SocketConnector() );
-        connector.getIoConnector().addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        connector.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+        connector.getIoConnector().getFilterChain().addFirst(
+                "threadPool", ioThreadPoolFilter );
+        connector.getFilterChain().addFirst(
+                "threadPool", protocolThreadPoolFilter );
 
         ProtocolProvider protocolProvider = new ClientProtocolProvider(
                 values );

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java Wed Mar 23 09:21:35 2005
@@ -35,8 +35,10 @@
         IoProtocolAcceptor acceptor = new IoProtocolAcceptor(
                 new SocketAcceptor() );
 
-        acceptor.getIoAcceptor().addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        acceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+        acceptor.getIoAcceptor().getFilterChain().addFirst(
+                "threadPool", ioThreadPoolFilter );
+        acceptor.getFilterChain().addFirst(
+                "threadPool", protocolThreadPoolFilter );
 
         acceptor.bind( new InetSocketAddress( SERVER_PORT ),
                 new ServerProtocolProvider() );

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/tennis/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/tennis/Main.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/tennis/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/tennis/Main.java Wed Mar 23 09:21:35 2005
@@ -37,10 +37,11 @@
         // Set up server
         VmPipeAcceptor acceptor = new VmPipeAcceptor();
         acceptor.bind( address, new TennisPlayer() );
-        acceptor.addFilter( 0, threadPool );
+        acceptor.getFilterChain().addFirst( "threadPool", threadPool );
 
         // Connect to the server.
         VmPipeConnector connector = new VmPipeConnector();
+        connector.getFilterChain().addFirst( "threadPool", threadPool );
         ProtocolSession session = connector.connect( address,
                                                      new TennisPlayer() );
 
@@ -56,4 +57,4 @@
         // Stop the thread pool
         threadPool.stop();
     }
-}
\ No newline at end of file
+}

Added: directory/network/trunk/src/java/org/apache/mina/common/FilterChainType.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/FilterChainType.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/FilterChainType.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/common/FilterChainType.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,23 @@
+package org.apache.mina.common;
+
+/**
+ * TODO document me
+ */
+public class FilterChainType {
+    
+    /**
+     * 'Preprocess chain' passes events to the next filter
+     * of the parent chain after processing its children.
+     */
+    public static final FilterChainType PREPROCESS = new FilterChainType();
+
+    /**
+     * 'Postprocess chain' passes events to the next filter
+     * of the parent chain before processing its children.
+     */
+    public static final FilterChainType POSTPROCESS = new FilterChainType();
+
+    private FilterChainType()
+    {
+    }
+}

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

Added: directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,703 @@
+package org.apache.mina.io;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.FilterChainType;
+import org.apache.mina.common.IdleStatus;
+
+public abstract class AbstractIoHandlerFilterChain implements IoHandlerFilterChain
+{
+    private final IoHandlerFilter HEAD_FILTER = new IoHandlerFilter()
+    {
+        public void sessionOpened( NextFilter nextFilter, IoSession session )
+        {
+            nextFilter.sessionOpened( session );
+        }
+
+        public void sessionClosed( NextFilter nextFilter, IoSession session )
+        {
+            nextFilter.sessionClosed( session );
+        }
+
+        public void sessionIdle( NextFilter nextFilter, IoSession session,
+                                IdleStatus status )
+        {
+            nextFilter.sessionIdle( session, status );
+        }
+
+        public void exceptionCaught( NextFilter nextFilter,
+                                    IoSession session, Throwable cause )
+        {
+            nextFilter.exceptionCaught( session, cause );
+        }
+
+        public void dataRead( NextFilter nextFilter, IoSession session,
+                             ByteBuffer buf )
+        {
+            nextFilter.dataRead( session, buf );
+        }
+
+        public void dataWritten( NextFilter nextFilter, IoSession session,
+                                Object marker )
+        {
+            nextFilter.dataWritten( session, marker );
+        }
+        
+        public void filterWrite( NextFilter nextFilter, IoSession session,
+                                 ByteBuffer buf, Object marker )
+        {
+            if( AbstractIoHandlerFilterChain.this.parent == null )
+            {
+                // write only when root filter chain traversal is finished.
+                doWrite( session, buf, marker );
+            }
+        }
+    };
+    
+    private static final IoHandlerFilter TAIL_FILTER = new IoHandlerFilter()
+    {
+        public void sessionOpened( NextFilter nextFilter, IoSession session )
+        {
+            session.getHandler().sessionOpened( session );
+        }
+
+        public void sessionClosed( NextFilter nextFilter, IoSession session )
+        {
+            session.getHandler().sessionClosed( session );
+        }
+
+        public void sessionIdle( NextFilter nextFilter, IoSession session,
+                                IdleStatus status )
+        {
+            session.getHandler().sessionIdle( session, status );
+        }
+
+        public void exceptionCaught( NextFilter nextFilter,
+                                    IoSession session, Throwable cause )
+        {
+            session.getHandler().exceptionCaught( session, cause );
+        }
+
+        public void dataRead( NextFilter nextFilter, IoSession session,
+                             ByteBuffer buf )
+        {
+            IoHandler handler = session.getHandler();
+            handler.dataRead( session, buf );
+            buf.release();
+        }
+
+        public void dataWritten( NextFilter nextFilter, IoSession session,
+                                Object marker )
+        {
+            session.getHandler().dataWritten( session, marker );
+        }
+
+        public void filterWrite( NextFilter nextFilter,
+                                 IoSession session, ByteBuffer buf, Object marker )
+        {
+            nextFilter.filterWrite( session, buf, marker );
+        }
+    };
+
+    private AbstractIoHandlerFilterChain parent;
+    
+    private final FilterChainType type; 
+    
+    private final Map name2entry = new HashMap();
+
+    private final Map filter2entry = new IdentityHashMap();
+
+    private final Entry head;
+
+    private final Entry tail;
+
+    protected AbstractIoHandlerFilterChain( FilterChainType type )
+    {
+        if( type == null )
+        {
+            throw new NullPointerException( "type" );
+        }
+        
+        this.type = type;
+        
+        head = new Entry( null, null, "head", HEAD_FILTER );
+        tail = new Entry( head, null, "tail", TAIL_FILTER );
+        head.nextEntry = tail;
+    }
+    
+    public IoHandlerFilterChain getRoot()
+    {
+        AbstractIoHandlerFilterChain current = this;
+        while( current.parent != null )
+        {
+            current = current.parent;
+        }
+        return current;
+    }
+    
+    public IoHandlerFilterChain getParent()
+    {
+        return parent;
+    }
+    
+    public FilterChainType getType()
+    {
+        return type;
+    }
+    
+    public IoHandlerFilter getChild( String name )
+    {
+        Entry e = ( Entry ) name2entry.get( name );
+        if ( e == null )
+        {
+            return null;
+        }
+        return e.filter;
+    }
+    
+    /**
+     * Adds the specified interceptor with the specified name at the beginning of this chain.
+     */
+    public synchronized void addFirst( String name,
+                                       IoHandlerFilter filter )
+    {
+        checkAddable( name, filter );
+        register( head, name, filter );
+    }
+
+
+    /**
+     * Adds the specified interceptor with the specified name at the end of this chain.
+     */
+    public synchronized void addLast( String name,
+                                      IoHandlerFilter filter )
+    {
+        checkAddable( name, filter );
+        register( tail.prevEntry, name, filter );
+    }
+
+
+    /**
+     * Adds the specified interceptor with the specified name just before the interceptor whose name is
+     * <code>baseName</code> in this chain.
+     */
+    public synchronized void addBefore( String baseName,
+                                        String name,
+                                        IoHandlerFilter filter )
+    {
+        Entry baseEntry = checkOldName( baseName );
+        checkAddable( name, filter );
+        register( baseEntry, name, filter );
+    }
+
+
+    /**
+     * Adds the specified interceptor with the specified name just after the interceptor whose name is
+     * <code>baseName</code> in this chain.
+     */
+    public synchronized void addAfter( String baseName,
+                                       String name,
+                                       IoHandlerFilter filter )
+    {
+        Entry baseEntry = checkOldName( baseName );
+        checkAddable( name, filter );
+        register( baseEntry.prevEntry, name, filter );
+    }
+
+
+    /**
+     * Removes the interceptor with the specified name from this chain.
+     */
+    public synchronized void remove( String name )
+    {
+        Entry entry = checkOldName( name );
+        Entry prevEntry = entry.prevEntry;
+        Entry nextEntry = entry.nextEntry;
+        prevEntry.nextEntry = nextEntry;
+        nextEntry.prevEntry = prevEntry;
+
+        name2entry.remove( name );
+        IoHandlerFilter filter = entry.filter;
+        filter2entry.remove( filter );
+        if ( filter instanceof AbstractIoHandlerFilterChain )
+        {
+            ( ( AbstractIoHandlerFilterChain ) filter ).parent = null;
+        }
+    }
+
+
+    /**
+     * Removes all interceptors added to this chain.
+     */
+    public synchronized void clear()
+    {
+        Iterator it = new ArrayList( name2entry.keySet() ).iterator();
+        while ( it.hasNext() )
+        {
+            this.remove( ( String ) it.next() );
+        }
+    }
+
+    private void register( Entry prevEntry, String name, IoHandlerFilter filter )
+    {
+        Entry newEntry = new Entry( prevEntry, prevEntry.nextEntry, name, filter );
+        prevEntry.nextEntry.prevEntry = newEntry;
+        prevEntry.nextEntry = newEntry;
+        name2entry.put( name, newEntry );
+        filter2entry.put( filter, newEntry );
+        if ( filter instanceof AbstractIoHandlerFilterChain )
+        {
+            ( ( AbstractIoHandlerFilterChain ) filter ).parent = this;
+        }
+    }
+
+    /**
+     * Throws an exception when the specified interceptor name is not registered in this chain.
+     *
+     * @return An interceptor entry with the specified name.
+     */
+    private Entry checkOldName( String baseName )
+    {
+        Entry e = ( Entry ) name2entry.get( baseName );
+        if ( e == null )
+        {
+            throw new IllegalArgumentException( "Unknown interceptor name:" +
+                    baseName );
+        }
+        return e;
+    }
+
+
+    /**
+     * Checks the specified interceptor name is already taken and throws an exception if already taken.
+     */
+    private void checkAddable( String name, IoHandlerFilter filter )
+    {
+        if ( name2entry.containsKey( name ) )
+        {
+            throw new IllegalArgumentException( "Other interceptor is using name '" + name + "'" );
+        }
+
+        if ( filter instanceof AbstractIoHandlerFilterChain )
+        {
+            if ( ( ( AbstractIoHandlerFilterChain ) filter ).parent != null )
+            {
+                throw new IllegalArgumentException( "This interceptor chain has its parent already." );
+            }
+        }
+    }
+
+    public void sessionOpened( NextFilter nextFilter, IoSession session )
+    {
+        Entry head = this.head;
+        callNextSessionOpened(head, nextFilter, session);
+    }
+
+    private void callNextSessionOpened( Entry entry,
+                                        NextFilter nextFilter, IoSession session)
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.sessionOpened( entry.nextFilter, session );
+            }
+            else if ( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.sessionOpened( entry.nextFilter, session );
+                nextFilter.sessionOpened( session );
+            }
+            else // POSTPROCESS
+            {
+                nextFilter.sessionOpened( session );
+                entry.filter.sessionOpened( entry.nextFilter, session );
+            }
+                
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public void sessionClosed( NextFilter nextFilter, IoSession session )
+    {
+        Entry head = this.head;
+        callNextSessionClosed(head, nextFilter, session);
+    }
+
+    private void callNextSessionClosed( Entry entry,
+                                        NextFilter nextFilter, IoSession session )
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.sessionClosed( entry.nextFilter, session );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.sessionClosed( entry.nextFilter, session );
+                nextFilter.sessionClosed( session );
+            }
+            else // POSTPROCESS
+            {
+                nextFilter.sessionClosed( session );
+                entry.filter.sessionClosed( entry.nextFilter, session );
+            }
+                
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public void sessionIdle( NextFilter nextFilter, IoSession session, IdleStatus status )
+    {
+        Entry head = this.head;
+        callNextSessionIdle(head, nextFilter, session, status);
+    }
+
+    private void callNextSessionIdle( Entry entry,
+                                      NextFilter nextFilter, IoSession session,
+                                      IdleStatus status )
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.sessionIdle( entry.nextFilter, session, status );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.sessionIdle( entry.nextFilter, session, status );
+                nextFilter.sessionIdle( session, status );
+            }
+            else // POSTPROCESS
+            {
+                nextFilter.sessionIdle( session, status );
+                entry.filter.sessionIdle( entry.nextFilter, session, status );
+            }
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public void dataRead( NextFilter nextFilter, IoSession session, ByteBuffer buf )
+    {
+        Entry head = this.head;
+        callNextDataRead(head, nextFilter, session, buf);
+    }
+
+    private void callNextDataRead( Entry entry,
+                                   NextFilter nextFilter, IoSession session,
+                                   ByteBuffer buf )
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.dataRead( entry.nextFilter, session, buf );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.dataRead( entry.nextFilter, session, buf );
+                nextFilter.dataRead( session, buf );
+            }
+            else // POSTPROCESS
+            {
+                nextFilter.dataRead( session, buf );
+                entry.filter.dataRead( entry.nextFilter, session, buf );
+            }
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public void dataWritten( NextFilter nextFilter, IoSession session, Object marker )
+    {
+        Entry head = this.head;
+        callNextDataWritten(head, nextFilter, session, marker);
+    }
+
+    private void callNextDataWritten( Entry entry,
+                                      NextFilter nextFilter, IoSession session,
+                                      Object marker ) 
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.dataWritten( entry.nextFilter, session, marker );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.dataWritten( entry.nextFilter, session, marker );
+                nextFilter.dataWritten( session, marker );
+            }
+            else // POSTPROCESS
+            {
+                nextFilter.dataWritten( session, marker );
+                entry.filter.dataWritten( entry.nextFilter, session, marker );
+            }
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public void exceptionCaught( NextFilter nextFilter, IoSession session, Throwable cause )
+    {
+        Entry head = this.head;
+        callNextExceptionCaught(head, nextFilter, session, cause);
+    }
+
+    private void callNextExceptionCaught( Entry entry,
+                                          NextFilter nextFilter, IoSession session,
+                                          Throwable cause )
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.exceptionCaught( entry.nextFilter, session, cause );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.exceptionCaught( entry.nextFilter, session, cause );
+                nextFilter.exceptionCaught( session, cause );
+            }
+            else // POSTPROCESS
+            {
+                entry.filter.exceptionCaught( entry.nextFilter, session, cause );
+                nextFilter.exceptionCaught( session, cause );
+            }
+        }
+        catch( Throwable e )
+        {
+            e.printStackTrace();
+        }
+    }
+    
+    public void filterWrite( NextFilter nextFilter,
+                             IoSession session, ByteBuffer buf, Object marker )
+    {
+        Entry tail = this.tail;
+        callPreviousFilterWrite( tail, nextFilter, session, buf, marker );
+    }
+
+    private void callPreviousFilterWrite( Entry entry,
+                                          NextFilter prevFilter, IoSession session,
+                                          ByteBuffer buf, Object marker )
+    {
+        if( buf == null )
+        {
+            return;
+        }
+        
+        try
+        {
+            if( prevFilter == null )
+            {
+                entry.filter.filterWrite( entry.prevFilter, session, buf, marker );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.filterWrite( entry.prevFilter, session, buf, marker );
+                prevFilter.filterWrite( session, buf, marker );
+            }
+            else // POSTPROCESS
+            {
+                entry.filter.filterWrite( entry.prevFilter, session, buf, marker );
+                prevFilter.filterWrite( session, buf, marker );
+            }
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public List getChildren()
+    {
+        List list = new ArrayList();
+        Entry e = head.nextEntry;
+        while( e != tail )
+        {
+            list.add( e.filter );
+            e = e.nextEntry;
+        }
+
+        return list;
+    }
+
+    public List getChildrenReversed()
+    {
+        List list = new ArrayList();
+        Entry e = tail.prevEntry;
+        while( e != head )
+        {
+            list.add( e.filter );
+            e = e.prevEntry;
+        }
+        while( e != null );
+
+        return list;
+
+    }
+    
+    private void fireExceptionCaught( IoSession session, Throwable cause )
+    {
+        try
+        {
+            getRoot().exceptionCaught( null, session, cause );
+        }
+        catch( Throwable t )
+        {
+            t.printStackTrace();
+        }
+    }
+    
+    protected abstract void doWrite( IoSession session, ByteBuffer buffer, Object marker );
+
+    private class Entry
+    {
+        private Entry prevEntry;
+
+        private Entry nextEntry;
+
+        private final String name;
+        
+        private final IoHandlerFilter filter;
+
+        private final NextFilter nextFilter;
+        
+        private final NextFilter prevFilter;
+
+        private Entry( Entry prevEntry, Entry nextEntry,
+                       String name, IoHandlerFilter filter )
+        {
+            if( filter == null )
+            {
+                throw new NullPointerException( "filter" );
+            }
+            if( name == null )
+            {
+                throw new NullPointerException( "name" );
+            }
+            
+            this.prevEntry = prevEntry;
+            this.nextEntry = nextEntry;
+            this.name = name;
+            this.filter = filter;
+            this.nextFilter = new NextFilter()
+            {
+
+                public void sessionOpened( IoSession session )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextSessionOpened( nextEntry, null, session );
+                }
+
+                public void sessionClosed( IoSession session )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextSessionClosed( nextEntry, null, session );
+                }
+
+                public void sessionIdle( IoSession session, IdleStatus status )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextSessionIdle( nextEntry, null, session, status );
+                }
+
+                public void exceptionCaught( IoSession session,
+                                            Throwable cause )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextExceptionCaught( nextEntry, null, session, cause );
+                }
+
+                public void dataRead( IoSession session, ByteBuffer buf )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextDataRead( nextEntry, null, session, buf );
+                }
+
+                public void dataWritten( IoSession session, Object marker )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextDataWritten( nextEntry, null, session, marker );
+                }
+                
+                public void filterWrite( IoSession session, ByteBuffer buf, Object marker )
+                {
+                    throw new IllegalStateException();
+                }
+            };
+            
+            this.prevFilter = new NextFilter()
+            {
+
+                public void sessionOpened( IoSession session )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void sessionClosed( IoSession session )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void sessionIdle( IoSession session, IdleStatus status )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void exceptionCaught( IoSession session,
+                                            Throwable cause )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void dataRead( IoSession session, ByteBuffer buf )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void dataWritten( IoSession session, Object marker )
+                {
+                    throw new IllegalStateException();
+                }
+                
+                public void filterWrite( IoSession session, ByteBuffer buf, Object marker )
+                {
+                    Entry nextEntry = Entry.this.prevEntry;
+                    callPreviousFilterWrite( nextEntry, null, session, buf, marker );
+                }
+            };
+        }
+        
+        public String getName()
+        {
+            return name;
+        }
+        
+        public IoHandlerFilter getFilter()
+        {
+            return filter;
+        }
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java Wed Mar 23 09:21:35 2005
@@ -20,7 +20,8 @@
 
 import java.io.IOException;
 import java.net.SocketAddress;
-import java.util.List;
+
+import org.apache.mina.common.FilterChainType;
 
 /**
  * Accepts incoming connection, communicates with clients, and fires events to
@@ -63,29 +64,9 @@
      */
     void unbind( SocketAddress address );
 
-    /**
-     * Adds the specified filter with the specified priority.  Greater priority
-     * value, higher priority, and thus evaluated more earlier.  Please note
-     * that priority value must be unique.
-     */
-    void addFilter( int priority, IoHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the filter list.
-     */
-    void removeFilter( IoHandlerFilter filter );
-
-    /**
-     * Removes all filters added to this acceptor.
-     */
-    void removeAllFilters();
+    IoHandlerFilterChain newFilterChain( FilterChainType type );
     
-    /**
-     * Returns the list of all filters ordered by priority (higher first).
-     * The returned list is clone of internal filter chain, and thus you
-     * cannot add or remove filters using it. 
-     */
-    List getAllFilters();
+    IoHandlerFilterChain getFilterChain();
     
     /**
      * Returns the current exception monitor.

Modified: directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java Wed Mar 23 09:21:35 2005
@@ -20,7 +20,8 @@
 
 import java.io.IOException;
 import java.net.SocketAddress;
-import java.util.List;
+
+import org.apache.mina.common.FilterChainType;
 
 /**
  * Connects to endpoint, communicates with the server, and fires events to
@@ -70,29 +71,9 @@
     IoSession connect( SocketAddress address, int timeout, IoHandler handler )
             throws IOException;
 
-    /**
-     * Adds the specified filter with the specified priority.  Greater priority
-     * value, higher priority, and thus evaluated more earlier.  Please note
-     * that priority value must be unique.
-     */
-    void addFilter( int priority, IoHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the filter list.
-     */
-    void removeFilter( IoHandlerFilter filter );
-
-    /**
-     * Removes all filters added to this connector.
-     */
-    void removeAllFilters();
+    IoHandlerFilterChain newFilterChain( FilterChainType type );
     
-    /**
-     * Returns the list of all filters ordered by priority (higher first).
-     * The returned list is clone of internal filter chain, and thus you
-     * cannot add or remove filters using it. 
-     */
-    List getAllFilters();
+    IoHandlerFilterChain getFilterChain();
 
     /**
      * Returns the current exception monitor.

Modified: directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilter.java Wed Mar 23 09:21:35 2005
@@ -51,37 +51,42 @@
     /**
      * Filters {@link IoHandler#sessionOpened(IoSession)} event.
      */
-    void sessionOpened( IoHandler nextHandler, IoSession session );
+    void sessionOpened( NextFilter nextFilter, IoSession session );
 
     /**
      * Filters {@link IoHandler#sessionClosed(IoSession)} event.
      */
-    void sessionClosed( IoHandler nextHandler, IoSession session );
+    void sessionClosed( NextFilter nextFilter, IoSession session );
 
     /**
      * Filters {@link IoHandler#sessionIdle(IoSession, IdleStatus)} event.
      */
-    void sessionIdle( IoHandler nextHandler, IoSession session,
-                     IdleStatus status );
+    void sessionIdle( NextFilter nextFilter, IoSession session,
+                      IdleStatus status );
 
     /**
      * Filters {@link IoHandler#exceptionCaught(IoSession, Throwable)} event.
      */
-    void exceptionCaught( IoHandler nextHandler, IoSession session,
-                         Throwable cause );
+    void exceptionCaught( NextFilter nextFilter, IoSession session,
+                          Throwable cause );
 
     /**
      * Filters {@link IoHandler#dataRead(IoSession, ByteBuffer)} event.
      */
-    void dataRead( IoHandler nextHandler, IoSession session, ByteBuffer buf );
+    void dataRead( NextFilter nextFilter, IoSession session, ByteBuffer buf );
 
     /**
      * Filters {@link IoHandler#dataWritten(IoSession, Object)} event.
      */
-    void dataWritten( IoHandler nextHandler, IoSession session, Object marker );
+    void dataWritten( NextFilter nextFilter, IoSession session, Object marker );
 
     /**
      * Filters {@link IoSession#write(ByteBuffer, Object)} method invocation.
      */
-    ByteBuffer filterWrite( IoSession session, ByteBuffer buf );
+    void filterWrite( NextFilter nextFilter, IoSession session, ByteBuffer buf, Object marker );
+    
+    public interface NextFilter extends IoHandler
+    {
+        void filterWrite( IoSession session, ByteBuffer buf, Object marker );
+    }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterAdapter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterAdapter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterAdapter.java Wed Mar 23 09:21:35 2005
@@ -35,42 +35,43 @@
  */
 public class IoHandlerFilterAdapter implements IoHandlerFilter
 {
-    public void sessionOpened( IoHandler nextHandler, IoSession session )
+    public void sessionOpened( NextFilter nextFilter, IoSession session )
     {
-        nextHandler.sessionOpened( session );
+        nextFilter.sessionOpened( session );
     }
 
-    public void sessionClosed( IoHandler nextHandler, IoSession session )
+    public void sessionClosed( NextFilter nextFilter, IoSession session )
     {
-        nextHandler.sessionClosed( session );
+        nextFilter.sessionClosed( session );
     }
 
-    public void sessionIdle( IoHandler nextHandler, IoSession session,
+    public void sessionIdle( NextFilter nextFilter, IoSession session,
                             IdleStatus status )
     {
-        nextHandler.sessionIdle( session, status );
+        nextFilter.sessionIdle( session, status );
     }
 
-    public void exceptionCaught( IoHandler nextHandler, IoSession session,
+    public void exceptionCaught( NextFilter nextFilter, IoSession session,
                                 Throwable cause )
     {
-        nextHandler.exceptionCaught( session, cause );
+        nextFilter.exceptionCaught( session, cause );
     }
 
-    public void dataRead( IoHandler nextHandler, IoSession session,
+    public void dataRead( NextFilter nextFilter, IoSession session,
                          ByteBuffer buf )
     {
-        nextHandler.dataRead( session, buf );
+        nextFilter.dataRead( session, buf );
     }
 
-    public void dataWritten( IoHandler nextHandler, IoSession session,
+    public void dataWritten( NextFilter nextFilter, IoSession session,
                             Object marker )
     {
-        nextHandler.dataWritten( session, marker );
+        nextFilter.dataWritten( session, marker );
     }
 
-    public ByteBuffer filterWrite( IoSession session, ByteBuffer buf )
+    public void filterWrite( NextFilter nextFilter, IoSession session,
+                             ByteBuffer buf, Object marker )
     {
-        return buf;
+        nextFilter.filterWrite( session, buf, marker );
     }
 }

Added: directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterChain.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterChain.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,22 @@
+package org.apache.mina.io;
+
+import java.util.List;
+
+import org.apache.mina.common.FilterChainType;
+
+
+public interface IoHandlerFilterChain extends IoHandlerFilter {
+    IoHandlerFilterChain getRoot();
+    IoHandlerFilterChain getParent();
+    FilterChainType getType();
+
+    IoHandlerFilter getChild( String name );
+    List getChildren();
+    List getChildrenReversed();
+    void addFirst( String name, IoHandlerFilter filter );
+    void addLast( String name, IoHandlerFilter filter );
+    void addBefore( String baseName, String name, IoHandlerFilter filter );
+    void addAfter( String baseName, String name, IoHandlerFilter filter );
+    void remove( String name );
+    void clear();
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/io/IoHandlerFilterChain.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java Wed Mar 23 09:21:35 2005
@@ -26,17 +26,16 @@
 import java.nio.channels.Selector;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
 import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerFilter;
-import org.apache.mina.util.IoHandlerFilterManager;
+import org.apache.mina.io.IoHandlerFilterChain;
 import org.apache.mina.util.Queue;
 
 /**
@@ -49,7 +48,7 @@
 {
     private static volatile int nextId = 0;
 
-    private final IoHandlerFilterManager filterManager = new IoHandlerFilterManager();
+    private final DatagramFilterChain filters = new DatagramFilterChain( FilterChainType.PREPROCESS, this );
 
     private final int id = nextId ++ ;
 
@@ -246,7 +245,7 @@
             DatagramChannel ch = ( DatagramChannel ) key.channel();
 
             DatagramSession session = new DatagramSession(
-                    DatagramAcceptor.this, filterManager, ch,
+                    DatagramAcceptor.this, filters, ch,
                     ( IoHandler ) key.attachment() );
             session.setSelectionKey( key );
 
@@ -280,12 +279,12 @@
                 newBuf.flip();
 
                 session.increaseReadBytes( newBuf.remaining() );
-                filterManager.fireDataRead( session, newBuf );
+                filters.dataRead( null, session, newBuf );
             }
         }
         catch( IOException e )
         {
-            filterManager.fireExceptionCaught( session, e );
+            filters.exceptionCaught( null, session, e );
         }
         finally
         {
@@ -316,7 +315,7 @@
             }
             catch( IOException e )
             {
-                session.getFilterManager().fireExceptionCaught( session, e );
+                session.getFilters().exceptionCaught( null, session, e );
             }
         }
     }
@@ -356,11 +355,11 @@
                 }
                 catch( IllegalStateException e )
                 {
-                    session.getFilterManager().fireExceptionCaught( session,
+                    session.getFilters().exceptionCaught( null, session,
                             e );
                 }
 
-                session.getFilterManager().fireDataWritten( session, marker );
+                session.getFilters().dataWritten( null, session, marker );
                 continue;
             }
 
@@ -386,7 +385,7 @@
                 }
 
                 session.increaseWrittenBytes( writtenBytes );
-                session.getFilterManager().fireDataWritten( session, marker );
+                session.getFilters().dataWritten( null, session, marker );
             }
         }
     }
@@ -496,25 +495,15 @@
             }
         }
     }
-
-    public void addFilter( int priority, IoHandlerFilter filter )
-    {
-        filterManager.addFilter( priority, false, filter );
-    }
-
-    public void removeFilter( IoHandlerFilter filter )
+    
+    public IoHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        filterManager.removeFilter( filter );
+        return new DatagramFilterChain( type, this );
     }
-
-    public void removeAllFilters()
-    {
-        filterManager.removeAllFilters();
-    }
-
-    public List getAllFilters()
+    
+    public IoHandlerFilterChain getFilterChain()
     {
-        return filterManager.getAllFilters();
+        return filters;
     }
 
     private static class RegistrationRequest

Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java Wed Mar 23 09:21:35 2005
@@ -26,17 +26,16 @@
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
 import org.apache.mina.io.IoConnector;
 import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerFilter;
+import org.apache.mina.io.IoHandlerFilterChain;
 import org.apache.mina.io.IoSession;
-import org.apache.mina.util.IoHandlerFilterManager;
 import org.apache.mina.util.Queue;
 
 /**
@@ -50,7 +49,7 @@
 {
     private static volatile int nextId = 0;
 
-    private final IoHandlerFilterManager filterManager = new IoHandlerFilterManager();
+    private final DatagramFilterChain filters = new DatagramFilterChain( FilterChainType.PREPROCESS, this );
 
     private final int id = nextId ++ ;
 
@@ -250,12 +249,12 @@
                 newBuf.put( readBuf );
                 newBuf.flip();
 
-                filterManager.fireDataRead( session, newBuf );
+                filters.dataRead( null, session, newBuf );
             }
         }
         catch( IOException e )
         {
-            filterManager.fireExceptionCaught( session, e );
+            filters.exceptionCaught( null, session, e );
         }
         finally
         {
@@ -286,7 +285,7 @@
             }
             catch( IOException e )
             {
-                session.getFilterManager().fireExceptionCaught( session, e );
+                session.getFilters().exceptionCaught( null, session, e );
             }
         }
     }
@@ -326,11 +325,11 @@
                 }
                 catch( IllegalStateException e )
                 {
-                    session.getFilterManager().fireExceptionCaught( session,
+                    session.getFilters().exceptionCaught( null, session,
                             e );
                 }
 
-                session.getFilterManager().fireDataWritten( session, marker );
+                session.getFilters().dataWritten( null, session, marker );
                 continue;
             }
 
@@ -353,7 +352,7 @@
                     writeBufferQueue.pop();
                     writeMarkerQueue.pop();
                 }
-                session.getFilterManager().fireDataWritten( session, marker );
+                session.getFilters().dataWritten( null, session, marker );
             }
         }
     }
@@ -375,7 +374,7 @@
                 break;
 
             DatagramSession session = new DatagramSession( this,
-                    filterManager, req.channel, req.handler );
+                    filters, req.channel, req.handler );
 
             SelectionKey key = req.channel.register( selector,
                     SelectionKey.OP_READ, session );
@@ -421,24 +420,14 @@
         }
     }
 
-    public void addFilter( int priority, IoHandlerFilter filter )
+    public IoHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        filterManager.addFilter( priority, false, filter );
+        return new DatagramFilterChain( type, this );
     }
-
-    public void removeFilter( IoHandlerFilter filter )
-    {
-        filterManager.removeFilter( filter );
-    }
-
-    public void removeAllFilters()
-    {
-        filterManager.removeAllFilters();
-    }
-
-    public List getAllFilters()
+    
+    public IoHandlerFilterChain getFilterChain()
     {
-        return filterManager.getAllFilters();
+        return filters;
     }
 
     private static class RegistrationRequest

Added: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramFilterChain.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramFilterChain.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,34 @@
+package org.apache.mina.io.datagram;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.FilterChainType;
+import org.apache.mina.io.AbstractIoHandlerFilterChain;
+import org.apache.mina.io.IoSession;
+import org.apache.mina.util.Queue;
+
+class DatagramFilterChain extends AbstractIoHandlerFilterChain {
+
+    private final DatagramProcessor processor;
+
+    DatagramFilterChain( FilterChainType type, DatagramProcessor processor )
+    {
+        super( type );
+        
+        this.processor = processor;
+    }
+
+    protected void doWrite( IoSession session, ByteBuffer buf, Object marker )
+    {
+        DatagramSession s = ( DatagramSession ) session;
+        Queue writeBufferQueue = s.getWriteBufferQueue();
+        Queue writeMarkerQueue = s.getWriteMarkerQueue();
+        
+        synchronized( writeBufferQueue )
+        {
+            writeBufferQueue.push( buf );
+            writeMarkerQueue.push( marker );
+        }
+
+        processor.flushSession( s );
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramFilterChain.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java Wed Mar 23 09:21:35 2005
@@ -28,9 +28,7 @@
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoSession;
-import org.apache.mina.util.IoHandlerFilterManager;
 import org.apache.mina.util.Queue;
-import org.apache.mina.util.IoHandlerFilterManager.WriteCommand;
 
 /**
  * TODO Insert type comment.
@@ -42,7 +40,7 @@
 {
     private final DatagramProcessor parent;
 
-    private final IoHandlerFilterManager filterManager;
+    private final DatagramFilterChain filters;
 
     private final DatagramChannel ch;
 
@@ -56,8 +54,6 @@
 
     private final SocketAddress localAddress;
 
-    private final WriteCommand writeCommand = new WriteCommandImpl();
-
     private SocketAddress remoteAddress;
 
     private SelectionKey key;
@@ -82,11 +78,11 @@
      * Creates a new instance.
      */
     DatagramSession( DatagramProcessor parent,
-                    IoHandlerFilterManager filterManager, DatagramChannel ch,
+                    DatagramFilterChain filters, DatagramChannel ch,
                     IoHandler defaultHandler )
     {
         this.parent = parent;
-        this.filterManager = filterManager;
+        this.filters = filters;
         this.ch = ch;
         this.config = new DatagramSessionConfig( ch );
         this.writeBufferQueue = new Queue();
@@ -96,9 +92,9 @@
         this.localAddress = ch.socket().getLocalSocketAddress();
     }
 
-    IoHandlerFilterManager getFilterManager()
+    DatagramFilterChain getFilters()
     {
-        return filterManager;
+        return filters;
     }
 
     DatagramChannel getChannel()
@@ -147,7 +143,7 @@
 
     public void write( ByteBuffer buf, Object marker )
     {
-        filterManager.write( this, writeCommand, buf, marker );
+        filters.filterWrite( null, this, buf, marker );
     }
 
     public TransportType getTransportType()
@@ -242,19 +238,5 @@
         else
             throw new IllegalArgumentException( "Unknown idle status: "
                                                 + status );
-    }
-
-    private class WriteCommandImpl implements WriteCommand
-    {
-        public void execute( ByteBuffer buf, Object marker )
-        {
-            synchronized( writeBufferQueue )
-            {
-                writeBufferQueue.push( buf );
-                writeMarkerQueue.push( marker );
-            }
-
-            parent.flushSession( DatagramSession.this );
-        }
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/BlacklistFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/BlacklistFilter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/BlacklistFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/BlacklistFilter.java Wed Mar 23 09:21:35 2005
@@ -25,7 +25,6 @@
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
 import org.apache.mina.io.IoHandlerFilterAdapter;
 import org.apache.mina.io.IoSession;
@@ -61,13 +60,13 @@
      * Forwards event if and if only the remote address of session is not
      * blacklisted.
      */
-    public void dataRead( IoHandler nextHandler, IoSession session,
+    public void dataRead( NextFilter nextFilter, IoSession session,
                          ByteBuffer buf )
     {
         if( !isBlocked( session ) )
         {
             // forward if not blocked
-            super.dataRead( nextHandler, session, buf );
+            super.dataRead( nextFilter, session, buf );
         }
     }
 
@@ -75,7 +74,7 @@
      * Close connection immediately if the remote address of session is
      * blacklisted.
      */
-    public void sessionOpened( IoHandler nextHandler, IoSession session )
+    public void sessionOpened( NextFilter nextFilter, IoSession session )
     {
         if( isBlocked( session ) )
         {
@@ -84,7 +83,7 @@
         }
         else
         {
-            super.sessionOpened( nextHandler, session );
+            super.sessionOpened( nextFilter, session );
         }
     }
 

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/IoThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/IoThreadPoolFilter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/IoThreadPoolFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/IoThreadPoolFilter.java Wed Mar 23 09:21:35 2005
@@ -197,49 +197,49 @@
         }
     }
 
-    public void sessionOpened( IoHandler nextHandler, IoSession session )
+    public void sessionOpened( NextFilter nextFilter, IoSession session )
     {
-        fireEvent( nextHandler, session, EventType.OPENED, null );
+        fireEvent( nextFilter, session, EventType.OPENED, null );
     }
 
-    public void sessionClosed( IoHandler nextHandler, IoSession session )
+    public void sessionClosed( NextFilter nextFilter, IoSession session )
     {
-        fireEvent( nextHandler, session, EventType.CLOSED, null );
+        fireEvent( nextFilter, session, EventType.CLOSED, null );
     }
 
-    public void sessionIdle( IoHandler nextHandler, IoSession session,
+    public void sessionIdle( NextFilter nextFilter, IoSession session,
                             IdleStatus status )
     {
-        fireEvent( nextHandler, session, EventType.IDLE, status );
+        fireEvent( nextFilter, session, EventType.IDLE, status );
     }
 
-    public void exceptionCaught( IoHandler nextHandler, IoSession session,
+    public void exceptionCaught( NextFilter nextFilter, IoSession session,
                                 Throwable cause )
     {
-        fireEvent( nextHandler, session, EventType.EXCEPTION, cause );
+        fireEvent( nextFilter, session, EventType.EXCEPTION, cause );
     }
 
-    public void dataRead( IoHandler nextHandler, IoSession session,
+    public void dataRead( NextFilter nextFilter, IoSession session,
                          ByteBuffer buf )
     {
         // MINA will release the buffer if this method returns.
         buf.acquire();
-        fireEvent( nextHandler, session, EventType.READ, buf );
+        fireEvent( nextFilter, session, EventType.READ, buf );
     }
 
-    public void dataWritten( IoHandler nextHandler, IoSession session,
+    public void dataWritten( NextFilter nextFilter, IoSession session,
                             Object marker )
     {
-        fireEvent( nextHandler, session, EventType.WRITTEN, marker );
+        fireEvent( nextFilter, session, EventType.WRITTEN, marker );
     }
 
-    private void fireEvent( IoHandler nextHandler, IoSession session,
+    private void fireEvent( NextFilter nextFilter, IoSession session,
                            EventType type, Object data )
     {
         SessionBuffer buf = getSessionBuffer( session );
         synchronized( buf )
         {
-            buf.nextHandlers.push( nextHandler );
+            buf.nextFilters.push( nextFilter );
             buf.eventTypes.push( type );
             buf.eventDatum.push( data );
         }
@@ -285,7 +285,7 @@
 
         private final IoSession session;
 
-        private final Queue nextHandlers = new Queue();
+        private final Queue nextFilters = new Queue();
 
         private final Queue eventTypes = new Queue();
 
@@ -388,10 +388,10 @@
                         buf = ( SessionBuffer ) it.next();
                         it.remove();
                     }
-                    while( buf != null && buf.nextHandlers.isEmpty()
+                    while( buf != null && buf.nextFilters.isEmpty()
                            && it.hasNext() );
                 }
-                while( buf != null && buf.nextHandlers.isEmpty() );
+                while( buf != null && buf.nextFilters.isEmpty() );
             }
 
             return buf;
@@ -402,50 +402,50 @@
             IoSession session = buf.session;
             for( ;; )
             {
-                IoHandler nextHandler;
+                NextFilter nextFilter;
                 EventType type;
                 Object data;
                 synchronized( buf )
                 {
-                    nextHandler = ( IoHandler ) buf.nextHandlers.pop();
-                    if( nextHandler == null )
+                    nextFilter = ( NextFilter ) buf.nextFilters.pop();
+                    if( nextFilter == null )
                         break;
 
                     type = ( EventType ) buf.eventTypes.pop();
                     data = buf.eventDatum.pop();
                 }
-                processEvent( nextHandler, session, type, data );
+                processEvent( nextFilter, session, type, data );
             }
         }
 
-        private void processEvent( IoHandler nextHandler, IoSession session,
+        private void processEvent( NextFilter nextFilter, IoSession session,
                                   EventType type, Object data )
         {
             if( type == EventType.READ )
             {
                 ByteBuffer buf = ( ByteBuffer ) data;
-                nextHandler.dataRead( session, buf );
+                nextFilter.dataRead( session, buf );
                 buf.release();
             }
             else if( type == EventType.WRITTEN )
             {
-                nextHandler.dataWritten( session, data );
+                nextFilter.dataWritten( session, data );
             }
             else if( type == EventType.EXCEPTION )
             {
-                nextHandler.exceptionCaught( session, ( Throwable ) data );
+                nextFilter.exceptionCaught( session, ( Throwable ) data );
             }
             else if( type == EventType.IDLE )
             {
-                nextHandler.sessionIdle( session, ( IdleStatus ) data );
+                nextFilter.sessionIdle( session, ( IdleStatus ) data );
             }
             else if( type == EventType.OPENED )
             {
-                nextHandler.sessionOpened( session );
+                nextFilter.sessionOpened( session );
             }
             else if( type == EventType.CLOSED )
             {
-                nextHandler.sessionClosed( session );
+                nextFilter.sessionClosed( session );
             }
         }
 
@@ -468,7 +468,7 @@
             synchronized( readySessionBuffers )
             {
                 busySessionBuffers.remove( buf );
-                if( buf.nextHandlers.isEmpty() )
+                if( buf.nextFilters.isEmpty() )
                 {
                     removeSessionBuffer( buf );
                 }
@@ -548,8 +548,8 @@
         }
     }
 
-    public ByteBuffer filterWrite( IoSession session, ByteBuffer buf )
+    public void filterWrite( NextFilter nextFilter, IoSession session, ByteBuffer buf, Object marker )
     {
-        return buf;
+        nextFilter.filterWrite( session, buf, marker );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java Wed Mar 23 09:21:35 2005
@@ -31,7 +31,6 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.io.DefaultExceptionMonitor;
-import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilterAdapter;
 import org.apache.mina.io.IoSession;
 
@@ -109,14 +108,14 @@
 
     // IoHandlerFilter impl.
 
-    public void sessionOpened( IoHandler nextHandler, IoSession session )
+    public void sessionOpened( NextFilter nextFilter, IoSession session )
     {
-        nextHandler.sessionOpened( session );
+        nextFilter.sessionOpened( session );
         // Create an SSL handler
         createSSLSessionHandler( session );
     }
 
-    public void sessionClosed( IoHandler nextHandler, IoSession session )
+    public void sessionClosed( NextFilter nextFilter, IoSession session )
     {
         SSLHandler sslHandler = getSSLSessionHandler( session );
         if( debug != null )
@@ -136,12 +135,12 @@
             }
             catch( SSLException ssle )
             {
-                nextHandler.exceptionCaught( session, ssle );
+                nextFilter.exceptionCaught( session, ssle );
             }
             finally
             {
                 // notify closed session
-                nextHandler.sessionClosed( session );
+                nextFilter.sessionClosed( session );
 
                 // release buffers
                 sslHandler.release();
@@ -150,7 +149,7 @@
         }
     }
 
-    public void dataRead( IoHandler nextHandler, IoSession session,
+    public void dataRead( NextFilter nextFilter, IoSession session,
                          ByteBuffer buf )
     {
         SSLHandler sslHandler = getSSLSessionHandler( session );
@@ -169,7 +168,7 @@
                     sslHandler.dataRead( buf.buf() );
 
                     // Handle data to be forwarded to application or written to net
-                    handleSSLData( nextHandler, session, sslHandler );
+                    handleSSLData( nextFilter, session, sslHandler );
 
                     if( sslHandler.isClosed() )
                     {
@@ -191,23 +190,23 @@
                         ssle = newSSLE;
                     }
 
-                    nextHandler.exceptionCaught( session, ssle );
+                    nextFilter.exceptionCaught( session, ssle );
                 }
             }
         }
         else
         {
-            nextHandler.dataRead( session, buf );
+            nextFilter.dataRead( session, buf );
         }
     }
 
-    public void dataWritten( IoHandler nextHandler, IoSession session,
+    public void dataWritten( NextFilter nextFilter, IoSession session,
                             Object marker )
     {
-        nextHandler.dataWritten( session, marker );
+        nextFilter.dataWritten( session, marker );
     }
 
-    public ByteBuffer filterWrite( IoSession session, ByteBuffer buf )
+    public void filterWrite( NextFilter nextFilter, IoSession session, ByteBuffer buf, Object marker )
     {
 
         SSLHandler sslHandler = getSSLSessionHandler( session );
@@ -226,7 +225,8 @@
                     {
                         debug.print( "  already encrypted: " + buf );
                     }
-                    return buf;
+                    nextFilter.filterWrite( session, buf, marker );
+                    return;
                 }
                 if( sslHandler.isInitialHandshakeComplete() )
                 {
@@ -246,7 +246,9 @@
                             debug.print( "encrypted data: "
                                     + encryptedBuffer.getHexDump() );
                         }
-                        return encryptedBuffer;
+                        buf.release();
+                        nextFilter.filterWrite( session, encryptedBuffer, marker );
+                        return;
                     }
                     catch( SSLException ssle )
                     {
@@ -256,21 +258,22 @@
                 }
             }
         }
-        return buf;
+        
+        nextFilter.filterWrite( session, buf, marker );
     }
 
     // Utiliities
 
-    private void handleSSLData( IoHandler nextHandler, IoSession session,
+    private void handleSSLData( NextFilter nextFilter, IoSession session,
                                SSLHandler sslHandler ) throws SSLException
     {
         // First write encrypted data to be written (if any)
         writeNetBuffer( session, sslHandler );
         // handle app. data read (if any)
-        handleAppDataRead( nextHandler, session, sslHandler );
+        handleAppDataRead( nextFilter, session, sslHandler );
     }
 
-    private void handleAppDataRead( IoHandler nextHandler, IoSession session,
+    private void handleAppDataRead( NextFilter nextFilter, IoSession session,
                                    SSLHandler sslHandler )
     {
         if( debug != null )
@@ -285,7 +288,7 @@
             {
                 debug.print( "app data read: " + readBuffer + " (" + readBuffer.getHexDump() + ')' );
             }
-            nextHandler.dataRead( session, readBuffer );
+            nextFilter.dataRead( session, readBuffer );
         }
     }
 

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java Wed Mar 23 09:21:35 2005
@@ -27,15 +27,14 @@
 import java.nio.channels.SocketChannel;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
 import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerFilter;
-import org.apache.mina.util.IoHandlerFilterManager;
+import org.apache.mina.io.IoHandlerFilterChain;
 import org.apache.mina.util.Queue;
 
 /**
@@ -48,7 +47,7 @@
 {
     private static volatile int nextId = 0;
 
-    private final IoHandlerFilterManager filterManager = new IoHandlerFilterManager();
+    private final SocketFilterChain filters = new SocketFilterChain( FilterChainType.PREPROCESS );
 
     private final int id = nextId ++ ;
 
@@ -225,7 +224,7 @@
                             continue;
 
                         SocketSession session = new SocketSession(
-                                filterManager, ch, ( IoHandler ) key
+                                filters, ch, ( IoHandler ) key
                                         .attachment() );
                         SocketIoProcessor.getInstance().addSession( session );
                     }
@@ -352,27 +351,17 @@
             }
         }
     }
-
-    public void addFilter( int priority, IoHandlerFilter filter )
+    
+    public IoHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        filterManager.addFilter( priority, false, filter );
+        return new SocketFilterChain( type );
     }
-
-    public void removeFilter( IoHandlerFilter filter )
-    {
-        filterManager.removeFilter( filter );
-    }
-
-    public void removeAllFilters()
+    
+    public IoHandlerFilterChain getFilterChain()
     {
-        filterManager.removeAllFilters();
+        return filters;
     }
-
-    public List getAllFilters()
-    {
-        return filterManager.getAllFilters();
-    }
-
+    
     private static class RegistrationRequest
     {
         private final SocketAddress address;

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnector.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnector.java Wed Mar 23 09:21:35 2005
@@ -26,16 +26,15 @@
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Set;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
 import org.apache.mina.io.IoConnector;
 import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerFilter;
+import org.apache.mina.io.IoHandlerFilterChain;
 import org.apache.mina.io.IoSession;
-import org.apache.mina.util.IoHandlerFilterManager;
 import org.apache.mina.util.Queue;
 
 /**
@@ -50,7 +49,7 @@
 
     private final int id = nextId++;
 
-    private final IoHandlerFilterManager filterManager = new IoHandlerFilterManager();
+    private final SocketFilterChain filters = new SocketFilterChain( FilterChainType.PREPROCESS );
 
     private final Selector selector;
 
@@ -247,7 +246,7 @@
 
     private SocketSession newSession( SocketChannel ch, IoHandler handler )
     {
-        SocketSession session = new SocketSession( filterManager, ch, handler );
+        SocketSession session = new SocketSession( filters, ch, handler );
         SocketIoProcessor.getInstance().addSession( session );
         return session;
     }
@@ -324,25 +323,14 @@
         }
     }
 
-    public void addFilter( int priority, IoHandlerFilter filter )
+    public IoHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        filterManager.addFilter( priority, false, filter );
-
+        return new SocketFilterChain( type );
     }
-
-    public void removeFilter( IoHandlerFilter filter )
-    {
-        filterManager.removeFilter( filter );
-    }
-
-    public void removeAllFilters()
-    {
-    	filterManager.removeAllFilters();
-    }
-
-    public List getAllFilters()
+    
+    public IoHandlerFilterChain getFilterChain()
     {
-    	return filterManager.getAllFilters();
+        return filters;
     }
 
     public ExceptionMonitor getExceptionMonitor()

Added: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketFilterChain.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketFilterChain.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,30 @@
+package org.apache.mina.io.socket;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.FilterChainType;
+import org.apache.mina.io.AbstractIoHandlerFilterChain;
+import org.apache.mina.io.IoSession;
+import org.apache.mina.util.Queue;
+
+class SocketFilterChain extends AbstractIoHandlerFilterChain {
+
+    SocketFilterChain( FilterChainType type )
+    {
+        super( type );
+    }
+
+    protected void doWrite( IoSession session, ByteBuffer buf, Object marker )
+    {
+        SocketSession s = ( SocketSession ) session;
+        Queue writeBufferQueue = s.getWriteBufferQueue();
+        Queue writeMarkerQueue = s.getWriteMarkerQueue();
+        
+        synchronized( writeBufferQueue )
+        {
+            writeBufferQueue.push( buf );
+            writeMarkerQueue.push( marker );
+        }
+
+        SocketIoProcessor.getInstance().flushSession( s );
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketFilterChain.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java Wed Mar 23 09:21:35 2005
@@ -156,12 +156,12 @@
             catch( IOException e )
             {
                 registered = false;
-                session.getFilterManager().fireExceptionCaught( session, e );
+                session.getFilters().exceptionCaught( null, session, e );
             }
 
             if( registered )
             {
-                session.getFilterManager().fireSessionOpened( session );
+                session.getFilters().sessionOpened( null, session );
             }
         }
     }
@@ -193,11 +193,11 @@
             }
             catch( IOException e )
             {
-                session.getFilterManager().fireExceptionCaught( session, e );
+                session.getFilters().exceptionCaught( null, session, e );
             }
             finally
             {
-                session.getFilterManager().fireSessionClosed( session );
+                session.getFilters().sessionClosed( null, session );
             }
         }
     }
@@ -259,7 +259,7 @@
                     ByteBuffer newBuf = ByteBuffer.allocate( readBytes );
                     newBuf.put( buf );
                     newBuf.flip();
-                    session.getFilterManager().fireDataRead( session, newBuf );
+                    session.getFilters().dataRead( null, session, newBuf );
                 }
             }
             else
@@ -271,7 +271,7 @@
         {
             if( e instanceof IOException )
                 scheduleRemove( session );
-            session.getFilterManager().fireExceptionCaught( session, e );
+            session.getFilters().exceptionCaught( null, session, e );
         }
     }
 
@@ -341,7 +341,7 @@
             && ( currentTime - lastIoTime ) >= idleTime )
         {
             session.setIdle( status, true );
-            session.getFilterManager().fireSessionIdle( session, status );
+            session.getFilters().sessionIdle( null, session, status );
         }
     }
 
@@ -354,8 +354,8 @@
             && ( session.getSelectionKey().interestOps() & SelectionKey.OP_WRITE ) != 0 )
         {
             session
-                    .getFilterManager()
-                    .fireExceptionCaught( session, new WriteTimeoutException() );
+                    .getFilters()
+                    .exceptionCaught( null, session, new WriteTimeoutException() );
         }
     }
 
@@ -386,7 +386,7 @@
             catch( IOException e )
             {
                 scheduleRemove( session );
-                session.getFilterManager().fireExceptionCaught( session, e );
+                session.getFilters().exceptionCaught( null, session, e );
             }
         }
     }
@@ -424,11 +424,11 @@
                 }
                 catch( IllegalStateException e )
                 {
-                    session.getFilterManager().fireExceptionCaught( session,
+                    session.getFilters().exceptionCaught( null, session,
                             e );
                 }
 
-                session.getFilterManager().fireDataWritten( session, marker );
+                session.getFilters().dataWritten( null, session, marker );
                 continue;
             }
 



Mime
View raw message