directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r158802 [2/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
Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java Wed Mar 23 09:21:35 2005
@@ -27,10 +27,9 @@
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoHandler;
+import org.apache.mina.io.IoHandlerFilterChain;
 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 +41,7 @@
 {
     private static final int READ_BUFFER_SIZE = 8192;
 
-    private final IoHandlerFilterManager filterManager;
+    private final IoHandlerFilterChain filters;
 
     private final SocketChannel ch;
 
@@ -60,8 +59,6 @@
 
     private final SocketAddress localAddress;
 
-    private final WriteCommand writeCommand = new WriteCommandImpl();
-
     private SelectionKey key;
 
     private Object attachment;
@@ -85,10 +82,10 @@
     /**
      * Creates a new instance.
      */
-    SocketSession( IoHandlerFilterManager filterManager, SocketChannel ch,
+    SocketSession( IoHandlerFilterChain filters, SocketChannel ch,
                   IoHandler defaultHandler )
     {
-        this.filterManager = filterManager;
+        this.filters = filters;
         this.ch = ch;
         this.config = new SocketSessionConfig( ch );
         this.readBuf = ByteBuffer.allocate( READ_BUFFER_SIZE ).limit( 0 );
@@ -99,9 +96,9 @@
         this.localAddress = ch.socket().getLocalSocketAddress();
     }
 
-    IoHandlerFilterManager getFilterManager()
+    IoHandlerFilterChain getFilters()
     {
-        return filterManager;
+        return filters;
     }
 
     SocketChannel getChannel()
@@ -166,7 +163,7 @@
 
     public void write( ByteBuffer buf, Object marker )
     {
-        filterManager.write( this, writeCommand, buf, marker );
+        filters.filterWrite( null, this, buf, marker );
     }
 
     public TransportType getTransportType()
@@ -256,19 +253,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 );
-            }
-
-            SocketIoProcessor.getInstance().flushSession( SocketSession.this );
-        }
     }
 }

Added: directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,701 @@
+package org.apache.mina.protocol;
+
+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.FilterChainType;
+import org.apache.mina.common.IdleStatus;
+
+public abstract class AbstractProtocolHandlerFilterChain implements ProtocolHandlerFilterChain
+{
+    private final ProtocolHandlerFilter HEAD_FILTER = new ProtocolHandlerFilter()
+    {
+        public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
+        {
+            nextFilter.sessionOpened( session );
+        }
+
+        public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
+        {
+            nextFilter.sessionClosed( session );
+        }
+
+        public void sessionIdle( NextFilter nextFilter, ProtocolSession session,
+                                IdleStatus status )
+        {
+            nextFilter.sessionIdle( session, status );
+        }
+
+        public void exceptionCaught( NextFilter nextFilter,
+                                    ProtocolSession session, Throwable cause )
+        {
+            nextFilter.exceptionCaught( session, cause );
+        }
+
+        public void messageReceived( NextFilter nextFilter, ProtocolSession session,
+                                     Object message )
+        {
+            nextFilter.messageReceived( session, message );
+        }
+
+        public void messageSent( NextFilter nextFilter, ProtocolSession session,
+                                 Object message )
+        {
+            nextFilter.messageSent( session, message );
+        }
+        
+        public void filterWrite( NextFilter nextFilter, ProtocolSession session,
+                                 Object message )
+        {
+            if( AbstractProtocolHandlerFilterChain.this.parent == null )
+            {
+                // write only when root filter chain traversal is finished.
+                doWrite( session, message );
+            }
+        }
+    };
+    
+    private static final ProtocolHandlerFilter TAIL_FILTER = new ProtocolHandlerFilter()
+    {
+        public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
+        {
+            session.getHandler().sessionOpened( session );
+        }
+
+        public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
+        {
+            session.getHandler().sessionClosed( session );
+        }
+
+        public void sessionIdle( NextFilter nextFilter, ProtocolSession session,
+                                IdleStatus status )
+        {
+            session.getHandler().sessionIdle( session, status );
+        }
+
+        public void exceptionCaught( NextFilter nextFilter,
+                                    ProtocolSession session, Throwable cause )
+        {
+            session.getHandler().exceptionCaught( session, cause );
+        }
+
+        public void messageReceived( NextFilter nextFilter, ProtocolSession session,
+                                     Object message )
+        {
+            ProtocolHandler handler = session.getHandler();
+            handler.messageReceived( session, message );
+        }
+
+        public void messageSent( NextFilter nextFilter, ProtocolSession session,
+                                 Object message )
+        {
+            session.getHandler().messageSent( session, message );
+        }
+
+        public void filterWrite( NextFilter nextFilter,
+                                 ProtocolSession session, Object message )
+        {
+            nextFilter.filterWrite( session, message );
+        }
+    };
+
+    private AbstractProtocolHandlerFilterChain 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 AbstractProtocolHandlerFilterChain( 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 ProtocolHandlerFilterChain getRoot()
+    {
+        AbstractProtocolHandlerFilterChain current = this;
+        while( current.parent != null )
+        {
+            current = current.parent;
+        }
+        return current;
+    }
+    
+    public ProtocolHandlerFilterChain getParent()
+    {
+        return parent;
+    }
+    
+    public FilterChainType getType()
+    {
+        return type;
+    }
+    
+    public ProtocolHandlerFilter 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,
+                                       ProtocolHandlerFilter 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,
+                                      ProtocolHandlerFilter 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,
+                                        ProtocolHandlerFilter 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,
+                                       ProtocolHandlerFilter 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 );
+        ProtocolHandlerFilter filter = entry.filter;
+        filter2entry.remove( filter );
+        if ( filter instanceof AbstractProtocolHandlerFilterChain )
+        {
+            ( ( AbstractProtocolHandlerFilterChain ) 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, ProtocolHandlerFilter 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 AbstractProtocolHandlerFilterChain )
+        {
+            ( ( AbstractProtocolHandlerFilterChain ) 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, ProtocolHandlerFilter filter )
+    {
+        if ( name2entry.containsKey( name ) )
+        {
+            throw new IllegalArgumentException( "Other interceptor is using name '" + name + "'" );
+        }
+
+        if ( filter instanceof AbstractProtocolHandlerFilterChain )
+        {
+            if ( ( ( AbstractProtocolHandlerFilterChain ) filter ).parent != null )
+            {
+                throw new IllegalArgumentException( "This interceptor chain has its parent already." );
+            }
+        }
+    }
+
+    public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
+    {
+        Entry head = this.head;
+        callNextSessionOpened(head, nextFilter, session);
+    }
+
+    private void callNextSessionOpened( Entry entry,
+                                        NextFilter nextFilter, ProtocolSession 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, ProtocolSession session )
+    {
+        Entry head = this.head;
+        callNextSessionClosed(head, nextFilter, session);
+    }
+
+    private void callNextSessionClosed( Entry entry,
+                                        NextFilter nextFilter, ProtocolSession 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, ProtocolSession session, IdleStatus status )
+    {
+        Entry head = this.head;
+        callNextSessionIdle(head, nextFilter, session, status);
+    }
+
+    private void callNextSessionIdle( Entry entry,
+                                      NextFilter nextFilter, ProtocolSession 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 messageReceived( NextFilter nextFilter, ProtocolSession session, Object message )
+    {
+        Entry head = this.head;
+        callNextMessageReceived(head, nextFilter, session, message );
+    }
+
+    private void callNextMessageReceived( Entry entry,
+                                   NextFilter nextFilter, ProtocolSession session,
+                                   Object message )
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.messageReceived( entry.nextFilter, session, message );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.messageReceived( entry.nextFilter, session, message );
+                nextFilter.messageReceived( session, message );
+            }
+            else // POSTPROCESS
+            {
+                nextFilter.messageReceived( session, message );
+                entry.filter.messageReceived( entry.nextFilter, session, message );
+            }
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public void messageSent( NextFilter nextFilter, ProtocolSession session, Object message )
+    {
+        Entry head = this.head;
+        callNextMessageSent(head, nextFilter, session, message);
+    }
+
+    private void callNextMessageSent( Entry entry,
+                                      NextFilter nextFilter, ProtocolSession session,
+                                      Object message ) 
+    {
+        try
+        {
+            if( nextFilter == null )
+            {
+                entry.filter.messageSent( entry.nextFilter, session, message );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.messageSent( entry.nextFilter, session, message );
+                nextFilter.messageSent( session, message );
+            }
+            else // POSTPROCESS
+            {
+                nextFilter.messageSent( session, message );
+                entry.filter.messageSent( entry.nextFilter, session, message );
+            }
+        }
+        catch( Throwable e )
+        {
+            fireExceptionCaught( session, e );
+        }
+    }
+
+    public void exceptionCaught( NextFilter nextFilter, ProtocolSession session, Throwable cause )
+    {
+        Entry head = this.head;
+        callNextExceptionCaught(head, nextFilter, session, cause);
+    }
+
+    private void callNextExceptionCaught( Entry entry,
+                                          NextFilter nextFilter, ProtocolSession 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,
+                             ProtocolSession session, Object message )
+    {
+        Entry tail = this.tail;
+        callPreviousFilterWrite( tail, nextFilter, session, message );
+    }
+
+    private void callPreviousFilterWrite( Entry entry,
+                                          NextFilter prevFilter, ProtocolSession session,
+                                          Object message )
+    {
+        if( message == null )
+        {
+            return;
+        }
+        
+        try
+        {
+            if( prevFilter == null )
+            {
+                entry.filter.filterWrite( entry.prevFilter, session, message );
+            }
+            else if( type == FilterChainType.PREPROCESS )
+            {
+                entry.filter.filterWrite( entry.prevFilter, session, message );
+                prevFilter.filterWrite( session, message );
+            }
+            else // POSTPROCESS
+            {
+                entry.filter.filterWrite( entry.prevFilter, session, message );
+                prevFilter.filterWrite( session, message );
+            }
+        }
+        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( ProtocolSession session, Throwable cause )
+    {
+        try
+        {
+            getRoot().exceptionCaught( null, session, cause );
+        }
+        catch( Throwable t )
+        {
+            t.printStackTrace();
+        }
+    }
+    
+    protected abstract void doWrite( ProtocolSession session, Object message );
+
+    private class Entry
+    {
+        private Entry prevEntry;
+
+        private Entry nextEntry;
+
+        private final String name;
+        
+        private final ProtocolHandlerFilter filter;
+
+        private final NextFilter nextFilter;
+        
+        private final NextFilter prevFilter;
+
+        private Entry( Entry prevEntry, Entry nextEntry,
+                       String name, ProtocolHandlerFilter 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( ProtocolSession session )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextSessionOpened( nextEntry, null, session );
+                }
+
+                public void sessionClosed( ProtocolSession session )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextSessionClosed( nextEntry, null, session );
+                }
+
+                public void sessionIdle( ProtocolSession session, IdleStatus status )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextSessionIdle( nextEntry, null, session, status );
+                }
+
+                public void exceptionCaught( ProtocolSession session,
+                                            Throwable cause )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextExceptionCaught( nextEntry, null, session, cause );
+                }
+
+                public void messageReceived( ProtocolSession session, Object message )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextMessageReceived( nextEntry, null, session, message );
+                }
+
+                public void messageSent( ProtocolSession session, Object message )
+                {
+                    Entry nextEntry = Entry.this.nextEntry;
+                    callNextMessageSent( nextEntry, null, session, message );
+                }
+                
+                public void filterWrite( ProtocolSession session, Object message )
+                {
+                    throw new IllegalStateException();
+                }
+            };
+            
+            this.prevFilter = new NextFilter()
+            {
+
+                public void sessionOpened( ProtocolSession session )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void sessionClosed( ProtocolSession session )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void sessionIdle( ProtocolSession session, IdleStatus status )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void exceptionCaught( ProtocolSession session,
+                                            Throwable cause )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void messageReceived( ProtocolSession session, Object message )
+                {
+                    throw new IllegalStateException();
+                }
+
+                public void messageSent( ProtocolSession session, Object message )
+                {
+                    throw new IllegalStateException();
+                }
+                
+                public void filterWrite( ProtocolSession session, Object message )
+                {
+                    Entry nextEntry = Entry.this.prevEntry;
+                    callPreviousFilterWrite( nextEntry, null, session, message );
+                }
+            };
+        }
+        
+        public String getName()
+        {
+            return name;
+        }
+        
+        public ProtocolHandlerFilter getFilter()
+        {
+            return filter;
+        }
+    }
+}

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

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAcceptor.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAcceptor.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
@@ -60,27 +61,7 @@
      */
     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, ProtocolHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the filter list.
-     */
-    void removeFilter( ProtocolHandlerFilter filter );
-
-    /**
-     * Removes all filters added to this acceptor.
-     */
-    void removeAllFilters();
-
-    /**
-     * 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();
+    ProtocolHandlerFilterChain newFilterChain( FilterChainType type );
+    
+    ProtocolHandlerFilterChain getFilterChain();
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConnector.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConnector.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
@@ -68,27 +69,7 @@
                             ProtocolProvider protocolProvider )
             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, ProtocolHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the filter list.
-     */
-    void removeFilter( ProtocolHandlerFilter filter );
-
-    /**
-     * Removes all filters added to this connector.
-     */
-    void removeAllFilters();
-
-    /**
-     * 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();
+    ProtocolHandlerFilterChain newFilterChain( FilterChainType type );
+    
+    ProtocolHandlerFilterChain getFilterChain();
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java Wed Mar 23 09:21:35 2005
@@ -48,43 +48,48 @@
     /**
      * Filters {@link ProtocolHandler#sessionOpened(ProtocolSession)} event.
      */
-    void sessionOpened( ProtocolHandler nextHandler, ProtocolSession session );
+    void sessionOpened( NextFilter nextFilter, ProtocolSession session );
 
     /**
      * Filters {@link ProtocolHandler#sessionClosed(ProtocolSession)} event.
      */
-    void sessionClosed( ProtocolHandler nextHandler, ProtocolSession session );
+    void sessionClosed( NextFilter nextFilter, ProtocolSession session );
 
     /**
      * Filters {@link ProtocolHandler#sessionIdle(ProtocolSession,IdleStatus)}
      * event.
      */
-    void sessionIdle( ProtocolHandler nextHandler, ProtocolSession session,
+    void sessionIdle( NextFilter nextFilter, ProtocolSession session,
                      IdleStatus status );
 
     /**
      * Filters {@link ProtocolHandler#exceptionCaught(ProtocolSession,Throwable)}
      * event.
      */
-    void exceptionCaught( ProtocolHandler nextHandler,
+    void exceptionCaught( NextFilter nextFilter,
                          ProtocolSession session, Throwable cause );
 
     /**
      * Filters {@link ProtocolHandler#messageReceived(ProtocolSession,Object)}
      * event.
      */
-    void messageReceived( ProtocolHandler nextHandler,
+    void messageReceived( NextFilter nextFilter,
                          ProtocolSession session, Object message );
 
     /**
      * Filters {@link ProtocolHandler#messageSent(ProtocolSession,Object)}
      * event.
      */
-    void messageSent( ProtocolHandler nextHandler, ProtocolSession session,
+    void messageSent( NextFilter nextFilter, ProtocolSession session,
                      Object message );
 
     /**
      * Filters {@link ProtocolSession#write(Object)} method invocation.
      */
-    Object filterWrite( ProtocolSession session, Object message );
+    void filterWrite( NextFilter nextFilter, ProtocolSession session, Object message );
+    
+    public interface NextFilter extends ProtocolHandler
+    {
+        void filterWrite( ProtocolSession session, Object message );
+    }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java Wed Mar 23 09:21:35 2005
@@ -30,44 +30,44 @@
  */
 public class ProtocolHandlerFilterAdapter implements ProtocolHandlerFilter
 {
-    public void sessionOpened( ProtocolHandler nextHandler,
+    public void sessionOpened( NextFilter nextFilter,
                               ProtocolSession session )
     {
-        nextHandler.sessionOpened( session );
+        nextFilter.sessionOpened( session );
     }
 
-    public void sessionClosed( ProtocolHandler nextHandler,
+    public void sessionClosed( NextFilter nextFilter,
                               ProtocolSession session )
     {
-        nextHandler.sessionClosed( session );
+        nextFilter.sessionClosed( session );
     }
 
-    public void sessionIdle( ProtocolHandler nextHandler,
+    public void sessionIdle( NextFilter nextFilter,
                             ProtocolSession session, IdleStatus status )
     {
-        nextHandler.sessionIdle( session, status );
+        nextFilter.sessionIdle( session, status );
     }
 
-    public void exceptionCaught( ProtocolHandler nextHandler,
+    public void exceptionCaught( NextFilter nextFilter,
                                 ProtocolSession session, Throwable cause )
     {
-        nextHandler.exceptionCaught( session, cause );
+        nextFilter.exceptionCaught( session, cause );
     }
 
-    public void messageReceived( ProtocolHandler nextHandler,
+    public void messageReceived( NextFilter nextFilter,
                                 ProtocolSession session, Object message )
     {
-        nextHandler.messageReceived( session, message );
+        nextFilter.messageReceived( session, message );
     }
 
-    public void messageSent( ProtocolHandler nextHandler,
+    public void messageSent( NextFilter nextFilter,
                             ProtocolSession session, Object message )
     {
-        nextHandler.messageSent( session, message );
+        nextFilter.messageSent( session, message );
     }
 
-    public Object filterWrite( ProtocolSession session, Object message )
+    public void filterWrite( NextFilter nextFilter, ProtocolSession session, Object message )
     {
-        return message;
+        nextFilter.filterWrite( session, message );
     }
 }

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

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

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolThreadPoolFilter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolThreadPoolFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolThreadPoolFilter.java Wed Mar 23 09:21:35 2005
@@ -169,49 +169,49 @@
         }
     }
 
-    public void sessionOpened( ProtocolHandler nextHandler,
+    public void sessionOpened( NextFilter nextFilter,
                               ProtocolSession session )
     {
-        fireEvent( nextHandler, session, EventType.OPENED, null );
+        fireEvent( nextFilter, session, EventType.OPENED, null );
     }
 
-    public void sessionClosed( ProtocolHandler nextHandler,
+    public void sessionClosed( NextFilter nextFilter,
                               ProtocolSession session )
     {
-        fireEvent( nextHandler, session, EventType.CLOSED, null );
+        fireEvent( nextFilter, session, EventType.CLOSED, null );
     }
 
-    public void sessionIdle( ProtocolHandler nextHandler,
+    public void sessionIdle( NextFilter nextFilter,
                             ProtocolSession session, IdleStatus status )
     {
-        fireEvent( nextHandler, session, EventType.IDLE, status );
+        fireEvent( nextFilter, session, EventType.IDLE, status );
     }
 
-    public void exceptionCaught( ProtocolHandler nextHandler,
+    public void exceptionCaught( NextFilter nextFilter,
                                 ProtocolSession session, Throwable cause )
     {
-        fireEvent( nextHandler, session, EventType.EXCEPTION, cause );
+        fireEvent( nextFilter, session, EventType.EXCEPTION, cause );
     }
 
-    public void messageReceived( ProtocolHandler nextHandler,
+    public void messageReceived( NextFilter nextFilter,
                                 ProtocolSession session, Object message )
     {
-        fireEvent( nextHandler, session, EventType.RECEIVED, message );
+        fireEvent( nextFilter, session, EventType.RECEIVED, message );
     }
 
-    public void messageSent( ProtocolHandler nextHandler,
+    public void messageSent( NextFilter nextFilter,
                             ProtocolSession session, Object message )
     {
-        fireEvent( nextHandler, session, EventType.SENT, message );
+        fireEvent( nextFilter, session, EventType.SENT, message );
     }
 
-    private void fireEvent( ProtocolHandler nextHandler,
+    private void fireEvent( NextFilter nextFilter,
                            ProtocolSession 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 );
         }
@@ -257,7 +257,7 @@
 
         private final ProtocolSession session;
 
-        private final Queue nextHandlers = new Queue();
+        private final Queue nextFilters = new Queue();
 
         private final Queue eventTypes = new Queue();
 
@@ -358,10 +358,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;
@@ -372,49 +372,49 @@
             ProtocolSession session = buf.session;
             for( ;; )
             {
-                ProtocolHandler nextHandler;
+                NextFilter nextFilter;
                 EventType type;
                 Object data;
                 synchronized( buf )
                 {
-                    nextHandler = ( ProtocolHandler ) 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( ProtocolHandler nextHandler,
+        private void processEvent( NextFilter nextFilter,
                                   ProtocolSession session, EventType type,
                                   Object data )
         {
             if( type == EventType.RECEIVED )
             {
-                nextHandler.messageReceived( session, data );
+                nextFilter.messageReceived( session, data );
             }
             else if( type == EventType.SENT )
             {
-                nextHandler.messageSent( session, data );
+                nextFilter.messageSent( 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 );
             }
         }
 
@@ -437,7 +437,7 @@
             synchronized( readySessionBuffers )
             {
                 busySessionBuffers.remove( buf );
-                if( buf.nextHandlers.isEmpty() )
+                if( buf.nextFilters.isEmpty() )
                 {
                     removeSessionBuffer( buf );
                 }
@@ -517,8 +517,8 @@
         }
     }
 
-    public Object filterWrite( ProtocolSession session, Object message )
+    public void filterWrite( NextFilter nextFilter, ProtocolSession session, Object message )
     {
-        return message;
+        nextFilter.filterWrite( session, message );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java Wed Mar 23 09:21:35 2005
@@ -19,9 +19,9 @@
 package org.apache.mina.protocol.io;
 
 import java.net.SocketAddress;
-import java.util.List;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
@@ -33,13 +33,11 @@
 import org.apache.mina.protocol.ProtocolEncoder;
 import org.apache.mina.protocol.ProtocolEncoderOutput;
 import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.protocol.ProtocolSession;
 import org.apache.mina.protocol.ProtocolViolationException;
-import org.apache.mina.util.ProtocolHandlerFilterManager;
 import org.apache.mina.util.Queue;
-import org.apache.mina.util.ProtocolHandlerFilterManager.WriteCommand;
 
 /**
  * Adapts the specified {@link ProtocolProvider} to {@link IoHandler}.
@@ -55,41 +53,20 @@
  */
 public class IoAdapter
 {
-    private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
+    private final IoProtocolFilterChain filters = new IoProtocolFilterChain( FilterChainType.PREPROCESS );
 
     IoAdapter()
     {
     }
-
-    /**
-     * 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.
-     */
-    public void addFilter( int priority, ProtocolHandlerFilter filter )
+    
+    public ProtocolHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        filterManager.addFilter( priority, false, filter );
+        return new IoProtocolFilterChain( type );
     }
-
-    /**
-     * Removes the specified filter from the filter list.
-     */
-    public void removeFilter( ProtocolHandlerFilter filter )
+    
+    public ProtocolHandlerFilterChain getFilterChain()
     {
-        filterManager.removeFilter( filter );
-    }
-
-    /**
-     * Removes all filters added to this adapter.
-     */
-    public void removeAllFilters()
-    {
-        filterManager.removeAllFilters();
-    }
-
-    public List getAllFilters()
-    {
-        return filterManager.getAllFilters();
+        return filters;
     }
 
     /**
@@ -120,7 +97,7 @@
         }
     }
 
-    private class SessionHandlerAdapter implements IoHandler
+    class SessionHandlerAdapter implements IoHandler
     {
         private final ProtocolCodecFactory codecFactory;
         private final ProtocolHandler handler;
@@ -133,23 +110,23 @@
 
         public void sessionOpened( IoSession session )
         {
-            filterManager.fireSessionOpened( getProtocolSession( session ) );
+            filters.sessionOpened( null, getProtocolSession( session ) );
         }
 
         public void sessionClosed( IoSession session )
         {
-            filterManager.fireSessionClosed( getProtocolSession( session ) );
+            filters.sessionClosed( null, getProtocolSession( session ) );
         }
 
         public void sessionIdle( IoSession session, IdleStatus status )
         {
-            filterManager.fireSessionIdle( getProtocolSession( session ),
+            filters.sessionIdle( null, getProtocolSession( session ),
                     status );
         }
 
         public void exceptionCaught( IoSession session, Throwable cause )
         {
-            filterManager.fireExceptionCaught( getProtocolSession( session ),
+            filters.exceptionCaught( null, getProtocolSession( session ),
                     cause );
         }
 
@@ -171,7 +148,7 @@
                     {
                         do
                         {
-                            filterManager.fireMessageReceived( psession,
+                            filters.messageReceived( null, psession,
                                     queue.pop() );
                         }
                         while( !queue.isEmpty() );
@@ -181,11 +158,11 @@
             catch( ProtocolViolationException pve )
             {
                 pve.setBuffer( in );
-                filterManager.fireExceptionCaught( psession, pve );
+                filters.exceptionCaught( null, psession, pve );
             }
             catch( Throwable t )
             {
-                filterManager.fireExceptionCaught( psession, t );
+                filters.exceptionCaught( null, psession, t );
             }
         }
 
@@ -193,11 +170,11 @@
         {
             if( marker == null )
                 return;
-            filterManager.fireMessageSent( ( ProtocolSession ) session
+            filters.messageSent( null, ( ProtocolSession ) session
                     .getAttachment(), marker );
         }
 
-        private void write( IoSession session )
+        void doWrite( IoSession session )
         {
             ProtocolSessionImpl psession = ( ProtocolSessionImpl ) session
                     .getAttachment();
@@ -235,7 +212,7 @@
             }
             catch( Throwable t )
             {
-                filterManager.fireExceptionCaught( psession, t );
+                filters.exceptionCaught( null, psession, t );
             }
         }
 
@@ -261,13 +238,13 @@
         }
     }
 
-    private class ProtocolSessionImpl implements ProtocolSession
+    class ProtocolSessionImpl implements ProtocolSession
     {
-        private final IoSession session;
+        final IoSession session;
 
-        private final SessionHandlerAdapter adapter;
+        final SessionHandlerAdapter adapter;
 
-        private final Queue writeQueue = new Queue();
+        final Queue writeQueue = new Queue();
         
         private final ProtocolEncoder encoder;
         
@@ -277,8 +254,6 @@
 
         private final ProtocolDecoderOutputImpl decOut;
 
-        private final WriteCommand writeCommand = new WriteCommandImpl();
-
         private Object attachment;
 
         private ProtocolSessionImpl( IoSession session,
@@ -324,7 +299,7 @@
 
         public void write( Object message )
         {
-            filterManager.write( this, writeCommand, message );
+            filters.filterWrite( null, this, message );
         }
 
         public TransportType getTransportType()
@@ -380,19 +355,6 @@
         public boolean isIdle( IdleStatus status )
         {
             return session.isIdle( status );
-        }
-
-        private class WriteCommandImpl implements WriteCommand
-        {
-            public void execute( Object message )
-            {
-                synchronized( writeQueue )
-                {
-                    writeQueue.push( message );
-                }
-
-                adapter.write( session );
-            }
         }
     }
 

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java Wed Mar 23 09:21:35 2005
@@ -5,11 +5,11 @@
 
 import java.io.IOException;
 import java.net.SocketAddress;
-import java.util.List;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.protocol.ProtocolAcceptor;
-import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
 
 /**
@@ -55,24 +55,14 @@
     {
         acceptor.unbind( address );
     }
-
-    public void addFilter( int priority, ProtocolHandlerFilter filter )
-    {
-        adapter.addFilter( priority, filter );
-    }
-
-    public void removeFilter( ProtocolHandlerFilter filter )
-    {
-        adapter.removeFilter( filter );
-    }
-
-    public void removeAllFilters()
+    
+    public ProtocolHandlerFilterChain newFilterChain( FilterChainType type )
     {
-    	adapter.removeAllFilters();
+        return adapter.newFilterChain( type );
     }
 
-    public List getAllFilters()
+    public ProtocolHandlerFilterChain getFilterChain()
     {
-    	return adapter.getAllFilters();
+        return adapter.getFilterChain();
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java Wed Mar 23 09:21:35 2005
@@ -5,12 +5,12 @@
 
 import java.io.IOException;
 import java.net.SocketAddress;
-import java.util.List;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.io.IoConnector;
 import org.apache.mina.io.IoSession;
 import org.apache.mina.protocol.ProtocolConnector;
-import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.protocol.ProtocolSession;
 
@@ -64,23 +64,13 @@
         return adapter.toProtocolSession( session );
     }
 
-    public void addFilter( int priority, ProtocolHandlerFilter filter )
+    public ProtocolHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        adapter.addFilter( priority, filter );
+        return adapter.newFilterChain( type );
     }
 
-    public void removeFilter( ProtocolHandlerFilter filter )
+    public ProtocolHandlerFilterChain getFilterChain()
     {
-        adapter.removeFilter( filter );
-    }
-
-    public void removeAllFilters()
-    {
-    	adapter.removeAllFilters();
-    }
-
-    public List getAllFilters()
-    {
-    	return adapter.getAllFilters();
+        return adapter.getFilterChain();
     }
 }

Added: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocolFilterChain.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,25 @@
+package org.apache.mina.protocol.io;
+
+import org.apache.mina.common.FilterChainType;
+import org.apache.mina.protocol.AbstractProtocolHandlerFilterChain;
+import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.protocol.io.IoAdapter.ProtocolSessionImpl;
+import org.apache.mina.util.Queue;
+
+class IoProtocolFilterChain extends AbstractProtocolHandlerFilterChain {
+
+    IoProtocolFilterChain(FilterChainType type) {
+        super(type);
+    }
+
+    protected void doWrite(ProtocolSession session, Object message) {
+        ProtocolSessionImpl s = ( ProtocolSessionImpl ) session;
+        Queue writeQueue = s.writeQueue;
+        synchronized( writeQueue )
+        {
+            writeQueue.push( message );
+        }
+
+        s.adapter.doWrite( s.session );
+    }
+}

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

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java Wed Mar 23 09:21:35 2005
@@ -6,14 +6,13 @@
 import java.io.IOException;
 import java.net.SocketAddress;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.protocol.ProtocolAcceptor;
 import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
-import org.apache.mina.util.ProtocolHandlerFilterManager;
 
 /**
  * Binds the specified {@link ProtocolProvider} to the specified
@@ -26,14 +25,14 @@
 {
     static final Map boundHandlers = new HashMap();
 
-    private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
+    private final VmPipeFilterChain filters = new VmPipeFilterChain( FilterChainType.PREPROCESS );
 
     /**
      * Creates a new instance.
      */
     public VmPipeAcceptor()
     {
-        filterManager.addFilter( Integer.MIN_VALUE + 1, true, new VmPipeFilter() );
+        filters.addLast( "VMPipe", new VmPipeFilter() );
     }
 
     public void bind( SocketAddress address, ProtocolProvider protocolProvider )
@@ -55,7 +54,7 @@
             }
 
             boundHandlers.put( address, new Entry( ( VmPipeAddress ) address,
-                    filterManager, protocolProvider.getHandler() ) );
+                    filters, protocolProvider.getHandler() ) );
         }
     }
 
@@ -69,41 +68,31 @@
             boundHandlers.remove( address );
         }
     }
-
-    public void addFilter( int priority, ProtocolHandlerFilter filter )
-    {
-        filterManager.addFilter( priority, false, filter );
-    }
-
-    public void removeFilter( ProtocolHandlerFilter filter )
+    
+    public ProtocolHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        filterManager.removeFilter( filter );
+        return new VmPipeFilterChain( type );
     }
-
-    public List getAllFilters()
-    {
-        return filterManager.getAllFilters();
-    }
-
-    public void removeAllFilters()
+    
+    public ProtocolHandlerFilterChain getFilterChain()
     {
-        filterManager.removeAllFilters();
+        return filters;
     }
 
     static class Entry
     {
         final VmPipeAddress address;
 
-        final ProtocolHandlerFilterManager filterManager;
+        final ProtocolHandlerFilterChain filters;
 
         final ProtocolHandler handler;
 
         private Entry( VmPipeAddress address,
-                      ProtocolHandlerFilterManager filterManager,
+                      ProtocolHandlerFilterChain filters,
                       ProtocolHandler handler )
         {
             this.address = address;
-            this.filterManager = filterManager;
+            this.filters = filters;
             this.handler = handler;
         }
     }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java Wed Mar 23 09:21:35 2005
@@ -5,14 +5,13 @@
 
 import java.io.IOException;
 import java.net.SocketAddress;
-import java.util.List;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.protocol.ProtocolConnector;
-import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.protocol.ProtocolSession;
 import org.apache.mina.protocol.vmpipe.VmPipeAcceptor.Entry;
-import org.apache.mina.util.ProtocolHandlerFilterManager;
 
 /**
  * Connects to {@link ProtocolProvider}s which is bound on the specified
@@ -23,34 +22,24 @@
  */
 public class VmPipeConnector implements ProtocolConnector
 {
-    private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
+    private final VmPipeFilterChain filters = new VmPipeFilterChain( FilterChainType.PREPROCESS );
 
     /**
      * Creates a new instance.
      */
     public VmPipeConnector()
     {
-        filterManager.addFilter( Integer.MIN_VALUE - 1, true, new VmPipeFilter() );
+        filters.addLast( "VMPipe", new VmPipeFilter() );
     }
-
-    public void addFilter( int priority, ProtocolHandlerFilter filter )
-    {
-        filterManager.addFilter( priority, false, filter );
-    }
-
-    public void removeFilter( ProtocolHandlerFilter filter )
+    
+    public ProtocolHandlerFilterChain newFilterChain( FilterChainType type )
     {
-        filterManager.removeFilter( filter );
+        return new VmPipeFilterChain( type );
     }
-
-    public void removeAllFilters()
-    {
-    	filterManager.removeAllFilters();
-    }
-
-    public List getAllFilters()
+    
+    public ProtocolHandlerFilterChain getFilterChain()
     {
-    	return filterManager.getAllFilters();
+        return filters;
     }
 
     public ProtocolSession connect( SocketAddress address,
@@ -73,10 +62,10 @@
                                                    new Object(), // lock
                                                    AnonymousVmPipeAddress.INSTANCE,
                                                    entry.address,
-                                                   filterManager,
+                                                   filters,
                                                    protocolProvider
                                                            .getHandler(),
-                                                   entry.filterManager,
+                                                   entry.filters,
                                                    entry.handler );
         VmPipeIdleStatusChecker.INSTANCE.addSession( session );
         return session;

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java Wed Mar 23 09:21:35 2005
@@ -24,7 +24,7 @@
         vps.lastReadTime = System.currentTimeMillis();
 
         // fire messageSent event first
-        vps.remoteFilterManager.fireMessageSent( vps.remoteSession, message );
+        vps.remoteFilters.messageSent( null, vps.remoteSession, message );
 
         // and then messageReceived
         nextHandler.messageReceived( session, message );

Added: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilterChain.java?view=auto&rev=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilterChain.java Wed Mar 23 09:21:35 2005
@@ -0,0 +1,26 @@
+package org.apache.mina.protocol.vmpipe;
+
+import org.apache.mina.common.FilterChainType;
+import org.apache.mina.protocol.AbstractProtocolHandlerFilterChain;
+import org.apache.mina.protocol.ProtocolSession;
+
+class VmPipeFilterChain extends AbstractProtocolHandlerFilterChain {
+
+    VmPipeFilterChain( FilterChainType type )
+    {
+        super(type);
+    }
+
+    protected void doWrite(ProtocolSession session, Object message)
+    {
+        VmPipeSession s = ( VmPipeSession ) session;
+        
+        synchronized( s.lock )
+        {
+            if( s.closed )
+                throw new IllegalStateException( "Session is closed." );
+            s.remoteFilters.messageReceived( null,
+                                             s.remoteSession, message );
+        }
+    }
+}

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

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java Wed Mar 23 09:21:35 2005
@@ -81,10 +81,10 @@
                                 session.bothIdle = idleTime > 0L
                                                    && ( currentTime - session.lastReadTime ) > idleTime;
                                 if( session.bothIdle )
-                                    session.localFilterManager
-                                            .fireSessionIdle(
-                                                              session,
-                                                              IdleStatus.BOTH_IDLE );
+                                    session.localFilters
+                                            .sessionIdle( null,
+                                                          session,
+                                                          IdleStatus.BOTH_IDLE );
                             }
 
                             if( !session.readerIdle )
@@ -94,10 +94,10 @@
                                 session.readerIdle = idleTime > 0L
                                                      && ( currentTime - session.lastReadTime ) > idleTime;
                                 if( session.readerIdle )
-                                    session.localFilterManager
-                                            .fireSessionIdle(
-                                                              session,
-                                                              IdleStatus.READER_IDLE );
+                                    session.localFilters
+                                            .sessionIdle( null,
+                                                          session,
+                                                          IdleStatus.READER_IDLE );
                             }
 
                             if( !session.writerIdle )
@@ -107,10 +107,10 @@
                                 session.writerIdle = idleTime > 0L
                                                      && ( currentTime - session.lastReadTime ) > idleTime;
                                 if( session.writerIdle )
-                                    session.localFilterManager
-                                            .fireSessionIdle(
-                                                              session,
-                                                              IdleStatus.WRITER_IDLE );
+                                    session.localFilters
+                                            .sessionIdle( null,
+                                                          session,
+                                                          IdleStatus.WRITER_IDLE );
                             }
                         }
                     }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java Wed Mar 23 09:21:35 2005
@@ -11,9 +11,8 @@
 import org.apache.mina.protocol.ProtocolDecoder;
 import org.apache.mina.protocol.ProtocolEncoder;
 import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.util.ProtocolHandlerFilterManager;
-import org.apache.mina.util.ProtocolHandlerFilterManager.WriteCommand;
 
 /**
  * TODO Document me.
@@ -23,8 +22,6 @@
  */
 class VmPipeSession implements ProtocolSession
 {
-    private final Object lock;
-
     private final SocketAddress localAddress;
 
     private final SocketAddress remoteAddress;
@@ -33,16 +30,16 @@
 
     private final VmPipeSessionConfig config = new VmPipeSessionConfig();
 
-    private final WriteCommand writeCommand = new WriteCommandImpl();
-
-    final ProtocolHandlerFilterManager localFilterManager;
+    final ProtocolHandlerFilterChain localFilters;
 
-    final ProtocolHandlerFilterManager remoteFilterManager;
+    final ProtocolHandlerFilterChain remoteFilters;
 
     final VmPipeSession remoteSession;
 
     private Object attachment;
 
+    final Object lock;
+
     boolean closed;
 
     long lastReadTime;
@@ -60,22 +57,22 @@
      */
     VmPipeSession( Object lock, SocketAddress localAddress,
                   SocketAddress remoteAddress,
-                  ProtocolHandlerFilterManager localFilterManager,
+                  ProtocolHandlerFilterChain localFilters,
                   ProtocolHandler localHandler,
-                  ProtocolHandlerFilterManager remoteFilterManager,
+                  ProtocolHandlerFilterChain removeFilters,
                   ProtocolHandler remoteHandler )
     {
         this.lock = lock;
         this.localAddress = localAddress;
         this.localHandler = localHandler;
-        this.localFilterManager = localFilterManager;
+        this.localFilters = localFilters;
         this.remoteAddress = remoteAddress;
-        this.remoteFilterManager = remoteFilterManager;
+        this.remoteFilters = removeFilters;
 
         remoteSession = new VmPipeSession( this, remoteHandler );
 
-        remoteFilterManager.fireSessionOpened( remoteSession );
-        localFilterManager.fireSessionOpened( this );
+        removeFilters.sessionOpened( null, remoteSession );
+        localFilters.sessionOpened( null, this );
     }
 
     /**
@@ -86,9 +83,9 @@
         this.lock = remoteSession.lock;
         this.localAddress = remoteSession.remoteAddress;
         this.localHandler = localHandler;
-        this.localFilterManager = remoteSession.remoteFilterManager;
+        this.localFilters = remoteSession.remoteFilters;
         this.remoteAddress = remoteSession.localAddress;
-        this.remoteFilterManager = remoteSession.localFilterManager;
+        this.remoteFilters = remoteSession.localFilters;
 
         this.remoteSession = remoteSession;
     }
@@ -116,8 +113,8 @@
                 return;
 
             closed = remoteSession.closed = true;
-            localFilterManager.fireSessionClosed( this );
-            remoteFilterManager.fireSessionClosed( remoteSession );
+            localFilters.sessionClosed( null, this );
+            remoteFilters.sessionClosed( null, remoteSession );
         }
     }
 
@@ -133,7 +130,7 @@
 
     public void write( Object message )
     {
-        localFilterManager.write( this, writeCommand, message );
+        localFilters.filterWrite( null, this, message );
     }
 
     public TransportType getTransportType()
@@ -200,19 +197,4 @@
 
         throw new IllegalArgumentException( "Illegal statue: " + status );
     }
-
-    private class WriteCommandImpl implements WriteCommand
-    {
-        public void execute( Object message )
-        {
-            synchronized( lock )
-            {
-                if( closed )
-                    throw new IllegalStateException( "Session is closed." );
-                remoteFilterManager.fireMessageReceived( remoteSession,
-                                                         message );
-            }
-        }
-    }
-
 }

Modified: directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java Wed Mar 23 09:21:35 2005
@@ -21,10 +21,11 @@
 import java.io.IOException;
 import java.util.Set;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerFilter;
-import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.io.IoHandlerFilterChain;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
 
 /**
@@ -48,62 +49,20 @@
     void bind( Service service, ProtocolProvider protocolProvider )
             throws IOException;
 
+    
     /**
      * Unbinds the specified service (and its aggregated I/O handler or
      * protocol provider). 
      */
     void unbind( Service service );
 
-    /**
-     * Adds the specified filter to the acceptors of all transport types
-     * in this registry.
-     */
-    void addFilter( int priority, IoHandlerFilter filter );
+    IoHandlerFilterChain newIoFilterChain( TransportType transportType, FilterChainType chainType );
     
-    /**
-     * Adds the specified filter to the acceptors of all transport types
-     * in this registry.
-     */
-    void addFilter( int priority, ProtocolHandlerFilter filter );
+    IoHandlerFilterChain getIoFilterChain( TransportType transportType );
     
-    /**
-     * Adds the specified filter to the acceptor of the specified transport
-     * type with the specified priority.
-     */
-    void addFilter( TransportType transportType, int priority,
-                   IoHandlerFilter filter );
-
-    /**
-     * Adds the specified filter to the acceptor of the specified transport
-     * type with the specified priority.
-     */
-    void addFilter( TransportType transportType, int priority,
-                   ProtocolHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the acceptors of all transport types
-     * in this registry.
-     */
-    void removeFilter( IoHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the acceptors of all transport types
-     * in this registry.
-     */
-    void removeFilter( ProtocolHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the acceptor of the specified
-     * transport type.
-     */
-    void removeFilter( TransportType transportType, IoHandlerFilter filter );
-
-    /**
-     * Removes the specified filter from the acceptor of the specified
-     * transport type.
-     */
-    void removeFilter( TransportType transportType,
-                      ProtocolHandlerFilter filter );
+    ProtocolHandlerFilterChain newProtocolFilterChain( TransportType transportType, FilterChainType chainType );
+    
+    ProtocolHandlerFilterChain getProtocolFilterChain( TransportType transportType );
 
     /**
      * Returns {@link Set} of all services bound in this registry.

Modified: directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java Wed Mar 23 09:21:35 2005
@@ -9,15 +9,16 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.mina.common.FilterChainType;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerFilter;
+import org.apache.mina.io.IoHandlerFilterChain;
 import org.apache.mina.io.datagram.DatagramAcceptor;
 import org.apache.mina.io.filter.IoThreadPoolFilter;
 import org.apache.mina.io.socket.SocketAcceptor;
 import org.apache.mina.protocol.ProtocolAcceptor;
-import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolHandlerFilterChain;
 import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.protocol.filter.ProtocolThreadPoolFilter;
 import org.apache.mina.protocol.io.IoProtocolAcceptor;
@@ -55,11 +56,11 @@
 
     public SimpleServiceRegistry() throws IOException
     {
-        socketIoAcceptor.addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        datagramIoAcceptor.addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        socketProtocolAcceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
-        datagramProtocolAcceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
-        vmPipeAcceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+        socketIoAcceptor.getFilterChain().addFirst( "threadPool", ioThreadPoolFilter );
+        datagramIoAcceptor.getFilterChain().addFirst( "threadPool", ioThreadPoolFilter );
+        socketProtocolAcceptor.getFilterChain().addFirst( "threadPool", protocolThreadPoolFilter );
+        datagramProtocolAcceptor.getFilterChain().addFirst( "threadPool", protocolThreadPoolFilter );
+        vmPipeAcceptor.getFilterChain().addFirst( "threadPool", protocolThreadPoolFilter );
     }
 
     public synchronized void bind( Service service, IoHandler ioHandler )
@@ -101,113 +102,20 @@
         stopThreadPools();
     }
 
-    public synchronized void addFilter( int priority, IoHandlerFilter filter )
-    {
-        boolean s = false;
-        boolean d = false;
-        try
-        {
-            socketIoAcceptor.addFilter( priority, filter );
-            s = true;
-            datagramIoAcceptor.addFilter( priority, filter );
-            d = true;
-        }
-        finally
-        {
-            if( !s || !d )
-            {
-                // rollback
-                if( s )
-                {
-                    socketIoAcceptor.removeFilter( filter );
-                }
-
-                if( d )
-                {
-                    datagramIoAcceptor.removeFilter( filter );
-                }
-            }
-        }
-    }
-
-    public synchronized void addFilter( int priority,
-                                       ProtocolHandlerFilter filter )
-    {
-        boolean s = false;
-        boolean d = false;
-        boolean v = false;
-        try
-        {
-            socketProtocolAcceptor.addFilter( priority, filter );
-            s = true;
-            datagramProtocolAcceptor.addFilter( priority, filter );
-            d = true;
-            vmPipeAcceptor.addFilter( priority, filter );
-            v = true;
-        }
-        finally
-        {
-            if( !s || !d || !v )
-            {
-                // rollback
-                if( s )
-                {
-                    socketProtocolAcceptor.removeFilter( filter );
-                }
-
-                if( d )
-                {
-                    datagramProtocolAcceptor.removeFilter( filter );
-                }
-
-                if( v )
-                {
-                    vmPipeAcceptor.removeFilter( filter );
-                }
-            }
-        }
+    public IoHandlerFilterChain newIoFilterChain(TransportType transportType, FilterChainType chainType) {
+        return findIoAcceptor( transportType ).newFilterChain( chainType );
     }
 
-    public synchronized void addFilter( TransportType transportType,
-                                       int priority, IoHandlerFilter filter )
-    {
-        IoAcceptor acceptor = findIoAcceptor( transportType );
-        acceptor.addFilter( priority, filter );
-    }
-
-    public synchronized void addFilter( TransportType transportType,
-                                       int priority,
-                                       ProtocolHandlerFilter filter )
-    {
-        ProtocolAcceptor acceptor = findProtocolAcceptor( transportType );
-        acceptor.addFilter( priority, filter );
-    }
-
-    public synchronized void removeFilter( IoHandlerFilter filter )
-    {
-        socketIoAcceptor.removeFilter( filter );
-        datagramIoAcceptor.removeFilter( filter );
-    }
-
-    public synchronized void removeFilter( ProtocolHandlerFilter filter )
-    {
-        socketProtocolAcceptor.removeFilter( filter );
-        datagramProtocolAcceptor.removeFilter( filter );
-        vmPipeAcceptor.removeFilter( filter );
+    public IoHandlerFilterChain getIoFilterChain(TransportType transportType) {
+        return findIoAcceptor( transportType ).getFilterChain();
     }
 
-    public synchronized void removeFilter( TransportType transportType,
-                                          IoHandlerFilter filter )
-    {
-        IoAcceptor acceptor = findIoAcceptor( transportType );
-        acceptor.removeFilter( filter );
+    public ProtocolHandlerFilterChain newProtocolFilterChain(TransportType transportType, FilterChainType chainType) {
+        return findProtocolAcceptor( transportType ).newFilterChain( chainType );
     }
 
-    public synchronized void removeFilter( TransportType transportType,
-                                          ProtocolHandlerFilter filter )
-    {
-        ProtocolAcceptor acceptor = findProtocolAcceptor( transportType );
-        acceptor.removeFilter( filter );
+    public ProtocolHandlerFilterChain getProtocolFilterChain(TransportType transportType) {
+        return findProtocolAcceptor( transportType ).getFilterChain();
     }
 
     public synchronized Set getAllServices()

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java Wed Mar 23 09:21:35 2005
@@ -115,8 +115,8 @@
         threadPoolFilter = new IoThreadPoolFilter();
         threadPoolFilter.start();
 
-        acceptor.addFilter( Integer.MAX_VALUE, threadPoolFilter );
-        datagramAcceptor.addFilter( Integer.MAX_VALUE, threadPoolFilter );
+        acceptor.getFilterChain().addFirst( "threadPool", threadPoolFilter );
+        datagramAcceptor.getFilterChain().addFirst( "threadPool", threadPoolFilter );
     }
 
     protected void tearDown() throws Exception

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java Wed Mar 23 09:21:35 2005
@@ -39,7 +39,7 @@
         // Add an SSL filter
         SSLFilter sslFilter = new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
         sslFilter.setDebug( SSLFilter.Debug.ON );
-        acceptor.addFilter( Integer.MAX_VALUE - 1, sslFilter );
+        acceptor.getFilterChain().addLast( "SSL", sslFilter );
         
         // Create a commons-net socket factory
         SSLSocketFactory.setSslEnabled(true);

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?view=diff&r1=158801&r2=158802
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java Wed Mar 23 09:21:35 2005
@@ -28,7 +28,7 @@
     public void testTCP() throws Exception
     {
         IoConnector connector = new SocketConnector();
-        connector.addFilter( Integer.MAX_VALUE, super.threadPoolFilter );
+        connector.getFilterChain().addFirst( "threadPool", super.threadPoolFilter );
         testTCP0( connector );
     }
 
@@ -39,16 +39,16 @@
     {
         // Add an SSL filter to acceptor
         SSLFilter acceptorSSLFilter = new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        acceptor.addFilter( Integer.MAX_VALUE - 1, acceptorSSLFilter );
+        acceptor.getFilterChain().addLast( "SSL", acceptorSSLFilter );
 
         // Create a connector
         IoConnector connector = new SocketConnector();
-        connector.addFilter( Integer.MAX_VALUE, super.threadPoolFilter );
+        connector.getFilterChain().addFirst( "threadPool", super.threadPoolFilter );
         
         // Add an SSL filter to connector
         SSLFilter connectorSSLFilter = new SSLFilter( BogusSSLContextFactory.getInstance( false ) );
         connectorSSLFilter.setDebug( SSLFilter.Debug.ON );
-        connector.addFilter( Integer.MAX_VALUE - 1, connectorSSLFilter );
+        connector.getFilterChain().addLast( "SSL", connectorSSLFilter );
 
         testTCP0( connector );
     }
@@ -109,7 +109,7 @@
     public void testUDP() throws Exception
     {
         IoConnector connector = new DatagramConnector();
-        connector.addFilter( Integer.MAX_VALUE, super.threadPoolFilter );
+        connector.getFilterChain().addFirst( "threadPool", super.threadPoolFilter );
         testTCP0( connector );
     }
     



Mime
View raw message