directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r350169 [6/16] - in /directory/network: branches/chain_refactor/src/java/org/apache/mina/common/ trunk/src/examples/org/apache/mina/examples/echoserver/ trunk/src/examples/org/apache/mina/examples/httpserver/ trunk/src/examples/org/apache/m...
Date Thu, 01 Dec 2005 05:19:07 GMT
Modified: directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java Wed Nov 30 21:17:41 2005
@@ -1,741 +1,799 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.common.support;
-
-import java.util.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.CloseFuture;
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoFilter;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.IoFilter.NextFilter;
-import org.apache.mina.common.IoFilter.WriteRequest;
-import org.apache.mina.util.ByteBufferUtil;
-import org.apache.mina.util.SessionLog;
-
-/**
- * An abstract implementation of {@link IoFilterChain} that provides
- * common operations for developers to extend protocol layer.
- * <p>
- * The only method a developer should implement is
- * {@link #doWrite(IoSession, WriteRequest)}.  This method is invoked
- * when filter chain is evaluated for
- * {@link IoFilter#filterWrite(NextFilter, IoSession, WriteRequest)} and 
- * finally to be written out.
- * 
- * @author The Apache Directory Project
- * @version $Rev$, $Date$
- */
-public abstract class AbstractIoFilterChain implements IoFilterChain
-{
-    private final Object parent;
-
-    private final Map name2entry = new HashMap();
-    private final Map filter2entry = new IdentityHashMap();
-    
-    private final Entry head;
-    private final Entry tail;
-
-    protected AbstractIoFilterChain( Object parent )
-    {
-        if( parent == null )
-        {
-            throw new NullPointerException( "parent" );
-        }
-        
-        this.parent = parent;
-        head = new Entry( null, null, "head", createHeadFilter() );
-        tail = new Entry( head, null, "tail", createTailFilter() );
-        head.nextEntry = tail;
-    }
-    
-    /**
-     * Override this method to create custom head of this filter chain.
-     */
-    protected IoFilter createHeadFilter()
-    {
-        return new IoFilter()
-        {
-            public void init( IoFilterChain parent, NextFilter nextFilter )
-            {
-            }
-            
-            public void destroy( IoFilterChain parent, NextFilter nextFilter )
-            {
-            }
-            
-            public void sessionCreated( NextFilter nextFilter, IoSession session )
-            {
-                nextFilter.sessionCreated( session );
-            }
-
-            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 messageReceived( NextFilter nextFilter, IoSession session,
-                                         Object message )
-            {
-                nextFilter.messageReceived( session, message );
-            }
-
-            public void messageSent( NextFilter nextFilter, IoSession session,
-                                     Object message )
-            {
-                nextFilter.messageSent( session, message );
-            }
-            
-            public void filterWrite( NextFilter nextFilter, IoSession session,
-                                     WriteRequest writeRequest ) throws Exception
-            {
-                if( session.getTransportType().getEnvelopeType().isAssignableFrom( writeRequest.getMessage().getClass() ) )
-                {
-                    doWrite( session, writeRequest );
-                }
-                else
-                {
-                    throw new IllegalStateException(
-                            "Write requests must be transformed to " + 
-                            session.getTransportType().getEnvelopeType() +
-                            ": " + writeRequest );
-                }
-            }
-
-            public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
-            {
-                doClose( session, closeFuture );
-            }
-        };
-    }
-    
-    /**
-     * Override this method to create custom head of this filter chain.
-     */
-    protected IoFilter createTailFilter()
-    {
-        return new IoFilter()
-        {
-            public void init( IoFilterChain parent, NextFilter nextFilter )
-            {
-            }
-            
-            public void destroy( IoFilterChain parent, NextFilter nextFilter )
-            {
-            }
-           
-            public void sessionCreated( NextFilter nextFilter, IoSession session ) throws Exception
-            {
-                session.getHandler().sessionCreated( session );
-            }
-            public void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception
-            {
-                session.getHandler().sessionOpened( session );
-            }
-
-            public void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception
-            {
-                try
-                {
-                    session.getHandler().sessionClosed( session );
-                }
-                finally
-                {
-                    // Remove all filters.
-                    session.getFilterChain().clear();
-                }
-            }
-
-            public void sessionIdle( NextFilter nextFilter, IoSession session,
-                                    IdleStatus status ) throws Exception
-            {
-                session.getHandler().sessionIdle( session, status );
-            }
-
-            public void exceptionCaught( NextFilter nextFilter,
-                                        IoSession session, Throwable cause ) throws Exception
-            {
-                session.getHandler().exceptionCaught( session, cause );
-            }
-
-            public void messageReceived( NextFilter nextFilter, IoSession session,
-                                         Object message ) throws Exception
-            {
-                try
-                {
-                    session.getHandler().messageReceived( session, message );
-                }
-                finally
-                {
-                    ByteBufferUtil.releaseIfPossible( message );
-                }
-            }
-
-            public void messageSent( NextFilter nextFilter, IoSession session,
-                                     Object message ) throws Exception
-            {
-                try
-                {
-                    session.getHandler().messageSent( session, message );
-                }
-                finally
-                {
-                    ByteBufferUtil.releaseIfPossible( message );
-                }
-            }
-
-            public void filterWrite( NextFilter nextFilter,
-                                     IoSession session, WriteRequest writeRequest ) throws Exception
-            {
-                nextFilter.filterWrite( session, writeRequest );
-            }
-
-            public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
-            {
-                nextFilter.filterClose( session, closeFuture );
-            }
-        };
-    }
-    
-    public Object getParent()
-    {
-        return parent;
-    }
-    
-    public IoFilter get( String name )
-    {
-        Entry e = ( Entry ) name2entry.get( name );
-        if ( e == null )
-        {
-            return null;
-        }
-        return e.filter;
-    }
-    
-    public String getName( IoFilter filter )
-    {
-        Entry e = ( Entry ) filter2entry.get( filter );
-        if( e == null )
-        {
-            return null;
-        }
-        
-        return e.name;
-    }
-    
-    public NextFilter getNextFilter( String name )
-    {
-        Entry e = ( Entry ) name2entry.get( name );
-        if ( e == null )
-        {
-            return null;
-        }
-        return e.nextFilter;
-    }
-
-    public NextFilter getNextFilter( IoFilter filter )
-    {
-        Entry e = ( Entry ) filter2entry.get( filter );
-        if( e == null )
-        {
-            return null;
-        }
-        
-        return e.nextFilter;
-    }
-
-    public synchronized void addFirst( String name,
-                                       IoFilter filter ) throws Exception
-    {
-        checkAddable( name );
-        register( head, name, filter );
-    }
-
-    public synchronized void addLast( String name,
-                                      IoFilter filter ) throws Exception
-    {
-        checkAddable( name );
-        register( tail.prevEntry, name, filter );
-    }
-
-    public synchronized void addBefore( String baseName,
-                                        String name,
-                                        IoFilter filter ) throws Exception
-    {
-        Entry baseEntry = checkOldName( baseName );
-        checkAddable( name );
-        register( baseEntry, name, filter );
-    }
-
-    public synchronized void addBefore( IoFilter baseFilter,
-                                        String name,
-                                        IoFilter filter ) throws Exception
-    {
-        Entry baseEntry = getEntry( baseFilter );
-        checkAddable( name );
-        register( baseEntry, name, filter );
-    }
-
-    public synchronized void addAfter( String baseName,
-                                       String name,
-                                       IoFilter filter ) throws Exception
-    {
-        Entry baseEntry = checkOldName( baseName );
-        checkAddable( name );
-        register( baseEntry.prevEntry, name, filter );
-    }
-
-    public synchronized void addAfter( IoFilter baseFilter,
-                                       String name,
-                                       IoFilter filter ) throws Exception
-    {
-        Entry baseEntry = getEntry( baseFilter );
-        checkAddable( name );
-        register( baseEntry.prevEntry, name, filter );
-    }
-
-    public synchronized IoFilter remove( String name ) throws Exception
-    {
-        Entry entry = checkOldName( name );
-        deregister( entry );
-        return entry.filter;
-    }
-
-    public synchronized void remove( IoFilter filter ) throws Exception
-    {
-        Entry entry = getEntry( filter );
-        deregister( entry );
-    }
-
-    public synchronized void clear() throws Exception
-    {
-        Iterator it = new ArrayList( name2entry.keySet() ).iterator();
-        while ( it.hasNext() )
-        {
-            this.remove( ( String ) it.next() );
-        }
-    }
-
-    private void register( Entry prevEntry, String name, IoFilter filter ) throws Exception
-    {
-        Entry newEntry = new Entry( prevEntry, prevEntry.nextEntry, name, filter );
-
-        filter.init( this, newEntry.nextFilter );
-        
-        prevEntry.nextEntry.prevEntry = newEntry;
-        prevEntry.nextEntry = newEntry;
-        name2entry.put( name, newEntry );
-        filter2entry.put( filter, newEntry );
-    }
-    
-    private void deregister( Entry entry ) throws Exception
-    {
-        Entry prevEntry = entry.prevEntry;
-        Entry nextEntry = entry.nextEntry;
-        prevEntry.nextEntry = nextEntry;
-        nextEntry.prevEntry = prevEntry;
-
-        name2entry.remove( entry.name );
-        IoFilter filter = entry.filter;
-        filter2entry.remove( filter );
-        
-        filter.destroy( this, entry.nextFilter );
-    }
-
-    private Entry getEntry( IoFilter filter )
-    {
-        Entry entry = ( Entry ) filter2entry.get( filter );
-        if( entry == null )
-        {
-            throw new IllegalArgumentException(
-                    "The specified filter doesn't belong to this filter chain." );
-        }
-
-        return entry;
-    }
-
-    /**
-     * Throws an exception when the specified filter name is not registered in this chain.
-     *
-     * @return An filter entry with the specified name.
-     */
-    private Entry checkOldName( String baseName )
-    {
-        Entry e = ( Entry ) name2entry.get( baseName );
-        if ( e == null )
-        {
-            throw new IllegalArgumentException( "Unknown filter name:" +
-                    baseName );
-        }
-        return e;
-    }
-
-
-    /**
-     * Checks the specified filter name is already taken and throws an exception if already taken.
-     */
-    private void checkAddable( String name )
-    {
-        if ( name2entry.containsKey( name ) )
-        {
-            throw new IllegalArgumentException( "Other filter is using the same name '" + name + "'" );
-        }
-    }
-
-    public void sessionCreated( IoSession session )
-    {
-        Entry head = this.head;
-        callNextSessionCreated(head, session);
-    }
-
-    private void callNextSessionCreated( Entry entry, IoSession session )
-    {
-        try
-        {
-            entry.filter.sessionCreated( entry.nextFilter, session );
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public void sessionOpened( IoSession session )
-    {
-        Entry head = this.head;
-        callNextSessionOpened(head, session);
-    }
-
-    private void callNextSessionOpened( Entry entry,
-                                        IoSession session)
-    {
-        try
-        {
-            entry.filter.sessionOpened( entry.nextFilter, session );
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public void sessionClosed( IoSession session )
-    {
-        Entry head = this.head;
-        callNextSessionClosed(head, session);
-    }
-
-    private void callNextSessionClosed( Entry entry,
-                                        IoSession session )
-    {
-        try
-        {
-            entry.filter.sessionClosed( entry.nextFilter, session );
-                
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public void sessionIdle( IoSession session, IdleStatus status )
-    {
-        Entry head = this.head;
-        callNextSessionIdle(head, session, status);
-    }
-
-    private void callNextSessionIdle( Entry entry,
-                                      IoSession session,
-                                      IdleStatus status )
-    {
-        try
-        {
-            entry.filter.sessionIdle( entry.nextFilter, session, status );
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public void messageReceived( IoSession session, Object message )
-    {
-        Entry head = this.head;
-        callNextMessageReceived(head, session, message );
-    }
-
-    private void callNextMessageReceived( Entry entry,
-                                          IoSession session,
-                                          Object message )
-    {
-        try
-        {
-            entry.filter.messageReceived( entry.nextFilter, session, message );
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public void messageSent( IoSession session, Object message )
-    {
-        Entry head = this.head;
-        callNextMessageSent(head, session, message);
-    }
-
-    private void callNextMessageSent( Entry entry,
-                                      IoSession session,
-                                      Object message ) 
-    {
-        try
-        {
-            entry.filter.messageSent( entry.nextFilter, session, message );
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public void exceptionCaught( IoSession session, Throwable cause )
-    {
-        Entry head = this.head;
-        callNextExceptionCaught(head, session, cause);
-    }
-
-    private void callNextExceptionCaught( Entry entry,
-                                          IoSession session,
-                                          Throwable cause )
-    {
-        try
-        {
-            entry.filter.exceptionCaught( entry.nextFilter, session, cause );
-        }
-        catch( Throwable e )
-        {
-            SessionLog.warn(
-                    session,
-                    "Unexpected exception from exceptionCaught handler.", e );
-        }
-    }
-    
-    public void filterWrite( IoSession session, WriteRequest writeRequest )
-    {
-        Entry tail = this.tail;
-        callPreviousFilterWrite( tail, session, writeRequest );
-    }
-
-    private void callPreviousFilterWrite( Entry entry,
-                                          IoSession session,
-                                          WriteRequest writeRequest )
-    {
-        try
-        {
-            entry.filter.filterWrite( entry.nextFilter, session, writeRequest );
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public void filterClose( IoSession session, CloseFuture closeFuture )
-    {
-        Entry tail = this.tail;
-        callPreviousFilterClose( tail, session, closeFuture );
-    }
-
-    private void callPreviousFilterClose( Entry entry,
-                                          IoSession session,
-                                          CloseFuture closeFuture )
-    {
-        try
-        {
-            entry.filter.filterClose( entry.nextFilter, session, closeFuture );
-        }
-        catch( Throwable e )
-        {
-            exceptionCaught( session, e );
-        }
-    }
-
-    public List getAll()
-    {
-        List list = new ArrayList();
-        Entry e = head.nextEntry;
-        while( e != tail )
-        {
-            list.add( e.filter );
-            e = e.nextEntry;
-        }
-
-        return list;
-    }
-
-    public List getAllReversed()
-    {
-        List list = new ArrayList();
-        Entry e = tail.prevEntry;
-        while( e != head )
-        {
-            list.add( e.filter );
-            e = e.prevEntry;
-        }
-        return list;
-    }
-    
-    protected void finalize() throws Throwable
-    {
-        try
-        {
-            this.clear();
-        }
-        finally
-        {
-            super.finalize();
-        }
-    }
-
-    protected abstract void doWrite( IoSession session, WriteRequest writeRequest ) throws Exception;
-    
-    protected abstract void doClose( IoSession session, CloseFuture closeFuture ) throws Exception;
-
-    private class Entry
-    {
-        private Entry prevEntry;
-
-        private Entry nextEntry;
-
-        private final String name;
-        
-        private final IoFilter filter;
-
-        private final NextFilter nextFilter;
-        
-        private Entry( Entry prevEntry, Entry nextEntry,
-                       String name, IoFilter 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 sessionCreated( IoSession session )
-                {
-                    Entry nextEntry = Entry.this.nextEntry;
-                    callNextSessionCreated( nextEntry, session );
-                }
-
-                public void sessionOpened( IoSession session )
-                {
-                    Entry nextEntry = Entry.this.nextEntry;
-                    callNextSessionOpened( nextEntry, session );
-                }
-
-                public void sessionClosed( IoSession session )
-                {
-                    Entry nextEntry = Entry.this.nextEntry;
-                    callNextSessionClosed( nextEntry, session );
-                }
-
-                public void sessionIdle( IoSession session, IdleStatus status )
-                {
-                    Entry nextEntry = Entry.this.nextEntry;
-                    callNextSessionIdle( nextEntry, session, status );
-                }
-
-                public void exceptionCaught( IoSession session,
-                                            Throwable cause )
-                {
-                    Entry nextEntry = Entry.this.nextEntry;
-                    callNextExceptionCaught( nextEntry, session, cause );
-                }
-
-                public void messageReceived( IoSession session, Object message )
-                {
-                    Entry nextEntry = Entry.this.nextEntry;
-                    callNextMessageReceived( nextEntry, session, message );
-                }
-
-                public void messageSent( IoSession session, Object message )
-                {
-                    Entry nextEntry = Entry.this.nextEntry;
-                    callNextMessageSent( nextEntry, session, message );
-                }
-                
-                public void filterWrite( IoSession session, WriteRequest writeRequest )
-                {
-                    Entry nextEntry = Entry.this.prevEntry;
-                    callPreviousFilterWrite( nextEntry, session, writeRequest );
-                }
-
-                public void filterClose( IoSession session, CloseFuture closeFuture )
-                {
-                    Entry nextEntry = Entry.this.prevEntry;
-                    callPreviousFilterClose( nextEntry, session, closeFuture );
-                }
-            };
-        }
-        
-        public String getName()
-        {
-            return name;
-        }
-        
-        public IoFilter getFilter()
-        {
-            return filter;
-        }
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFilterLifeCycleException;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.common.IoFilter.WriteRequest;
+import org.apache.mina.util.ByteBufferUtil;
+import org.apache.mina.util.SessionLog;
+
+/**
+ * An abstract implementation of {@link IoFilterChain} that provides
+ * common operations for developers to implement their own transport layer.
+ * <p>
+ * The only method a developer should implement is
+ * {@link #doWrite(IoSession, WriteRequest)}.  This method is invoked
+ * when filter chain is evaluated for
+ * {@link IoFilter#filterWrite(NextFilter, IoSession, WriteRequest)} and 
+ * finally to be written out.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractIoFilterChain implements IoFilterChain
+{
+    private final IoSession session;
+
+    private final Map name2entry = new HashMap();
+    
+    private final EntryImpl head;
+    private final EntryImpl tail;
+
+    protected AbstractIoFilterChain( IoSession session )
+    {
+        if( session == null )
+        {
+            throw new NullPointerException( "session" );
+        }
+        
+        this.session = session;
+        head = new EntryImpl( null, null, "head", createHeadFilter() );
+        tail = new EntryImpl( head, null, "tail", createTailFilter() );
+        head.nextEntry = tail;
+    }
+    
+    /**
+     * Override this method to create custom head of this filter chain.
+     */
+    protected IoFilter createHeadFilter()
+    {
+        return new IoFilterAdapter()
+        {
+            public void sessionCreated( NextFilter nextFilter, IoSession session )
+            {
+                nextFilter.sessionCreated( session );
+            }
+
+            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 messageReceived( NextFilter nextFilter, IoSession session,
+                                         Object message )
+            {
+                nextFilter.messageReceived( session, message );
+            }
+
+            public void messageSent( NextFilter nextFilter, IoSession session,
+                                     Object message )
+            {
+                nextFilter.messageSent( session, message );
+            }
+            
+            public void filterWrite( NextFilter nextFilter, IoSession session,
+                                     WriteRequest writeRequest ) throws Exception
+            {
+                if( session.getTransportType().getEnvelopeType().isAssignableFrom( writeRequest.getMessage().getClass() ) )
+                {
+                    doWrite( session, writeRequest );
+                }
+                else
+                {
+                    throw new IllegalStateException(
+                            "Write requests must be transformed to " + 
+                            session.getTransportType().getEnvelopeType() +
+                            ": " + writeRequest );
+                }
+            }
+
+            public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
+            {
+                doClose( session, closeFuture );
+            }
+        };
+    }
+    
+    /**
+     * Override this method to create custom head of this filter chain.
+     */
+    protected IoFilter createTailFilter()
+    {
+        return new IoFilterAdapter()
+        {
+            public void sessionCreated( NextFilter nextFilter, IoSession session ) throws Exception
+            {
+                session.getHandler().sessionCreated( session );
+            }
+            public void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception
+            {
+                session.getHandler().sessionOpened( session );
+            }
+
+            public void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception
+            {
+                try
+                {
+                    session.getHandler().sessionClosed( session );
+                }
+                finally
+                {
+                    // Remove all filters.
+                    session.getFilterChain().clear();
+                }
+            }
+
+            public void sessionIdle( NextFilter nextFilter, IoSession session,
+                                    IdleStatus status ) throws Exception
+            {
+                session.getHandler().sessionIdle( session, status );
+            }
+
+            public void exceptionCaught( NextFilter nextFilter,
+                                        IoSession session, Throwable cause ) throws Exception
+            {
+                session.getHandler().exceptionCaught( session, cause );
+            }
+
+            public void messageReceived( NextFilter nextFilter, IoSession session,
+                                         Object message ) throws Exception
+            {
+                try
+                {
+                    session.getHandler().messageReceived( session, message );
+                }
+                finally
+                {
+                    ByteBufferUtil.releaseIfPossible( message );
+                }
+            }
+
+            public void messageSent( NextFilter nextFilter, IoSession session,
+                                     Object message ) throws Exception
+            {
+                try
+                {
+                    session.getHandler().messageSent( session, message );
+                }
+                finally
+                {
+                    ByteBufferUtil.releaseIfPossible( message );
+                }
+            }
+
+            public void filterWrite( NextFilter nextFilter,
+                                     IoSession session, WriteRequest writeRequest ) throws Exception
+            {
+                nextFilter.filterWrite( session, writeRequest );
+            }
+
+            public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
+            {
+                nextFilter.filterClose( session, closeFuture );
+            }
+        };
+    }
+    
+    public IoSession getSession()
+    {
+        return session;
+    }
+    
+    public Entry getEntry( String name )
+    {
+        Entry e = ( Entry ) name2entry.get( name );
+        if ( e == null )
+        {
+            return null;
+        }
+        return e;
+    }
+    
+    public IoFilter get( String name )
+    {
+        Entry e = getEntry( name );
+        if( e == null )
+        {
+            return null;
+        }
+        
+        return e.getFilter();
+    }
+    
+    public NextFilter getNextFilter( String name )
+    {
+        Entry e = getEntry( name );
+        if( e == null )
+        {
+            return null;
+        }
+        
+        return e.getNextFilter();
+    }
+    
+    public synchronized void addFirst( String name,
+                                       IoFilter filter )
+    {
+        checkAddable( name );
+        register( head, name, filter );
+    }
+
+    public synchronized void addLast( String name,
+                                      IoFilter filter )
+    {
+        checkAddable( name );
+        register( tail.prevEntry, name, filter );
+    }
+
+    public synchronized void addBefore( String baseName,
+                                        String name,
+                                        IoFilter filter )
+    {
+        EntryImpl baseEntry = checkOldName( baseName );
+        checkAddable( name );
+        register( baseEntry.prevEntry, name, filter );
+    }
+
+    public synchronized void addAfter( String baseName,
+                                       String name,
+                                       IoFilter filter )
+    {
+        EntryImpl baseEntry = checkOldName( baseName );
+        checkAddable( name );
+        register( baseEntry, name, filter );
+    }
+
+    public synchronized IoFilter remove( String name )
+    {
+        EntryImpl entry = checkOldName( name );
+        deregister( entry );
+        return entry.getFilter();
+    }
+
+    public synchronized void clear() throws Exception
+    {
+        Iterator it = new ArrayList( name2entry.keySet() ).iterator();
+        while ( it.hasNext() )
+        {
+            this.remove( ( String ) it.next() );
+        }
+    }
+
+    private void register( EntryImpl prevEntry, String name, IoFilter filter )
+    {
+        EntryImpl newEntry = new EntryImpl( prevEntry, prevEntry.nextEntry, name, filter );
+
+        IoFilterLifeCycleManager lifeCycleManager = IoFilterLifeCycleManager.getInstance();
+        
+        synchronized( lifeCycleManager )
+        {
+            lifeCycleManager.callInitIfNecessary( filter );
+
+            try
+            {
+                lifeCycleManager.callOnPreAdd( this, name, filter, newEntry.getNextFilter() );
+            }
+            finally
+            {
+                lifeCycleManager.callDestroyIfNecessary( filter );
+            }
+
+            prevEntry.nextEntry.prevEntry = newEntry;
+            prevEntry.nextEntry = newEntry;
+            name2entry.put( name, newEntry );
+
+            try
+            {
+                lifeCycleManager.callOnPostAdd( this, name, filter, newEntry.getNextFilter() );
+            }
+            catch( IoFilterLifeCycleException e )
+            {
+                deregister0( newEntry );
+                throw e;
+            }
+            finally
+            {
+                lifeCycleManager.callDestroyIfNecessary( filter );
+            }
+        }
+    }
+    
+    private void deregister( EntryImpl entry )
+    {
+        IoFilter filter = entry.getFilter();
+        IoFilterLifeCycleManager lifeCycleManager = IoFilterLifeCycleManager.getInstance();
+        
+        lifeCycleManager.callOnPreRemove( this, entry.getName(), filter, entry.getNextFilter() );
+        
+        deregister0( entry );
+
+        try
+        {
+            lifeCycleManager.callOnPostRemove(
+                    this, entry.getName(), filter, entry.getNextFilter() );
+        }
+        finally
+        {
+            lifeCycleManager.callDestroyIfNecessary( filter );
+        }
+    }
+
+    private void deregister0( EntryImpl entry )
+    {
+        EntryImpl prevEntry = entry.prevEntry;
+        EntryImpl nextEntry = entry.nextEntry;
+        prevEntry.nextEntry = nextEntry;
+        nextEntry.prevEntry = prevEntry;
+
+        name2entry.remove( entry.name );
+    }
+
+    /**
+     * Throws an exception when the specified filter name is not registered in this chain.
+     *
+     * @return An filter entry with the specified name.
+     */
+    private EntryImpl checkOldName( String baseName )
+    {
+        EntryImpl e = ( EntryImpl ) name2entry.get( baseName );
+        if ( e == null )
+        {
+            throw new IllegalArgumentException( "Unknown filter name:" +
+                    baseName );
+        }
+        return e;
+    }
+
+
+    /**
+     * Checks the specified filter name is already taken and throws an exception if already taken.
+     */
+    private void checkAddable( String name )
+    {
+        if ( name2entry.containsKey( name ) )
+        {
+            throw new IllegalArgumentException( "Other filter is using the same name '" + name + "'" );
+        }
+    }
+
+    public void sessionCreated( IoSession session )
+    {
+        Entry head = this.head;
+        callNextSessionCreated(head, session);
+    }
+
+    private void callNextSessionCreated( Entry entry, IoSession session )
+    {
+        try
+        {
+            entry.getFilter().sessionCreated( entry.getNextFilter(), session );
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public void sessionOpened( IoSession session )
+    {
+        Entry head = this.head;
+        callNextSessionOpened(head, session);
+    }
+
+    private void callNextSessionOpened( Entry entry,
+                                        IoSession session)
+    {
+        try
+        {
+            entry.getFilter().sessionOpened( entry.getNextFilter(), session );
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public void sessionClosed( IoSession session )
+    {
+        Entry head = this.head;
+        callNextSessionClosed(head, session);
+    }
+
+    private void callNextSessionClosed( Entry entry,
+                                        IoSession session )
+    {
+        try
+        {
+            entry.getFilter().sessionClosed( entry.getNextFilter(), session );
+                
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public void sessionIdle( IoSession session, IdleStatus status )
+    {
+        Entry head = this.head;
+        callNextSessionIdle(head, session, status);
+    }
+
+    private void callNextSessionIdle( Entry entry,
+                                      IoSession session,
+                                      IdleStatus status )
+    {
+        try
+        {
+            entry.getFilter().sessionIdle( entry.getNextFilter(), session, status );
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public void messageReceived( IoSession session, Object message )
+    {
+        Entry head = this.head;
+        callNextMessageReceived(head, session, message );
+    }
+
+    private void callNextMessageReceived( Entry entry,
+                                          IoSession session,
+                                          Object message )
+    {
+        try
+        {
+            entry.getFilter().messageReceived( entry.getNextFilter(), session, message );
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public void messageSent( IoSession session, Object message )
+    {
+        Entry head = this.head;
+        callNextMessageSent(head, session, message);
+    }
+
+    private void callNextMessageSent( Entry entry,
+                                      IoSession session,
+                                      Object message ) 
+    {
+        try
+        {
+            entry.getFilter().messageSent( entry.getNextFilter(), session, message );
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public void exceptionCaught( IoSession session, Throwable cause )
+    {
+        Entry head = this.head;
+        callNextExceptionCaught(head, session, cause);
+    }
+
+    private void callNextExceptionCaught( Entry entry,
+                                          IoSession session,
+                                          Throwable cause )
+    {
+        try
+        {
+            entry.getFilter().exceptionCaught( entry.getNextFilter(), session, cause );
+        }
+        catch( Throwable e )
+        {
+            SessionLog.warn(
+                    session,
+                    "Unexpected exception from exceptionCaught handler.", e );
+        }
+    }
+    
+    public void filterWrite( IoSession session, WriteRequest writeRequest )
+    {
+        Entry tail = this.tail;
+        callPreviousFilterWrite( tail, session, writeRequest );
+    }
+
+    private void callPreviousFilterWrite( Entry entry,
+                                          IoSession session,
+                                          WriteRequest writeRequest )
+    {
+        try
+        {
+            entry.getFilter().filterWrite( entry.getNextFilter(), session, writeRequest );
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public void filterClose( IoSession session, CloseFuture closeFuture )
+    {
+        Entry tail = this.tail;
+        callPreviousFilterClose( tail, session, closeFuture );
+    }
+
+    private void callPreviousFilterClose( Entry entry,
+                                          IoSession session,
+                                          CloseFuture closeFuture )
+    {
+        try
+        {
+            entry.getFilter().filterClose( entry.getNextFilter(), session, closeFuture );
+        }
+        catch( Throwable e )
+        {
+            exceptionCaught( session, e );
+        }
+    }
+
+    public List getAll()
+    {
+        List list = new ArrayList();
+        EntryImpl e = head.nextEntry;
+        while( e != tail )
+        {
+            list.add( e );
+            e = e.nextEntry;
+        }
+
+        return list;
+    }
+
+    public List getAllReversed()
+    {
+        List list = new ArrayList();
+        EntryImpl e = tail.prevEntry;
+        while( e != head )
+        {
+            list.add( e );
+            e = e.prevEntry;
+        }
+        return list;
+    }
+    
+    public boolean contains( String name )
+    {
+        return getEntry( name ) != null;
+    }
+
+    public boolean contains( IoFilter filter )
+    {
+        EntryImpl e = head.nextEntry;
+        while( e != tail )
+        {
+            if( e.getFilter() == filter )
+            {
+                return true;
+            }
+            e = e.nextEntry;
+        }
+        return false;
+    }
+
+    public boolean contains( Class filterType )
+    {
+        EntryImpl e = head.nextEntry;
+        while( e != tail )
+        {
+            if( filterType.isAssignableFrom( e.getFilter().getClass() ) )
+            {
+                return true;
+            }
+            e = e.nextEntry;
+        }
+        return false;
+    }
+
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "{ " );
+        
+        boolean empty = true;
+        
+        EntryImpl e = head.nextEntry;
+        while( e != tail )
+        {
+            if( !empty )
+            {
+                buf.append( ", " );
+            }
+            else
+            {
+                empty = false;
+            }
+            
+            buf.append( '(' );
+            buf.append( e.getName() );
+            buf.append( ':' );
+            buf.append( e.getFilter() );
+            buf.append( ')' );
+
+            e = e.nextEntry;
+        }
+
+        if( empty )
+        {
+            buf.append( "empty" );
+        }
+        
+        buf.append( " }" );
+        
+        return buf.toString();
+    }
+
+    
+    protected void finalize() throws Throwable
+    {
+        try
+        {
+            this.clear();
+        }
+        finally
+        {
+            super.finalize();
+        }
+    }
+
+    protected abstract void doWrite( IoSession session, WriteRequest writeRequest ) throws Exception;
+    
+    protected abstract void doClose( IoSession session, CloseFuture closeFuture ) throws Exception;
+
+    private class EntryImpl implements Entry
+    {
+        private EntryImpl prevEntry;
+
+        private EntryImpl nextEntry;
+
+        private final String name;
+        
+        private final IoFilter filter;
+
+        private final NextFilter nextFilter;
+        
+        private EntryImpl( EntryImpl prevEntry, EntryImpl nextEntry,
+                       String name, IoFilter 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 sessionCreated( IoSession session )
+                {
+                    Entry nextEntry = EntryImpl.this.nextEntry;
+                    callNextSessionCreated( nextEntry, session );
+                }
+
+                public void sessionOpened( IoSession session )
+                {
+                    Entry nextEntry = EntryImpl.this.nextEntry;
+                    callNextSessionOpened( nextEntry, session );
+                }
+
+                public void sessionClosed( IoSession session )
+                {
+                    Entry nextEntry = EntryImpl.this.nextEntry;
+                    callNextSessionClosed( nextEntry, session );
+                }
+
+                public void sessionIdle( IoSession session, IdleStatus status )
+                {
+                    Entry nextEntry = EntryImpl.this.nextEntry;
+                    callNextSessionIdle( nextEntry, session, status );
+                }
+
+                public void exceptionCaught( IoSession session,
+                                            Throwable cause )
+                {
+                    Entry nextEntry = EntryImpl.this.nextEntry;
+                    callNextExceptionCaught( nextEntry, session, cause );
+                }
+
+                public void messageReceived( IoSession session, Object message )
+                {
+                    Entry nextEntry = EntryImpl.this.nextEntry;
+                    callNextMessageReceived( nextEntry, session, message );
+                }
+
+                public void messageSent( IoSession session, Object message )
+                {
+                    Entry nextEntry = EntryImpl.this.nextEntry;
+                    callNextMessageSent( nextEntry, session, message );
+                }
+                
+                public void filterWrite( IoSession session, WriteRequest writeRequest )
+                {
+                    Entry nextEntry = EntryImpl.this.prevEntry;
+                    callPreviousFilterWrite( nextEntry, session, writeRequest );
+                }
+
+                public void filterClose( IoSession session, CloseFuture closeFuture )
+                {
+                    Entry nextEntry = EntryImpl.this.prevEntry;
+                    callPreviousFilterClose( nextEntry, session, closeFuture );
+                }
+            };
+        }
+        
+        public String getName()
+        {
+            return name;
+        }
+        
+        public IoFilter getFilter()
+        {
+            return filter;
+        }
+        
+        public NextFilter getNextFilter()
+        {
+            return nextFilter;
+        }
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoAcceptor.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoAcceptor.java Wed Nov 30 21:17:41 2005
@@ -1,57 +1,65 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.common.support;
-
-import java.net.SocketAddress;
-
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoSession;
-
-/**
- * A base implementation of {@link IoAcceptor}.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public abstract class BaseIoAcceptor extends BaseIoSessionManager implements IoAcceptor
-{
-    /* TODO: DIRMINA-93
-    private boolean disconnectClientsOnUnbind = true;
-    */
-    
-    protected BaseIoAcceptor()
-    {
-    }
-    
-    /* TODO: DIRMINA-93
-    public boolean isDisconnectClientsOnUnbind()
-    {
-        return disconnectClientsOnUnbind;
-    }
-
-    public void setDisconnectClientsOnUnbind( boolean disconnectClientsOnUnbind )
-    {
-        this.disconnectClientsOnUnbind = disconnectClientsOnUnbind;
-    }
-    */
-    public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
-    {
-        throw new UnsupportedOperationException();
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A base implementation of {@link IoAcceptor}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseIoAcceptor extends BaseIoSessionManager implements IoAcceptor
+{
+    /* TODO: DIRMINA-93
+    private boolean disconnectClientsOnUnbind = true;
+    */
+    
+    protected BaseIoAcceptor()
+    {
+    }
+    
+    public void bind( SocketAddress address, IoHandler handler ) throws IOException
+    {
+        this.bind( address, handler, IoFilterChainBuilder.NOOP );
+    }
+
+    /* TODO: DIRMINA-93
+    public boolean isDisconnectClientsOnUnbind()
+    {
+        return disconnectClientsOnUnbind;
+    }
+
+    public void setDisconnectClientsOnUnbind( boolean disconnectClientsOnUnbind )
+    {
+        this.disconnectClientsOnUnbind = disconnectClientsOnUnbind;
+    }
+    */
+    public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
+    {
+        throw new UnsupportedOperationException();
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoConnector.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoConnector.java Wed Nov 30 21:17:41 2005
@@ -1,55 +1,70 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.common.support;
-
-import org.apache.mina.common.IoConnector;
-
-/**
- * A base implementation of {@link IoConnector}.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public abstract class BaseIoConnector extends BaseIoSessionManager implements IoConnector
-{
-    private int defaultConnectTimeout = 60; // 1 minute
-
-    protected BaseIoConnector()
-    {
-    }
-    
-    public int getConnectTimeout()
-    {
-        return defaultConnectTimeout;
-    }
-
-    public long getConnectTimeoutMillis()
-    {
-        return defaultConnectTimeout * 1000L;
-    }
-
-    public void setConnectTimeout( int defaultConnectTimeout )
-    {
-        if( defaultConnectTimeout <= 0 )
-        {
-            throw new IllegalArgumentException( "defaultConnectTimeout: " + defaultConnectTimeout );
-        }
-        this.defaultConnectTimeout = defaultConnectTimeout;
-    }    
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import java.net.SocketAddress;
+
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
+
+/**
+ * A base implementation of {@link IoConnector}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseIoConnector extends BaseIoSessionManager implements IoConnector
+{
+    private int defaultConnectTimeout = 60; // 1 minute
+
+    protected BaseIoConnector()
+    {
+    }
+    
+    public ConnectFuture connect( SocketAddress address, IoHandler handler )
+    {
+        return connect( address, handler, IoFilterChainBuilder.NOOP );
+    }
+
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler handler )
+    {
+        return connect( address, localAddress, handler, IoFilterChainBuilder.NOOP );
+    }
+
+    public int getConnectTimeout()
+    {
+        return defaultConnectTimeout;
+    }
+
+    public long getConnectTimeoutMillis()
+    {
+        return defaultConnectTimeout * 1000L;
+    }
+
+    public void setConnectTimeout( int defaultConnectTimeout )
+    {
+        if( defaultConnectTimeout <= 0 )
+        {
+            throw new IllegalArgumentException( "defaultConnectTimeout: " + defaultConnectTimeout );
+        }
+        this.defaultConnectTimeout = defaultConnectTimeout;
+    }    
+}

Modified: directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java Wed Nov 30 21:17:41 2005
@@ -1,433 +1,433 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.common.support;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.mina.common.CloseFuture;
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.IoSessionManager;
-import org.apache.mina.common.TrafficMask;
-import org.apache.mina.common.WriteFuture;
-import org.apache.mina.common.IoFilter.WriteRequest;
-
-/**
- * Base implementation of {@link IoSession}.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public abstract class BaseIoSession implements IoSession
-{
-    private final Map attributes = new HashMap();
-    private final long creationTime;
-
-    /**
-     * A lock object which is acquired when {@link IoSession#close()},
-     * {@link #isClosing()}, or {@link IoSession#write(Object)} is invoked.
-     */
-    protected final Object ioLock = new Object();
-    
-    /** 
-     * A future that will be set 'closed' when the connection is closed.
-     */
-    private final CloseFuture closeFuture = new CloseFuture();
-    private boolean closing;
-
-    // Configuration variables
-    private int idleTimeForRead;
-    private int idleTimeForWrite;
-    private int idleTimeForBoth;
-    private int writeTimeout;
-    private TrafficMask trafficMask = TrafficMask.ALL; 
-    
-    // Status variables
-    private long readBytes;
-    private long writtenBytes;
-    private long writtenWriteRequests;
-    
-    private long lastReadTime;
-    private long lastWriteTime;
-
-    private int idleCountForBoth;
-    private int idleCountForRead;
-    private int idleCountForWrite;
-    
-    private long lastIdleTimeForBoth;
-    private long lastIdleTimeForRead;
-    private long lastIdleTimeForWrite;
-
-
-    protected BaseIoSession()
-    {
-        creationTime = lastReadTime = lastWriteTime =
-            lastIdleTimeForBoth = lastIdleTimeForRead = lastIdleTimeForWrite =
-                System.currentTimeMillis();
-    }
-    
-    public boolean isConnected()
-    {
-        return !closeFuture.isClosed();
-    }
-    
-    public boolean isClosing()
-    {
-        synchronized( ioLock )
-        {
-            return closing;
-        }
-    }
-    
-    public CloseFuture getCloseFuture()
-    {
-        return closeFuture;
-    }
-    
-    public CloseFuture close()
-    {
-        synchronized( ioLock )
-        {
-            if( !closing )
-            {
-                closing = true;
-                close0( closeFuture );
-            }
-        }
-
-        return closeFuture;
-
-    }
-
-    /**
-     * Implement this method to perform real close operation.
-     * By default, this method is implemented to set the future to
-     * 'closed' immediately.
-     * 
-     * @param closeFuture a future that should be set to 'closed'
-     */
-    protected void close0( CloseFuture closeFuture )
-    {
-        closeFuture.setClosed();
-    }
-    
-    public WriteFuture write( Object message )
-    {
-        WriteFuture future = new WriteFuture();
-        synchronized( ioLock )
-        {
-            if( isClosing() )
-            {
-                future.setWritten( false );
-            }
-            else
-            {
-                write0( new WriteRequest( message, future ) );
-            }
-        }
-        return future;
-    }
-    
-    /**
-     * Implement this method to perform real write operation with
-     * the specified <code>writeRequest</code>.
-     * 
-     * By default, this method is implemented to set the future to
-     * 'not written' immediately.
-     */
-    protected void write0( WriteRequest writeRequest )
-    {
-        writeRequest.getFuture().setWritten( false );
-    }
-
-    
-    public Object getAttachment()
-    {
-        return attributes.get( "" );
-    }
-
-    public Object setAttachment( Object attachment )
-    {
-        synchronized( attributes )
-        {
-            return attributes.put( "", attachment );
-        }
-    }
-
-    public Object getAttribute( String key )
-    {
-        return attributes.get( key );
-    }
-
-    public Object setAttribute( String key, Object value )
-    {
-        synchronized( attributes )
-        {
-            return attributes.put( key, value );
-        }
-    }
-    
-    public Object setAttribute( String key )
-    {
-        return setAttribute( key, Boolean.TRUE );
-    }
-    
-    public Object removeAttribute( String key )
-    {
-        synchronized( attributes )
-        {
-            return attributes.remove( key );
-        }
-    }
-    
-    public boolean containsAttribute( String key )
-    {
-        return getAttribute( key ) != null;
-    }
-
-    public Set getAttributeKeys() {
-        synchronized( attributes )
-        {
-            return attributes.keySet();
-        }
-    }
-    
-    public int getIdleTime( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            return idleTimeForBoth;
-
-        if( status == IdleStatus.READER_IDLE )
-            return idleTimeForRead;
-
-        if( status == IdleStatus.WRITER_IDLE )
-            return idleTimeForWrite;
-
-        throw new IllegalArgumentException( "Unknown idle status: " + status );
-    }
-
-    public long getIdleTimeInMillis( IdleStatus status )
-    {
-        return getIdleTime( status ) * 1000L;
-    }
-
-    public void setIdleTime( IdleStatus status, int idleTime )
-    {
-        if( idleTime < 0 )
-            throw new IllegalArgumentException( "Illegal idle time: "
-                                                + idleTime );
-
-        if( status == IdleStatus.BOTH_IDLE )
-            idleTimeForBoth = idleTime;
-        else if( status == IdleStatus.READER_IDLE )
-            idleTimeForRead = idleTime;
-        else if( status == IdleStatus.WRITER_IDLE )
-            idleTimeForWrite = idleTime;
-        else
-            throw new IllegalArgumentException( "Unknown idle status: "
-                                                + status );
-    }
-
-    public int getWriteTimeout()
-    {
-        return writeTimeout;
-    }
-
-    public long getWriteTimeoutInMillis()
-    {
-        return writeTimeout * 1000L;
-    }
-
-    public void setWriteTimeout( int writeTimeout )
-    {
-        if( writeTimeout < 0 )
-            throw new IllegalArgumentException( "Illegal write timeout: "
-                                                + writeTimeout );
-        this.writeTimeout = writeTimeout;
-    }
-
-    public TrafficMask getTrafficMask()
-    {
-        return trafficMask;
-    }
-    
-    public void setTrafficMask( TrafficMask trafficMask )
-    {
-        if( trafficMask == null )
-        {
-            throw new NullPointerException( "trafficMask" );
-        }
-        
-        if( this.trafficMask == trafficMask )
-        {
-            return;
-        }
-        
-        this.trafficMask = trafficMask;
-        updateTrafficMask();
-    }
-    
-    public void suspendRead()
-    {
-        setTrafficMask( getTrafficMask().and( TrafficMask.READ.not() ) );
-    }
-
-    public void suspendWrite()
-    {
-        setTrafficMask( getTrafficMask().and( TrafficMask.WRITE.not() ) );
-    }
-
-    public void resumeRead()
-    {
-        setTrafficMask( getTrafficMask().or( TrafficMask.READ ) );
-    }
-
-    public void resumeWrite()
-    {
-        setTrafficMask( getTrafficMask().or( TrafficMask.WRITE ) );
-    }
-
-    /**
-     * Signals the {@link IoSessionManager} that the {@link TrafficMask} of this
-     * session has been changed.
-     */
-    protected abstract void updateTrafficMask();
-    
-    public long getReadBytes()
-    {
-        return readBytes;
-    }
-
-    public long getWrittenBytes()
-    {
-        return writtenBytes;
-    }
-    
-    public long getWrittenWriteRequests()
-    {
-        return writtenWriteRequests;
-    }
-    
-    public void increaseReadBytes( int increment )
-    {
-        readBytes += increment;
-        lastReadTime = System.currentTimeMillis();
-        idleCountForBoth = 0;
-        idleCountForWrite = 0;
-    }
-
-    public void increaseWrittenBytes( int increment )
-    {
-        writtenBytes += increment;
-        lastWriteTime = System.currentTimeMillis();
-        idleCountForBoth = 0;
-        idleCountForWrite = 0;
-    }
-    
-    public void increaseWrittenWriteRequests()
-    {
-        writtenWriteRequests ++;
-    }
-    
-    public long getCreationTime()
-    {
-        return creationTime;
-    }
-
-    public long getLastIoTime()
-    {
-        return Math.max( lastReadTime, lastWriteTime );
-    }
-
-    public long getLastReadTime()
-    {
-        return lastReadTime;
-    }
-
-    public long getLastWriteTime()
-    {
-        return lastWriteTime;
-    }
-
-    public boolean isIdle( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            return idleCountForBoth > 0;
-
-        if( status == IdleStatus.READER_IDLE )
-            return idleCountForRead > 0;
-
-        if( status == IdleStatus.WRITER_IDLE )
-            return idleCountForWrite > 0;
-
-        throw new IllegalArgumentException( "Unknown idle status: " + status );
-    }
-
-    public int getIdleCount( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            return idleCountForBoth;
-
-        if( status == IdleStatus.READER_IDLE )
-            return idleCountForRead;
-
-        if( status == IdleStatus.WRITER_IDLE )
-            return idleCountForWrite;
-
-        throw new IllegalArgumentException( "Unknown idle status: " + status );
-    }
-    
-    public long getLastIdleTime( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            return lastIdleTimeForBoth;
-
-        if( status == IdleStatus.READER_IDLE )
-            return lastIdleTimeForRead;
-
-        if( status == IdleStatus.WRITER_IDLE )
-            return lastIdleTimeForWrite;
-
-        throw new IllegalArgumentException( "Unknown idle status: " + status );
-    }
-
-    public void increaseIdleCount( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-        {
-            idleCountForBoth ++;
-            lastIdleTimeForBoth = System.currentTimeMillis();
-        }
-        else if( status == IdleStatus.READER_IDLE )
-        {
-            idleCountForRead ++;
-            lastIdleTimeForRead = System.currentTimeMillis();
-        }
-        else if( status == IdleStatus.WRITER_IDLE )
-        {
-            idleCountForWrite ++;
-            lastIdleTimeForWrite = System.currentTimeMillis();
-        }
-        else
-            throw new IllegalArgumentException( "Unknown idle status: "
-                                                + status );
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionManager;
+import org.apache.mina.common.TrafficMask;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.IoFilter.WriteRequest;
+
+/**
+ * Base implementation of {@link IoSession}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseIoSession implements IoSession
+{
+    private final Map attributes = new HashMap();
+    private final long creationTime;
+
+    /**
+     * A lock object which is acquired when {@link IoSession#close()},
+     * {@link #isClosing()}, or {@link IoSession#write(Object)} is invoked.
+     */
+    protected final Object ioLock = new Object();
+    
+    /** 
+     * A future that will be set 'closed' when the connection is closed.
+     */
+    private final CloseFuture closeFuture = new CloseFuture();
+    private boolean closing;
+
+    // Configuration variables
+    private int idleTimeForRead;
+    private int idleTimeForWrite;
+    private int idleTimeForBoth;
+    private int writeTimeout;
+    private TrafficMask trafficMask = TrafficMask.ALL; 
+    
+    // Status variables
+    private long readBytes;
+    private long writtenBytes;
+    private long writtenWriteRequests;
+    
+    private long lastReadTime;
+    private long lastWriteTime;
+
+    private int idleCountForBoth;
+    private int idleCountForRead;
+    private int idleCountForWrite;
+    
+    private long lastIdleTimeForBoth;
+    private long lastIdleTimeForRead;
+    private long lastIdleTimeForWrite;
+
+
+    protected BaseIoSession()
+    {
+        creationTime = lastReadTime = lastWriteTime =
+            lastIdleTimeForBoth = lastIdleTimeForRead = lastIdleTimeForWrite =
+                System.currentTimeMillis();
+    }
+    
+    public boolean isConnected()
+    {
+        return !closeFuture.isClosed();
+    }
+    
+    public boolean isClosing()
+    {
+        synchronized( ioLock )
+        {
+            return closing;
+        }
+    }
+    
+    public CloseFuture getCloseFuture()
+    {
+        return closeFuture;
+    }
+    
+    public CloseFuture close()
+    {
+        synchronized( ioLock )
+        {
+            if( !closing )
+            {
+                closing = true;
+                close0( closeFuture );
+            }
+        }
+
+        return closeFuture;
+
+    }
+
+    /**
+     * Implement this method to perform real close operation.
+     * By default, this method is implemented to set the future to
+     * 'closed' immediately.
+     * 
+     * @param closeFuture a future that should be set to 'closed'
+     */
+    protected void close0( CloseFuture closeFuture )
+    {
+        closeFuture.setClosed();
+    }
+    
+    public WriteFuture write( Object message )
+    {
+        WriteFuture future = new WriteFuture();
+        synchronized( ioLock )
+        {
+            if( isClosing() )
+            {
+                future.setWritten( false );
+            }
+            else
+            {
+                write0( new WriteRequest( message, future ) );
+            }
+        }
+        return future;
+    }
+    
+    /**
+     * Implement this method to perform real write operation with
+     * the specified <code>writeRequest</code>.
+     * 
+     * By default, this method is implemented to set the future to
+     * 'not written' immediately.
+     */
+    protected void write0( WriteRequest writeRequest )
+    {
+        writeRequest.getFuture().setWritten( false );
+    }
+
+    
+    public Object getAttachment()
+    {
+        return attributes.get( "" );
+    }
+
+    public Object setAttachment( Object attachment )
+    {
+        synchronized( attributes )
+        {
+            return attributes.put( "", attachment );
+        }
+    }
+
+    public Object getAttribute( String key )
+    {
+        return attributes.get( key );
+    }
+
+    public Object setAttribute( String key, Object value )
+    {
+        synchronized( attributes )
+        {
+            return attributes.put( key, value );
+        }
+    }
+    
+    public Object setAttribute( String key )
+    {
+        return setAttribute( key, Boolean.TRUE );
+    }
+    
+    public Object removeAttribute( String key )
+    {
+        synchronized( attributes )
+        {
+            return attributes.remove( key );
+        }
+    }
+    
+    public boolean containsAttribute( String key )
+    {
+        return getAttribute( key ) != null;
+    }
+
+    public Set getAttributeKeys() {
+        synchronized( attributes )
+        {
+            return attributes.keySet();
+        }
+    }
+    
+    public int getIdleTime( IdleStatus status )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+            return idleTimeForBoth;
+
+        if( status == IdleStatus.READER_IDLE )
+            return idleTimeForRead;
+
+        if( status == IdleStatus.WRITER_IDLE )
+            return idleTimeForWrite;
+
+        throw new IllegalArgumentException( "Unknown idle status: " + status );
+    }
+
+    public long getIdleTimeInMillis( IdleStatus status )
+    {
+        return getIdleTime( status ) * 1000L;
+    }
+
+    public void setIdleTime( IdleStatus status, int idleTime )
+    {
+        if( idleTime < 0 )
+            throw new IllegalArgumentException( "Illegal idle time: "
+                                                + idleTime );
+
+        if( status == IdleStatus.BOTH_IDLE )
+            idleTimeForBoth = idleTime;
+        else if( status == IdleStatus.READER_IDLE )
+            idleTimeForRead = idleTime;
+        else if( status == IdleStatus.WRITER_IDLE )
+            idleTimeForWrite = idleTime;
+        else
+            throw new IllegalArgumentException( "Unknown idle status: "
+                                                + status );
+    }
+
+    public int getWriteTimeout()
+    {
+        return writeTimeout;
+    }
+
+    public long getWriteTimeoutInMillis()
+    {
+        return writeTimeout * 1000L;
+    }
+
+    public void setWriteTimeout( int writeTimeout )
+    {
+        if( writeTimeout < 0 )
+            throw new IllegalArgumentException( "Illegal write timeout: "
+                                                + writeTimeout );
+        this.writeTimeout = writeTimeout;
+    }
+
+    public TrafficMask getTrafficMask()
+    {
+        return trafficMask;
+    }
+    
+    public void setTrafficMask( TrafficMask trafficMask )
+    {
+        if( trafficMask == null )
+        {
+            throw new NullPointerException( "trafficMask" );
+        }
+        
+        if( this.trafficMask == trafficMask )
+        {
+            return;
+        }
+        
+        this.trafficMask = trafficMask;
+        updateTrafficMask();
+    }
+    
+    public void suspendRead()
+    {
+        setTrafficMask( getTrafficMask().and( TrafficMask.READ.not() ) );
+    }
+
+    public void suspendWrite()
+    {
+        setTrafficMask( getTrafficMask().and( TrafficMask.WRITE.not() ) );
+    }
+
+    public void resumeRead()
+    {
+        setTrafficMask( getTrafficMask().or( TrafficMask.READ ) );
+    }
+
+    public void resumeWrite()
+    {
+        setTrafficMask( getTrafficMask().or( TrafficMask.WRITE ) );
+    }
+
+    /**
+     * Signals the {@link IoSessionManager} that the {@link TrafficMask} of this
+     * session has been changed.
+     */
+    protected abstract void updateTrafficMask();
+    
+    public long getReadBytes()
+    {
+        return readBytes;
+    }
+
+    public long getWrittenBytes()
+    {
+        return writtenBytes;
+    }
+    
+    public long getWrittenWriteRequests()
+    {
+        return writtenWriteRequests;
+    }
+    
+    public void increaseReadBytes( int increment )
+    {
+        readBytes += increment;
+        lastReadTime = System.currentTimeMillis();
+        idleCountForBoth = 0;
+        idleCountForWrite = 0;
+    }
+
+    public void increaseWrittenBytes( int increment )
+    {
+        writtenBytes += increment;
+        lastWriteTime = System.currentTimeMillis();
+        idleCountForBoth = 0;
+        idleCountForWrite = 0;
+    }
+    
+    public void increaseWrittenWriteRequests()
+    {
+        writtenWriteRequests ++;
+    }
+    
+    public long getCreationTime()
+    {
+        return creationTime;
+    }
+
+    public long getLastIoTime()
+    {
+        return Math.max( lastReadTime, lastWriteTime );
+    }
+
+    public long getLastReadTime()
+    {
+        return lastReadTime;
+    }
+
+    public long getLastWriteTime()
+    {
+        return lastWriteTime;
+    }
+
+    public boolean isIdle( IdleStatus status )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+            return idleCountForBoth > 0;
+
+        if( status == IdleStatus.READER_IDLE )
+            return idleCountForRead > 0;
+
+        if( status == IdleStatus.WRITER_IDLE )
+            return idleCountForWrite > 0;
+
+        throw new IllegalArgumentException( "Unknown idle status: " + status );
+    }
+
+    public int getIdleCount( IdleStatus status )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+            return idleCountForBoth;
+
+        if( status == IdleStatus.READER_IDLE )
+            return idleCountForRead;
+
+        if( status == IdleStatus.WRITER_IDLE )
+            return idleCountForWrite;
+
+        throw new IllegalArgumentException( "Unknown idle status: " + status );
+    }
+    
+    public long getLastIdleTime( IdleStatus status )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+            return lastIdleTimeForBoth;
+
+        if( status == IdleStatus.READER_IDLE )
+            return lastIdleTimeForRead;
+
+        if( status == IdleStatus.WRITER_IDLE )
+            return lastIdleTimeForWrite;
+
+        throw new IllegalArgumentException( "Unknown idle status: " + status );
+    }
+
+    public void increaseIdleCount( IdleStatus status )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+        {
+            idleCountForBoth ++;
+            lastIdleTimeForBoth = System.currentTimeMillis();
+        }
+        else if( status == IdleStatus.READER_IDLE )
+        {
+            idleCountForRead ++;
+            lastIdleTimeForRead = System.currentTimeMillis();
+        }
+        else if( status == IdleStatus.WRITER_IDLE )
+        {
+            idleCountForWrite ++;
+            lastIdleTimeForWrite = System.currentTimeMillis();
+        }
+        else
+            throw new IllegalArgumentException( "Unknown idle status: "
+                                                + status );
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSessionManager.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSessionManager.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSessionManager.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSessionManager.java Wed Nov 30 21:17:41 2005
@@ -1,55 +1,89 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.common.support;
-
-import org.apache.mina.common.ExceptionMonitor;
-import org.apache.mina.common.IoSessionManager;
-
-/**
- * Base implementation of {@link IoSessionManager}s.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public abstract class BaseIoSessionManager implements IoSessionManager {
-
-    /**
-     * Current exception monitor.
-     */
-    protected ExceptionMonitor exceptionMonitor = new DefaultExceptionMonitor();
-    
-    protected BaseIoSessionManager()
-    {
-    }
-    
-    public ExceptionMonitor getExceptionMonitor()
-    {
-        return exceptionMonitor;
-    }
-
-    public void setExceptionMonitor( ExceptionMonitor monitor )
-    {
-        if( monitor == null )
-        {
-            monitor = new DefaultExceptionMonitor();
-        }
-
-        this.exceptionMonitor = monitor;
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoSessionManager;
+
+/**
+ * Base implementation of {@link IoSessionManager}s.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseIoSessionManager implements IoSessionManager {
+
+    /**
+     * Current exception monitor.
+     */
+    protected ExceptionMonitor exceptionMonitor = new DefaultExceptionMonitor();
+    
+    /**
+     * Current filter chain builder.
+     */
+    protected IoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
+
+    protected BaseIoSessionManager()
+    {
+    }
+    
+    public IoFilterChainBuilder getFilterChainBuilder()
+    {
+        return filterChainBuilder;
+    }
+
+    public void setFilterChainBuilder( IoFilterChainBuilder builder )
+    {
+        if( builder == null )
+        {
+            builder = new DefaultIoFilterChainBuilder();
+        }
+        filterChainBuilder = builder;
+    }
+    
+    public DefaultIoFilterChainBuilder getFilterChain()
+    {
+        if( filterChainBuilder instanceof DefaultIoFilterChainBuilder )
+        {
+            return ( DefaultIoFilterChainBuilder ) filterChainBuilder;
+        }
+        else
+        {
+            throw new IllegalStateException(
+                    "Current filter chain builder is not a DefaultIoFilterChainBuilder." );
+        }
+    }
+
+    public ExceptionMonitor getExceptionMonitor()
+    {
+        return exceptionMonitor;
+    }
+
+    public void setExceptionMonitor( ExceptionMonitor monitor )
+    {
+        if( monitor == null )
+        {
+            monitor = new DefaultExceptionMonitor();
+        }
+
+        this.exceptionMonitor = monitor;
+    }
+}



Mime
View raw message