directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r350169 [14/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/...
Date Thu, 01 Dec 2005 05:19:07 GMT
Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java Wed Nov 30 21:17:41 2005
@@ -1,64 +1,72 @@
-/*
- * @(#) $Id$
- */
-package org.apache.mina.transport.vmpipe;
-
-import java.io.IOException;
-import java.net.SocketAddress;
-
-import org.apache.mina.common.ConnectFuture;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.support.BaseIoConnector;
-import org.apache.mina.transport.vmpipe.support.VmPipe;
-import org.apache.mina.transport.vmpipe.support.VmPipeSessionImpl;
-import org.apache.mina.transport.vmpipe.support.VmPipeSessionManagerFilterChain;
-import org.apache.mina.util.AnonymousSocketAddress;
-
-/**
- * Connects to {@link IoHandler}s which is bound on the specified
- * {@link VmPipeAddress}.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class VmPipeConnector extends BaseIoConnector
-{
-    private final VmPipeSessionManagerFilterChain filterChain =
-        new VmPipeSessionManagerFilterChain( this );
-
-    public IoFilterChain getFilterChain()
-    {
-        return filterChain;
-    }
-
-    public ConnectFuture connect( SocketAddress address, IoHandler handler ) throws IOException 
-    {
-        return connect( address, null, handler );
-    }
-
-    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler handler ) throws IOException
-    {
-        if( address == null )
-            throw new NullPointerException( "address" );
-        if( handler == null )
-            throw new NullPointerException( "handler" );
-        if( ! ( address instanceof VmPipeAddress ) )
-            throw new IllegalArgumentException(
-                                                "address must be VmPipeAddress." );
-
-        VmPipe entry = ( VmPipe ) VmPipeAcceptor.boundHandlers.get( address );
-        if( entry == null )
-            throw new IOException( "Endpoint unavailable: " + address );
-
-        VmPipeSessionImpl session = new VmPipeSessionImpl( new Object(), // lock
-                                                   AnonymousSocketAddress.INSTANCE,
-                                                   filterChain,
-                                                   handler,
-                                                   entry );
-
-        ConnectFuture future = new ConnectFuture();
-        future.setSession( session );
-        return future;
-    }
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.support.BaseIoConnector;
+import org.apache.mina.transport.vmpipe.support.VmPipe;
+import org.apache.mina.transport.vmpipe.support.VmPipeSessionImpl;
+import org.apache.mina.util.AnonymousSocketAddress;
+
+/**
+ * Connects to {@link IoHandler}s which is bound on the specified
+ * {@link VmPipeAddress}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeConnector extends BaseIoConnector
+{
+    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder ) 
+    {
+        return connect( address, null, handler, filterChainBuilder );
+    }
+
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler handler, IoFilterChainBuilder filterChainBuilder )
+    {
+        if( address == null )
+            throw new NullPointerException( "address" );
+        if( handler == null )
+            throw new NullPointerException( "handler" );
+        if( ! ( address instanceof VmPipeAddress ) )
+            throw new IllegalArgumentException(
+                                                "address must be VmPipeAddress." );
+
+        if( filterChainBuilder == null )
+        {
+            filterChainBuilder = IoFilterChainBuilder.NOOP;
+        }
+
+        VmPipe entry = ( VmPipe ) VmPipeAcceptor.boundHandlers.get( address );
+        if( entry == null )
+        {
+            return ConnectFuture.newFailedFuture(
+                    new IOException( "Endpoint unavailable: " + address ) );
+        }
+
+        ConnectFuture future = new ConnectFuture();
+        try
+        {
+            VmPipeSessionImpl session =
+                new VmPipeSessionImpl(
+                        this,
+                        new Object(), // lock
+                        AnonymousSocketAddress.INSTANCE,
+                        handler,
+                        filterChainBuilder,
+                        entry );
+            future.setSession( session );
+        }
+        catch( IOException e )
+        {
+            future.setException( e );
+        }
+        return future;
+    }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java Wed Nov 30 21:17:41 2005
@@ -1,16 +1,16 @@
-/*
- * @(#) $Id$
- */
-package org.apache.mina.transport.vmpipe;
-
-import org.apache.mina.common.IoSession;
-
-/**
- * A {@link IoSession} for in-VM transport (VM_PIPE).
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public interface VmPipeSession extends IoSession
-{
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import org.apache.mina.common.IoSession;
+
+/**
+ * A {@link IoSession} for in-VM transport (VM_PIPE).
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface VmPipeSession extends IoSession
+{
 }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipe.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipe.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipe.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipe.java Wed Nov 30 21:17:41 2005
@@ -1,47 +1,48 @@
-/*
- * @(#) $Id$
- */
-package org.apache.mina.transport.vmpipe.support;
-
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
-import org.apache.mina.transport.vmpipe.VmPipeAddress;
-
-public class VmPipe
-{
-    private final VmPipeAcceptor acceptor;
-    private final VmPipeAddress address;
-    private final VmPipeSessionManagerFilterChain managerFilterChain;
-    private final IoHandler handler;
-    
-    public VmPipe( VmPipeAcceptor acceptor,
-                   VmPipeAddress address,
-                   VmPipeSessionManagerFilterChain managerFilterChain,
-                   IoHandler handler )
-    {
-        this.acceptor = acceptor;
-        this.address = address;
-        this.managerFilterChain = managerFilterChain;
-        this.handler = handler;
-    }
-
-    public VmPipeAcceptor getAcceptor()
-    {
-        return acceptor;
-    }
-
-    public VmPipeAddress getAddress()
-    {
-        return address;
-    }
-
-    public IoHandler getHandler()
-    {
-        return handler;
-    }
-
-    public VmPipeSessionManagerFilterChain getManagerFilterChain()
-    {
-        return managerFilterChain;
-    }
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe.support;
+
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
+
+public class VmPipe
+{
+    private final VmPipeAcceptor acceptor;
+    private final VmPipeAddress address;
+    private final IoHandler handler;
+    private final IoFilterChainBuilder filterChainBuilder;
+    
+    public VmPipe( VmPipeAcceptor acceptor,
+                   VmPipeAddress address,
+                   IoHandler handler,
+                   IoFilterChainBuilder filterChainBuilder )
+    {
+        this.acceptor = acceptor;
+        this.address = address;
+        this.handler = handler;
+        this.filterChainBuilder = filterChainBuilder;
+    }
+
+    public VmPipeAcceptor getAcceptor()
+    {
+        return acceptor;
+    }
+
+    public VmPipeAddress getAddress()
+    {
+        return address;
+    }
+
+    public IoHandler getHandler()
+    {
+        return handler;
+    }
+    
+    public IoFilterChainBuilder getFilterChainBuilder()
+    {
+        return filterChainBuilder;
+    }
 }

Added: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java?rev=350169&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java Wed Nov 30 21:17:41 2005
@@ -0,0 +1,106 @@
+package org.apache.mina.transport.vmpipe.support;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoFilter.WriteRequest;
+import org.apache.mina.common.support.AbstractIoFilterChain;
+
+public class VmPipeFilterChain extends AbstractIoFilterChain {
+
+    public VmPipeFilterChain( IoSession session )
+    {
+        super( session );
+    }
+
+    public void messageReceived( IoSession session, Object message )
+    {
+        VmPipeSessionImpl s = ( VmPipeSessionImpl ) session;
+        synchronized( s.lock )
+        {
+            if( !s.getTrafficMask().isReadable() )
+            {
+                synchronized( s.pendingDataQueue )
+                {
+                    s.pendingDataQueue.push( message );
+                }
+            }
+            else
+            {
+                int byteCount = 1;
+                if( message instanceof ByteBuffer )
+                {
+                    byteCount = ( ( ByteBuffer ) message ).remaining();
+                }
+                
+                s.increaseReadBytes( byteCount );
+                
+                super.messageReceived( s, message );
+            }
+        }
+    }
+
+    protected void doWrite( IoSession session, WriteRequest writeRequest )
+    {
+        VmPipeSessionImpl s = ( VmPipeSessionImpl ) session;
+        synchronized( s.lock )
+        {
+            if( s.isConnected() )
+            {
+                
+                if( !s.getTrafficMask().isWritable() )
+                {
+                    synchronized( s.pendingDataQueue )
+                    {
+                        s.pendingDataQueue.push( writeRequest );
+                    }
+                }
+                else
+                {
+                
+                    Object message = writeRequest.getMessage();
+                    
+                    int byteCount = 1;
+                    Object messageCopy = message;
+                    if( message instanceof ByteBuffer )
+                    {
+                        ByteBuffer rb = ( ByteBuffer ) message;
+                        byteCount = rb.remaining();
+                        ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
+                        wb.put( rb );
+                        wb.flip();
+                        messageCopy = wb;
+                    }
+                    
+                    s.increaseWrittenBytes( byteCount );
+                    s.increaseWrittenWriteRequests();
+    
+                    ( ( VmPipeFilterChain ) s.getFilterChain() ).messageSent( s, message );
+                    ( ( VmPipeFilterChain ) s.remoteSession.getFilterChain() )
+                                .messageReceived( s.remoteSession, messageCopy );
+                    
+                    writeRequest.getFuture().setWritten( true );
+                }
+            }
+            else 
+            {
+                writeRequest.getFuture().setWritten( false );
+            }
+        }
+    }
+
+    protected void doClose( IoSession session, CloseFuture closeFuture )
+    {
+        VmPipeSessionImpl s = ( VmPipeSessionImpl ) session;
+        synchronized( s.lock )
+        {
+            if( !closeFuture.isClosed() )
+            {
+                ( ( VmPipeFilterChain ) s.getFilterChain() ).sessionClosed( session );
+                closeFuture.setClosed();
+                s.remoteSession.close();
+            }
+        }
+    }
+    
+}

Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java Wed Nov 30 21:17:41 2005
@@ -1,117 +1,118 @@
-/*
- * @(#) $Id$
- */
-package org.apache.mina.transport.vmpipe.support;
-
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.mina.common.IdleStatus;
-
-/**
- * Dectects idle sessions and fires <tt>sessionIdle</tt> events to them. 
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class VmPipeIdleStatusChecker
-{
-    private static final VmPipeIdleStatusChecker INSTANCE = new VmPipeIdleStatusChecker();
-    
-    public static VmPipeIdleStatusChecker getInstance()
-    {
-        return INSTANCE;
-    }
-
-    private final Map sessions = new IdentityHashMap(); // will use as a set
-
-    private final Worker worker = new Worker();
-
-    private VmPipeIdleStatusChecker()
-    {
-        worker.start();
-    }
-
-    public void addSession( VmPipeSessionImpl session )
-    {
-        synchronized( sessions )
-        {
-            sessions.put( session, session );
-        }
-    }
-
-    private class Worker extends Thread
-    {
-        private Worker()
-        {
-            super( "VmPipeIdleStatusChecker" );
-            setDaemon( true );
-        }
-
-        public void run()
-        {
-            for( ;; )
-            {
-                try
-                {
-                    Thread.sleep( 1000 );
-                }
-                catch( InterruptedException e )
-                {
-                }
-
-                long currentTime = System.currentTimeMillis();
-
-                synchronized( sessions )
-                {
-                    Iterator it = sessions.keySet().iterator();
-                    while( it.hasNext() )
-                    {
-                        VmPipeSessionImpl session = ( VmPipeSessionImpl ) it.next();
-                        if( !session.isConnected() )
-                        {
-                            it.remove();
-                        }
-                        else
-                        {
-                            notifyIdleSession( session, currentTime );
-                        }
-                    }
-                }
-            }
-        }
-    }
-    
-    private void notifyIdleSession( VmPipeSessionImpl session, long currentTime )
-    {
-        notifyIdleSession0(
-                session, currentTime,
-                session.getIdleTimeInMillis( IdleStatus.BOTH_IDLE ),
-                IdleStatus.BOTH_IDLE,
-                Math.max( session.getLastIoTime(), session.getLastIdleTime( IdleStatus.BOTH_IDLE ) ) );
-        notifyIdleSession0(
-                session, currentTime,
-                session.getIdleTimeInMillis( IdleStatus.READER_IDLE ),
-                IdleStatus.READER_IDLE,
-                Math.max( session.getLastReadTime(), session.getLastIdleTime( IdleStatus.READER_IDLE ) ) );
-        notifyIdleSession0(
-                session, currentTime,
-                session.getIdleTimeInMillis( IdleStatus.WRITER_IDLE ),
-                IdleStatus.WRITER_IDLE,
-                Math.max( session.getLastWriteTime(), session.getLastIdleTime( IdleStatus.WRITER_IDLE ) ) );
-    }
-
-    private void notifyIdleSession0( VmPipeSessionImpl session, long currentTime,
-                                    long idleTime, IdleStatus status,
-                                    long lastIoTime )
-    {
-        if( idleTime > 0 && lastIoTime != 0
-            && ( currentTime - lastIoTime ) >= idleTime )
-        {
-            session.increaseIdleCount( status );
-            session.getManagerFilterChain().sessionIdle( session, status );
-        }
-    }
-
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe.support;
+
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.support.AbstractIoFilterChain;
+
+/**
+ * Dectects idle sessions and fires <tt>sessionIdle</tt> events to them. 
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeIdleStatusChecker
+{
+    private static final VmPipeIdleStatusChecker INSTANCE = new VmPipeIdleStatusChecker();
+    
+    public static VmPipeIdleStatusChecker getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private final Map sessions = new IdentityHashMap(); // will use as a set
+
+    private final Worker worker = new Worker();
+
+    private VmPipeIdleStatusChecker()
+    {
+        worker.start();
+    }
+
+    public void addSession( VmPipeSessionImpl session )
+    {
+        synchronized( sessions )
+        {
+            sessions.put( session, session );
+        }
+    }
+
+    private class Worker extends Thread
+    {
+        private Worker()
+        {
+            super( "VmPipeIdleStatusChecker" );
+            setDaemon( true );
+        }
+
+        public void run()
+        {
+            for( ;; )
+            {
+                try
+                {
+                    Thread.sleep( 1000 );
+                }
+                catch( InterruptedException e )
+                {
+                }
+
+                long currentTime = System.currentTimeMillis();
+
+                synchronized( sessions )
+                {
+                    Iterator it = sessions.keySet().iterator();
+                    while( it.hasNext() )
+                    {
+                        VmPipeSessionImpl session = ( VmPipeSessionImpl ) it.next();
+                        if( !session.isConnected() )
+                        {
+                            it.remove();
+                        }
+                        else
+                        {
+                            notifyIdleSession( session, currentTime );
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    private void notifyIdleSession( VmPipeSessionImpl session, long currentTime )
+    {
+        notifyIdleSession0(
+                session, currentTime,
+                session.getIdleTimeInMillis( IdleStatus.BOTH_IDLE ),
+                IdleStatus.BOTH_IDLE,
+                Math.max( session.getLastIoTime(), session.getLastIdleTime( IdleStatus.BOTH_IDLE ) ) );
+        notifyIdleSession0(
+                session, currentTime,
+                session.getIdleTimeInMillis( IdleStatus.READER_IDLE ),
+                IdleStatus.READER_IDLE,
+                Math.max( session.getLastReadTime(), session.getLastIdleTime( IdleStatus.READER_IDLE ) ) );
+        notifyIdleSession0(
+                session, currentTime,
+                session.getIdleTimeInMillis( IdleStatus.WRITER_IDLE ),
+                IdleStatus.WRITER_IDLE,
+                Math.max( session.getLastWriteTime(), session.getLastIdleTime( IdleStatus.WRITER_IDLE ) ) );
+    }
+
+    private void notifyIdleSession0( VmPipeSessionImpl session, long currentTime,
+                                    long idleTime, IdleStatus status,
+                                    long lastIoTime )
+    {
+        if( idleTime > 0 && lastIoTime != 0
+            && ( currentTime - lastIoTime ) >= idleTime )
+        {
+            session.increaseIdleCount( status );
+            ( ( AbstractIoFilterChain ) session.getFilterChain() ).sessionIdle( session, status );
+        }
+    }
+
 }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java Wed Nov 30 21:17:41 2005
@@ -1,183 +1,187 @@
-/*
- * @(#) $Id$
- */
-package org.apache.mina.transport.vmpipe.support;
-
-import java.io.IOException;
-import java.net.SocketAddress;
-
-import org.apache.mina.common.CloseFuture;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.common.IoFilter.WriteRequest;
-import org.apache.mina.common.support.BaseIoSession;
-import org.apache.mina.common.support.IoSessionFilterChain;
-import org.apache.mina.filter.codec.ProtocolDecoder;
-import org.apache.mina.filter.codec.ProtocolEncoder;
-import org.apache.mina.transport.vmpipe.VmPipeSession;
-import org.apache.mina.util.ExceptionUtil;
-import org.apache.mina.util.Queue;
-
-/**
- * A {@link IoSession} for in-VM transport (VM_PIPE).
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class VmPipeSessionImpl extends BaseIoSession implements VmPipeSession
-{
-    private final SocketAddress localAddress;
-    private final SocketAddress remoteAddress;
-    private final IoHandler handler;
-    private final IoSessionFilterChain filterChain;
-    private final VmPipeSessionManagerFilterChain managerFilterChain;
-    final VmPipeSessionImpl remoteSession;
-    final Object lock;
-    final Queue pendingDataQueue;
-
-    /**
-     * Constructor for client-side session.
-     */
-    public VmPipeSessionImpl( Object lock, SocketAddress localAddress,
-                   VmPipeSessionManagerFilterChain managerFilterChain,
-                   IoHandler handler,
-                   VmPipe remoteEntry ) throws IOException
-    {
-        this.lock = lock;
-        this.localAddress = localAddress;
-        this.remoteAddress = remoteEntry.getAddress();
-        this.handler = handler;
-        this.filterChain = new IoSessionFilterChain( this, managerFilterChain );
-        this.managerFilterChain = managerFilterChain;
-        this.pendingDataQueue = new Queue();
-
-        remoteSession = new VmPipeSessionImpl( this, remoteEntry );
-        
-        // initialize remote session
-        try
-        {
-            remoteEntry.getManagerFilterChain().sessionCreated( remoteSession );
-        }
-        catch( Throwable t )
-        {
-            remoteEntry.getAcceptor().getExceptionMonitor().exceptionCaught( remoteEntry.getAcceptor(), t );
-            IOException e = new IOException( "Failed to initialize remote session." );
-            e.initCause( t );
-            throw e;
-        }
-        
-        // initialize client session
-        try
-        {
-            handler.sessionCreated( this );
-        }
-        catch( Throwable t )
-        {
-            ExceptionUtil.throwException( t );
-        }
-
-        VmPipeIdleStatusChecker.getInstance().addSession( remoteSession );
-        VmPipeIdleStatusChecker.getInstance().addSession( this );
-        
-        remoteEntry.getManagerFilterChain().sessionOpened( remoteSession );
-        managerFilterChain.sessionOpened( this );
-    }
-
-    /**
-     * Constructor for server-side session.
-     */
-    private VmPipeSessionImpl( VmPipeSessionImpl remoteSession, VmPipe entry )
-    {
-        this.lock = remoteSession.lock;
-        this.localAddress = remoteSession.remoteAddress;
-        this.remoteAddress = remoteSession.localAddress;
-        this.handler = entry.getHandler();
-        this.managerFilterChain = entry.getManagerFilterChain();
-        this.filterChain = new IoSessionFilterChain( this, entry.getManagerFilterChain() );
-        this.remoteSession = remoteSession;
-        this.pendingDataQueue = new Queue();
-    }
-    
-    VmPipeSessionManagerFilterChain getManagerFilterChain()
-    {
-        return managerFilterChain;
-    }
-    
-    public IoFilterChain getFilterChain()
-    {
-        return filterChain;
-    }
-
-    public IoHandler getHandler()
-    {
-        return handler;
-    }
-
-    public ProtocolEncoder getEncoder()
-    {
-        return null;
-    }
-
-    public ProtocolDecoder getDecoder()
-    {
-        return null;
-    }
-    
-    protected void close0( CloseFuture closeFuture )
-    {
-        managerFilterChain.filterClose( this, closeFuture );
-    }
-    
-    protected void write0( WriteRequest writeRequest )
-    {
-        this.filterChain.filterWrite( this, writeRequest );
-    }
-
-    public int getScheduledWriteRequests()
-    {
-        return 0;
-    }
-
-    public TransportType getTransportType()
-    {
-        return TransportType.VM_PIPE;
-    }
-
-    public SocketAddress getRemoteAddress()
-    {
-        return remoteAddress;
-    }
-
-    public SocketAddress getLocalAddress()
-    {
-        return localAddress;
-    }
-
-    protected void updateTrafficMask()
-    {
-        if( getTrafficMask().isReadable() || getTrafficMask().isWritable())
-        {
-            Object[] data = null;
-            synchronized( pendingDataQueue )
-            {
-                data = pendingDataQueue.toArray();
-                pendingDataQueue.clear();
-            }
-            
-            for( int i = 0; i < data.length; i++ )
-            {
-                if( data[ i ] instanceof WriteRequest )
-                {
-                    WriteRequest wr = ( WriteRequest ) data[ i ];
-                    managerFilterChain.doWrite( this, wr );
-                }
-                else
-                {
-                    managerFilterChain.messageReceived( this, data[ i ] );
-                }
-            }
-        }
-    }
-}
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe.support;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionManager;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.common.IoFilter.WriteRequest;
+import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.transport.vmpipe.VmPipeSession;
+import org.apache.mina.util.ExceptionUtil;
+import org.apache.mina.util.Queue;
+
+/**
+ * A {@link IoSession} for in-VM transport (VM_PIPE).
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeSessionImpl extends BaseIoSession implements VmPipeSession
+{
+    private final IoSessionManager manager;
+    private final SocketAddress localAddress;
+    private final SocketAddress remoteAddress;
+    private final IoHandler handler;
+    private final VmPipeFilterChain filterChain;
+    final VmPipeSessionImpl remoteSession;
+    final Object lock;
+    final Queue pendingDataQueue;
+
+    /**
+     * Constructor for client-side session.
+     */
+    public VmPipeSessionImpl( IoSessionManager manager, Object lock, SocketAddress localAddress,
+                   IoHandler handler, IoFilterChainBuilder filterChainBuilder,
+                   VmPipe remoteEntry ) throws IOException
+    {
+        this.manager = manager;
+        this.lock = lock;
+        this.localAddress = localAddress;
+        this.remoteAddress = remoteEntry.getAddress();
+        this.handler = handler;
+        this.filterChain = new VmPipeFilterChain( this );
+        this.pendingDataQueue = new Queue();
+
+        remoteSession = new VmPipeSessionImpl( manager, this, remoteEntry );
+        
+        // initialize remote session
+        try
+        {
+            remoteEntry.getAcceptor().getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
+            remoteEntry.getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
+            ( ( VmPipeFilterChain ) remoteSession.getFilterChain() ).sessionCreated( remoteSession );
+        }
+        catch( Throwable t )
+        {
+            remoteEntry.getAcceptor().getExceptionMonitor().exceptionCaught( remoteEntry.getAcceptor(), t );
+            IOException e = new IOException( "Failed to initialize remote session." );
+            e.initCause( t );
+            throw e;
+        }
+        
+        // initialize client session
+        try
+        {
+            manager.getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
+            filterChainBuilder.buildFilterChain( remoteSession.getFilterChain() );
+            handler.sessionCreated( this );
+        }
+        catch( Throwable t )
+        {
+            ExceptionUtil.throwException( t );
+        }
+
+        VmPipeIdleStatusChecker.getInstance().addSession( remoteSession );
+        VmPipeIdleStatusChecker.getInstance().addSession( this );
+        
+        ( ( VmPipeFilterChain ) remoteSession.getFilterChain() ).sessionOpened( remoteSession );
+        filterChain.sessionOpened( this );
+    }
+
+    /**
+     * Constructor for server-side session.
+     */
+    private VmPipeSessionImpl( IoSessionManager manager, VmPipeSessionImpl remoteSession, VmPipe entry )
+    {
+        this.manager = manager;
+        this.lock = remoteSession.lock;
+        this.localAddress = remoteSession.remoteAddress;
+        this.remoteAddress = remoteSession.localAddress;
+        this.handler = entry.getHandler();
+        this.filterChain = new VmPipeFilterChain( this );
+        this.remoteSession = remoteSession;
+        this.pendingDataQueue = new Queue();
+    }
+    
+    public IoSessionManager getManager()
+    {
+        return manager;
+    }
+
+    public IoFilterChain getFilterChain()
+    {
+        return filterChain;
+    }
+
+    public IoHandler getHandler()
+    {
+        return handler;
+    }
+
+    public ProtocolEncoder getEncoder()
+    {
+        return null;
+    }
+
+    public ProtocolDecoder getDecoder()
+    {
+        return null;
+    }
+    
+    protected void close0( CloseFuture closeFuture )
+    {
+        filterChain.filterClose( this, closeFuture );
+    }
+    
+    protected void write0( WriteRequest writeRequest )
+    {
+        this.filterChain.filterWrite( this, writeRequest );
+    }
+
+    public int getScheduledWriteRequests()
+    {
+        return 0;
+    }
+
+    public TransportType getTransportType()
+    {
+        return TransportType.VM_PIPE;
+    }
+
+    public SocketAddress getRemoteAddress()
+    {
+        return remoteAddress;
+    }
+
+    public SocketAddress getLocalAddress()
+    {
+        return localAddress;
+    }
+
+    protected void updateTrafficMask()
+    {
+        if( getTrafficMask().isReadable() || getTrafficMask().isWritable())
+        {
+            Object[] data = null;
+            synchronized( pendingDataQueue )
+            {
+                data = pendingDataQueue.toArray();
+                pendingDataQueue.clear();
+            }
+            
+            for( int i = 0; i < data.length; i++ )
+            {
+                if( data[ i ] instanceof WriteRequest )
+                {
+                    WriteRequest wr = ( WriteRequest ) data[ i ];
+                    filterChain.doWrite( this, wr );
+                }
+                else
+                {
+                    filterChain.messageReceived( this, data[ i ] );
+                }
+            }
+        }
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/util/AnonymousSocketAddress.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/AnonymousSocketAddress.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/AnonymousSocketAddress.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/AnonymousSocketAddress.java Wed Nov 30 21:17:41 2005
@@ -1,50 +1,50 @@
-/*
- * @(#) $Id$
- */
-package org.apache.mina.util;
-
-import java.net.SocketAddress;
-
-/**
- * A {@link SocketAddress} which represents anonymous address.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class AnonymousSocketAddress extends SocketAddress implements Comparable
-{
-    private static final long serialVersionUID = 3978421416766944048L;
-
-    public static final AnonymousSocketAddress INSTANCE = new AnonymousSocketAddress();
-
-    /**
-     * Creates a new instance with the specifid port number.
-     */
-    private AnonymousSocketAddress()
-    {
-    }
-
-    public int hashCode()
-    {
-        return 1432482932;
-    }
-
-    public boolean equals( Object o )
-    {
-        if( o == null )
-            return false;
-        if( this == o )
-            return true;
-        return o instanceof AnonymousSocketAddress;
-    }
-
-    public int compareTo( Object o )
-    {
-        return this.hashCode() - ( ( AnonymousSocketAddress ) o ).hashCode();
-    }
-
-    public String toString()
-    {
-        return "anonymous";
-    }
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.util;
+
+import java.net.SocketAddress;
+
+/**
+ * A {@link SocketAddress} which represents anonymous address.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class AnonymousSocketAddress extends SocketAddress implements Comparable
+{
+    private static final long serialVersionUID = 3978421416766944048L;
+
+    public static final AnonymousSocketAddress INSTANCE = new AnonymousSocketAddress();
+
+    /**
+     * Creates a new instance with the specifid port number.
+     */
+    private AnonymousSocketAddress()
+    {
+    }
+
+    public int hashCode()
+    {
+        return 1432482932;
+    }
+
+    public boolean equals( Object o )
+    {
+        if( o == null )
+            return false;
+        if( this == o )
+            return true;
+        return o instanceof AnonymousSocketAddress;
+    }
+
+    public int compareTo( Object o )
+    {
+        return this.hashCode() - ( ( AnonymousSocketAddress ) o ).hashCode();
+    }
+
+    public String toString()
+    {
+        return "anonymous";
+    }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/util/ByteBufferUtil.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/ByteBufferUtil.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/ByteBufferUtil.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/ByteBufferUtil.java Wed Nov 30 21:17:41 2005
@@ -1,50 +1,50 @@
-/*
- *   @(#) $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.util;
-
-import org.apache.mina.common.ByteBuffer;
-
-/**
- * ByteBuffer utility.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class ByteBufferUtil
-{
-    public static void acquireIfPossible( Object message )
-    {
-        if( message instanceof ByteBuffer )
-        {
-            ( ( ByteBuffer ) message ).acquire();
-        }
-    }
-    
-    public static void releaseIfPossible( Object message )
-    {
-        if( message instanceof ByteBuffer )
-        {
-            ( ( ByteBuffer ) message ).release();
-        }
-    }
-    
-    private ByteBufferUtil()
-    {
-    }
-}
+/*
+ *   @(#) $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.util;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ByteBuffer utility.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ByteBufferUtil
+{
+    public static void acquireIfPossible( Object message )
+    {
+        if( message instanceof ByteBuffer )
+        {
+            ( ( ByteBuffer ) message ).acquire();
+        }
+    }
+    
+    public static void releaseIfPossible( Object message )
+    {
+        if( message instanceof ByteBuffer )
+        {
+            ( ( ByteBuffer ) message ).release();
+        }
+    }
+    
+    private ByteBufferUtil()
+    {
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.java Wed Nov 30 21:17:41 2005
@@ -1,54 +1,54 @@
-/*
- *   @(#) $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.util;
-
-import java.io.IOException;
-
-/**
- * Exception utility.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class ExceptionUtil {
-
-    public static void throwException( Throwable t ) throws IOException
-    {
-        if( t instanceof IOException )
-        {
-            throw ( IOException ) t;
-        }
-        else if( t instanceof RuntimeException )
-        {
-            throw ( RuntimeException ) t;
-        }
-        else if( t instanceof Error )
-        {
-            throw ( Error ) t;
-        }
-        else
-        {
-            throw new RuntimeException( t );
-        }
-    }
-    
-    private ExceptionUtil()
-    {
-    }
-}
+/*
+ *   @(#) $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.util;
+
+import java.io.IOException;
+
+/**
+ * Exception utility.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ExceptionUtil {
+
+    public static void throwException( Throwable t ) throws IOException
+    {
+        if( t instanceof IOException )
+        {
+            throw ( IOException ) t;
+        }
+        else if( t instanceof RuntimeException )
+        {
+            throw ( RuntimeException ) t;
+        }
+        else if( t instanceof Error )
+        {
+            throw ( Error ) t;
+        }
+        else
+        {
+            throw new RuntimeException( t );
+        }
+    }
+    
+    private ExceptionUtil()
+    {
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/util/Queue.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/Queue.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/Queue.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/Queue.java Wed Nov 30 21:17:41 2005
@@ -1,348 +1,348 @@
-/*
- *   @(#) $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.util;
-
-import java.io.Serializable;
-import java.util.AbstractList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * A unbounded circular queue.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class Queue extends AbstractList implements List, Serializable
-{
-    private static final long serialVersionUID = 3835151744526464313L;
-
-	private static final int DEFAULT_CAPACITY = 4;
-
-    private static final int DEFAULT_MASK = DEFAULT_CAPACITY - 1;
-
-    private Object[] items;
-
-    private int mask;
-
-    private int first = 0;
-
-    private int last = 0;
-
-    private int size = 0;
-
-    /**
-     * Construct a new, empty queue.
-     */
-    public Queue()
-    {
-        items = new Object[ DEFAULT_CAPACITY ];
-        mask = DEFAULT_MASK;
-    }
-    
-    /**
-     * Returns the capacity of this queue.
-     */
-    public int capacity()
-    {
-        return items.length;
-    }
-
-    /**
-     * Clears this queue.
-     */
-    public void clear()
-    {
-        Arrays.fill( items, null );
-        first = 0;
-        last = 0;
-        size = 0;
-    }
-
-    /**
-     * Dequeues from this queue.
-     * 
-     * @return <code>null</code>, if this queue is empty or the element is
-     *         really <code>null</code>.
-     */
-    public Object pop()
-    {
-        if( size == 0 )
-        {
-            return null;
-        }
-
-        Object ret = items[ first ];
-        items[ first ] = null;
-        decreaseSize();
-
-        return ret;
-    }
-
-    /**
-     * Enqueue into this queue.
-     */
-    public void push( Object obj )
-    {
-        ensureCapacity();
-        items[ last ] = obj;
-        increaseSize();
-    }
-
-    /**
-     * Returns the first element of the queue.
-     * 
-     * @return <code>null</code>, if the queue is empty, or the element is
-     *         really <code>null</code>.
-     */
-    public Object first()
-    {
-        if( size == 0 )
-        {
-            return null;
-        }
-
-        return items[ first ];
-    }
-
-    /**
-     * Returns the last element of the queue.
-     * 
-     * @return <code>null</code>, if the queue is empty, or the element is
-     *         really <code>null</code>.
-     */
-    public Object last()
-    {
-        if( size == 0 )
-        {
-            return null;
-        }
-
-        return items[ ( last + items.length - 1 ) & mask ];
-    }
-    
-    public Object get( int idx )
-    {
-        checkIndex(idx);
-        return items[ getRealIndex(idx) ];
-    }
-
-    /**
-     * Returns <code>true</code> if the queue is empty.
-     */
-    public boolean isEmpty()
-    {
-        return ( size == 0 );
-    }
-
-    /**
-     * Returns the number of elements in the queue.
-     */
-    public int size()
-    {
-        return size;
-    }
-    
-    public String toString()
-    {
-        return "first=" + first + ", last=" + last + ", size=" + size + ", mask = " + mask;
-    }
-
-    private void checkIndex( int idx )
-    {
-        if( idx < 0 || idx >= size )
-        {
-            throw new IndexOutOfBoundsException( String.valueOf( idx ) );
-        }
-    }
-
-    private int getRealIndex( int idx )
-    {
-        return ( first + idx ) & mask;
-    }
-
-    private void increaseSize()
-    {
-        last = ( last + 1 ) & mask;
-        size++;
-    }
-
-    private void decreaseSize() {
-        first = ( first + 1 ) & mask;
-        size--;
-    }
-
-    private void ensureCapacity()
-    {
-        if( size < items.length )
-        {
-            return;
-        }
-        
-        // expand queue
-        final int oldLen = items.length;
-        Object[] tmp = new Object[ oldLen * 2 ];
-
-        if( first < last )
-        {
-            System.arraycopy( items, first, tmp, 0, last - first );
-        }
-        else
-        {
-            System.arraycopy( items, first, tmp, 0, oldLen - first );
-            System.arraycopy( items, 0, tmp, oldLen - first, last );
-        }
-
-        first = 0;
-        last = oldLen;
-        items = tmp;
-        mask = tmp.length - 1;
-    }
-
-    //////////////////////////////////////////
-    // java.util.List compatibility methods //
-    //////////////////////////////////////////
-
-    public boolean add( Object o )
-    {
-        push( o );
-        return true;
-    }
-
-    public Object set(int idx, Object o) {
-        checkIndex(idx);
-        
-        int realIdx = getRealIndex(idx);
-        Object old = items[ realIdx ];
-        items[ realIdx ] = o;
-        return old;
-    }
-
-    public void add( int idx, Object o )
-    {
-        if( idx == size )
-        {
-            push( o );
-            return;
-        }
-        
-        checkIndex( idx );
-        ensureCapacity();
-        
-        int realIdx = getRealIndex( idx );
-        
-        // Make a room for a new element.
-        if( first < last )
-        {
-            System.arraycopy( items, realIdx, items, realIdx + 1, last - realIdx );
-        }
-        else
-        {
-            if( realIdx >= first )
-            {
-                System.arraycopy( items, 0, items, 1, last );
-                items[ 0 ] = items[ items.length - 1 ];
-                System.arraycopy( items, realIdx, items, realIdx + 1, items.length - realIdx - 1 );
-            }
-            else
-            {
-                System.arraycopy( items, realIdx, items, realIdx + 1, last - realIdx );
-            }
-        }
-        
-        items[ realIdx ] = o;
-        increaseSize();
-    }
-
-    public Object remove( int idx )
-    {
-        if( idx == 0 )
-        {
-            return pop();
-        }
-        
-        checkIndex( idx );
-        
-        int realIdx = getRealIndex( idx );
-        Object removed = items[ realIdx ];
-        
-        // Remove a room for the removed element.
-        if( first < last )
-        {
-            System.arraycopy( items, first, items, first + 1, realIdx - first );
-        }
-        else
-        {
-            if( realIdx >= first )
-            {
-                System.arraycopy( items, first, items, first + 1, realIdx - first );
-            }
-            else
-            {
-                System.arraycopy( items, 0, items, 1, realIdx );
-                items[ 0 ] = items[ items.length - 1 ];
-                System.arraycopy( items, first, items, first + 1, items.length - first - 1 );
-            }
-        }
-        
-        items[ first ] = null;
-        decreaseSize();
-
-        return removed;
-    }
-
-    ///////////////////////////////////////////
-    // java.util.Queue compatibility methods //
-    ///////////////////////////////////////////
-
-    public boolean offer( Object o )
-    {
-        push( o );
-        return true;
-    }
-
-    public Object poll()
-    {
-        return pop();
-    }
-
-    public Object remove()
-    {
-        if( size == 0 )
-        {
-            throw new NoSuchElementException();
-        }
-        return pop();
-    }
-
-    public Object peek()
-    {
-        return first();
-    }
-
-    public Object element()
-    {
-        if( size == 0 )
-        {
-            throw new NoSuchElementException();
-        }
-        return first();
-    }
+/*
+ *   @(#) $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.util;
+
+import java.io.Serializable;
+import java.util.AbstractList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * A unbounded circular queue.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class Queue extends AbstractList implements List, Serializable
+{
+    private static final long serialVersionUID = 3835151744526464313L;
+
+	private static final int DEFAULT_CAPACITY = 4;
+
+    private static final int DEFAULT_MASK = DEFAULT_CAPACITY - 1;
+
+    private Object[] items;
+
+    private int mask;
+
+    private int first = 0;
+
+    private int last = 0;
+
+    private int size = 0;
+
+    /**
+     * Construct a new, empty queue.
+     */
+    public Queue()
+    {
+        items = new Object[ DEFAULT_CAPACITY ];
+        mask = DEFAULT_MASK;
+    }
+    
+    /**
+     * Returns the capacity of this queue.
+     */
+    public int capacity()
+    {
+        return items.length;
+    }
+
+    /**
+     * Clears this queue.
+     */
+    public void clear()
+    {
+        Arrays.fill( items, null );
+        first = 0;
+        last = 0;
+        size = 0;
+    }
+
+    /**
+     * Dequeues from this queue.
+     * 
+     * @return <code>null</code>, if this queue is empty or the element is
+     *         really <code>null</code>.
+     */
+    public Object pop()
+    {
+        if( size == 0 )
+        {
+            return null;
+        }
+
+        Object ret = items[ first ];
+        items[ first ] = null;
+        decreaseSize();
+
+        return ret;
+    }
+
+    /**
+     * Enqueue into this queue.
+     */
+    public void push( Object obj )
+    {
+        ensureCapacity();
+        items[ last ] = obj;
+        increaseSize();
+    }
+
+    /**
+     * Returns the first element of the queue.
+     * 
+     * @return <code>null</code>, if the queue is empty, or the element is
+     *         really <code>null</code>.
+     */
+    public Object first()
+    {
+        if( size == 0 )
+        {
+            return null;
+        }
+
+        return items[ first ];
+    }
+
+    /**
+     * Returns the last element of the queue.
+     * 
+     * @return <code>null</code>, if the queue is empty, or the element is
+     *         really <code>null</code>.
+     */
+    public Object last()
+    {
+        if( size == 0 )
+        {
+            return null;
+        }
+
+        return items[ ( last + items.length - 1 ) & mask ];
+    }
+    
+    public Object get( int idx )
+    {
+        checkIndex(idx);
+        return items[ getRealIndex(idx) ];
+    }
+
+    /**
+     * Returns <code>true</code> if the queue is empty.
+     */
+    public boolean isEmpty()
+    {
+        return ( size == 0 );
+    }
+
+    /**
+     * Returns the number of elements in the queue.
+     */
+    public int size()
+    {
+        return size;
+    }
+    
+    public String toString()
+    {
+        return "first=" + first + ", last=" + last + ", size=" + size + ", mask = " + mask;
+    }
+
+    private void checkIndex( int idx )
+    {
+        if( idx < 0 || idx >= size )
+        {
+            throw new IndexOutOfBoundsException( String.valueOf( idx ) );
+        }
+    }
+
+    private int getRealIndex( int idx )
+    {
+        return ( first + idx ) & mask;
+    }
+
+    private void increaseSize()
+    {
+        last = ( last + 1 ) & mask;
+        size++;
+    }
+
+    private void decreaseSize() {
+        first = ( first + 1 ) & mask;
+        size--;
+    }
+
+    private void ensureCapacity()
+    {
+        if( size < items.length )
+        {
+            return;
+        }
+        
+        // expand queue
+        final int oldLen = items.length;
+        Object[] tmp = new Object[ oldLen * 2 ];
+
+        if( first < last )
+        {
+            System.arraycopy( items, first, tmp, 0, last - first );
+        }
+        else
+        {
+            System.arraycopy( items, first, tmp, 0, oldLen - first );
+            System.arraycopy( items, 0, tmp, oldLen - first, last );
+        }
+
+        first = 0;
+        last = oldLen;
+        items = tmp;
+        mask = tmp.length - 1;
+    }
+
+    //////////////////////////////////////////
+    // java.util.List compatibility methods //
+    //////////////////////////////////////////
+
+    public boolean add( Object o )
+    {
+        push( o );
+        return true;
+    }
+
+    public Object set(int idx, Object o) {
+        checkIndex(idx);
+        
+        int realIdx = getRealIndex(idx);
+        Object old = items[ realIdx ];
+        items[ realIdx ] = o;
+        return old;
+    }
+
+    public void add( int idx, Object o )
+    {
+        if( idx == size )
+        {
+            push( o );
+            return;
+        }
+        
+        checkIndex( idx );
+        ensureCapacity();
+        
+        int realIdx = getRealIndex( idx );
+        
+        // Make a room for a new element.
+        if( first < last )
+        {
+            System.arraycopy( items, realIdx, items, realIdx + 1, last - realIdx );
+        }
+        else
+        {
+            if( realIdx >= first )
+            {
+                System.arraycopy( items, 0, items, 1, last );
+                items[ 0 ] = items[ items.length - 1 ];
+                System.arraycopy( items, realIdx, items, realIdx + 1, items.length - realIdx - 1 );
+            }
+            else
+            {
+                System.arraycopy( items, realIdx, items, realIdx + 1, last - realIdx );
+            }
+        }
+        
+        items[ realIdx ] = o;
+        increaseSize();
+    }
+
+    public Object remove( int idx )
+    {
+        if( idx == 0 )
+        {
+            return pop();
+        }
+        
+        checkIndex( idx );
+        
+        int realIdx = getRealIndex( idx );
+        Object removed = items[ realIdx ];
+        
+        // Remove a room for the removed element.
+        if( first < last )
+        {
+            System.arraycopy( items, first, items, first + 1, realIdx - first );
+        }
+        else
+        {
+            if( realIdx >= first )
+            {
+                System.arraycopy( items, first, items, first + 1, realIdx - first );
+            }
+            else
+            {
+                System.arraycopy( items, 0, items, 1, realIdx );
+                items[ 0 ] = items[ items.length - 1 ];
+                System.arraycopy( items, first, items, first + 1, items.length - first - 1 );
+            }
+        }
+        
+        items[ first ] = null;
+        decreaseSize();
+
+        return removed;
+    }
+
+    ///////////////////////////////////////////
+    // java.util.Queue compatibility methods //
+    ///////////////////////////////////////////
+
+    public boolean offer( Object o )
+    {
+        push( o );
+        return true;
+    }
+
+    public Object poll()
+    {
+        return pop();
+    }
+
+    public Object remove()
+    {
+        if( size == 0 )
+        {
+            throw new NoSuchElementException();
+        }
+        return pop();
+    }
+
+    public Object peek()
+    {
+        return first();
+    }
+
+    public Object element()
+    {
+        if( size == 0 )
+        {
+            throw new NoSuchElementException();
+        }
+        return first();
+    }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java Wed Nov 30 21:17:41 2005
@@ -1,161 +1,161 @@
-/*
- *   @(#) $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.util;
-
-import org.apache.mina.common.IoSession;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provides utility methods to log protocol-specific messages.
- * <p>
- * Set {@link #PREFIX} and {@link #LOGGER} session attributes
- * to override prefix string and logger.
- *
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- *
- */
-public class SessionLog {
-    /**
-     * Session attribute key: prefix string
-     */
-    public static final String PREFIX = SessionLog.class.getName() + ".prefix";
-
-    /**
-     * Session attribute key: {@link Logger}
-     */
-    public static final String LOGGER = SessionLog.class.getName() + ".logger";
-    
-    private static Class getClass( IoSession session )
-    {
-        return session.getHandler().getClass();
-    }
-
-    public static void debug( IoSession session, String message )
-    {
-        Logger log = getLogger( session );
-        if( log.isDebugEnabled() )
-        {
-            log.debug( String.valueOf( session.getAttribute( PREFIX ) ) + message );
-        }
-    }
-
-    public static void debug( IoSession session, String message, Throwable cause )
-    {
-        Logger log = getLogger( session );
-        if( log.isDebugEnabled() )
-        {
-            log.debug( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
-        }
-    }
-
-    public static void info( IoSession session, String message )
-    {
-        Logger log = getLogger( session );
-        if( log.isInfoEnabled() )
-        {
-            log.info( String.valueOf( session.getAttribute( PREFIX ) ) + message );
-        }
-    }
-
-    public static void info( IoSession session, String message, Throwable cause )
-    {
-        Logger log = getLogger( session );
-        if( log.isInfoEnabled() )
-        {
-            log.info( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
-        }
-    }
-
-    public static void warn( IoSession session, String message )
-    {
-        Logger log = getLogger( session );
-        if( log.isWarnEnabled() )
-        {
-            log.warn( String.valueOf( session.getAttribute( PREFIX ) ) + message );
-        }
-    }
-
-    public static void warn( IoSession session, String message, Throwable cause )
-    {
-        Logger log = getLogger( session );
-        if( log.isWarnEnabled() )
-        {
-            log.warn( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
-        }
-    }
-
-    public static void error( IoSession session, String message )
-    {
-        Logger log = getLogger( session );
-        if( log.isErrorEnabled() )
-        {
-            log.error( String.valueOf( session.getAttribute( PREFIX ) ) + message );
-        }
-    }
-
-    public static void error( IoSession session, String message, Throwable cause )
-    {
-        Logger log = getLogger( session );
-        if( log.isErrorEnabled() )
-        {
-            log.error( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
-        }
-    }
-    
-    public static boolean isDebugEnabled( IoSession session )
-    {
-        return getLogger( session ).isDebugEnabled();
-    }
-    
-    public static boolean isInfoEnabled( IoSession session )
-    {
-        return getLogger( session ).isInfoEnabled();
-    }
-    
-    public static boolean isWarnEnabled( IoSession session )
-    {
-        return getLogger( session ).isWarnEnabled();
-    }
-    
-    public static boolean isErrorEnabled( IoSession session )
-    {
-        return getLogger( session ).isErrorEnabled();
-    }
-
-    private static Logger getLogger( IoSession session )
-    {
-        Logger log = (Logger) session.getAttribute( LOGGER );
-        if( log == null )
-        {
-            log = LoggerFactory.getLogger( getClass( session ) );
-            String prefix = ( String ) session.getAttribute( PREFIX );
-            if( prefix == null )
-            {
-                prefix = "[" + session.getRemoteAddress() + "] ";
-                session.setAttribute( PREFIX, prefix );
-            }
-                
-            session.setAttribute( LOGGER, log );
-        }
-        
-        return log;
-    }
-}
+/*
+ *   @(#) $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.util;
+
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides utility methods to log protocol-specific messages.
+ * <p>
+ * Set {@link #PREFIX} and {@link #LOGGER} session attributes
+ * to override prefix string and logger.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ *
+ */
+public class SessionLog {
+    /**
+     * Session attribute key: prefix string
+     */
+    public static final String PREFIX = SessionLog.class.getName() + ".prefix";
+
+    /**
+     * Session attribute key: {@link Logger}
+     */
+    public static final String LOGGER = SessionLog.class.getName() + ".logger";
+    
+    private static Class getClass( IoSession session )
+    {
+        return session.getHandler().getClass();
+    }
+
+    public static void debug( IoSession session, String message )
+    {
+        Logger log = getLogger( session );
+        if( log.isDebugEnabled() )
+        {
+            log.debug( String.valueOf( session.getAttribute( PREFIX ) ) + message );
+        }
+    }
+
+    public static void debug( IoSession session, String message, Throwable cause )
+    {
+        Logger log = getLogger( session );
+        if( log.isDebugEnabled() )
+        {
+            log.debug( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
+        }
+    }
+
+    public static void info( IoSession session, String message )
+    {
+        Logger log = getLogger( session );
+        if( log.isInfoEnabled() )
+        {
+            log.info( String.valueOf( session.getAttribute( PREFIX ) ) + message );
+        }
+    }
+
+    public static void info( IoSession session, String message, Throwable cause )
+    {
+        Logger log = getLogger( session );
+        if( log.isInfoEnabled() )
+        {
+            log.info( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
+        }
+    }
+
+    public static void warn( IoSession session, String message )
+    {
+        Logger log = getLogger( session );
+        if( log.isWarnEnabled() )
+        {
+            log.warn( String.valueOf( session.getAttribute( PREFIX ) ) + message );
+        }
+    }
+
+    public static void warn( IoSession session, String message, Throwable cause )
+    {
+        Logger log = getLogger( session );
+        if( log.isWarnEnabled() )
+        {
+            log.warn( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
+        }
+    }
+
+    public static void error( IoSession session, String message )
+    {
+        Logger log = getLogger( session );
+        if( log.isErrorEnabled() )
+        {
+            log.error( String.valueOf( session.getAttribute( PREFIX ) ) + message );
+        }
+    }
+
+    public static void error( IoSession session, String message, Throwable cause )
+    {
+        Logger log = getLogger( session );
+        if( log.isErrorEnabled() )
+        {
+            log.error( String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
+        }
+    }
+    
+    public static boolean isDebugEnabled( IoSession session )
+    {
+        return getLogger( session ).isDebugEnabled();
+    }
+    
+    public static boolean isInfoEnabled( IoSession session )
+    {
+        return getLogger( session ).isInfoEnabled();
+    }
+    
+    public static boolean isWarnEnabled( IoSession session )
+    {
+        return getLogger( session ).isWarnEnabled();
+    }
+    
+    public static boolean isErrorEnabled( IoSession session )
+    {
+        return getLogger( session ).isErrorEnabled();
+    }
+
+    private static Logger getLogger( IoSession session )
+    {
+        Logger log = (Logger) session.getAttribute( LOGGER );
+        if( log == null )
+        {
+            log = LoggerFactory.getLogger( getClass( session ) );
+            String prefix = ( String ) session.getAttribute( PREFIX );
+            if( prefix == null )
+            {
+                prefix = "[" + session.getRemoteAddress() + "] ";
+                session.setAttribute( PREFIX, prefix );
+            }
+                
+            session.setAttribute( LOGGER, log );
+        }
+        
+        return log;
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java Wed Nov 30 21:17:41 2005
@@ -1,53 +1,53 @@
-/*
- *   @(#) $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.util;
-
-import java.net.SocketException;
-
-import org.apache.mina.common.IoSession;
-import org.apache.mina.transport.socket.nio.DatagramSession;
-import org.apache.mina.transport.socket.nio.SocketSession;
-
-/**
- * Exception utility.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class SessionUtil
-{
-    public static void initialize( IoSession session ) throws SocketException
-    {
-        if( session instanceof SocketSession )
-        {
-            SocketSession ss = ( SocketSession ) session;
-            ss.setReuseAddress( true );
-            ss.setKeepAlive( true );
-        }
-        else if( session instanceof DatagramSession )
-        {
-            DatagramSession ds = ( DatagramSession ) session;
-            ds.setReuseAddress( true );
-        }
-    }
-
-    private SessionUtil()
-    {
-    }
-}
+/*
+ *   @(#) $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.util;
+
+import java.net.SocketException;
+
+import org.apache.mina.common.IoSession;
+import org.apache.mina.transport.socket.nio.DatagramSession;
+import org.apache.mina.transport.socket.nio.SocketSession;
+
+/**
+ * Exception utility.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SessionUtil
+{
+    public static void initialize( IoSession session ) throws SocketException
+    {
+        if( session instanceof SocketSession )
+        {
+            SocketSession ss = ( SocketSession ) session;
+            ss.setReuseAddress( true );
+            ss.setKeepAlive( true );
+        }
+        else if( session instanceof DatagramSession )
+        {
+            DatagramSession ds = ( DatagramSession ) session;
+            ds.setReuseAddress( true );
+        }
+    }
+
+    private SessionUtil()
+    {
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/util/Stack.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/Stack.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/Stack.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/Stack.java Wed Nov 30 21:17:41 2005
@@ -1,151 +1,151 @@
-/*
- *   @(#) $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.util;
-
-import java.io.Serializable;
-import java.util.Arrays;
-
-/**
- * A unbounded stack.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class Stack implements Serializable
-{
-    private static final long serialVersionUID = 3546919169401434168L;
-
-	private static final int DEFAULT_CAPACITY = 4;
-
-    private Object[] items;
-
-    private int size = 0;
-
-    /**
-     * Construct a new, empty stack.
-     */
-    public Stack()
-    {
-        items = new Object[ DEFAULT_CAPACITY ];
-    }
-
-    /**
-     * Clears this stack.
-     */
-    public void clear()
-    {
-        Arrays.fill( items, null );
-        size = 0;
-    }
-
-    /**
-     * Pops from this stack.
-     * 
-     * @return <code>null</code>, if this stack is empty or the element is
-     *         really <code>null</code>.
-     */
-    public Object pop()
-    {
-        if( size == 0 )
-        {
-            return null;
-        }
-
-        int pos = size - 1;
-        Object ret = items[ pos ];
-        items[ pos ] = null;
-        size--;
-
-        return ret;
-    }
-
-    /**
-     * Push into this stack.
-     */
-    public void push( Object obj )
-    {
-        if( size == items.length )
-        {
-            // expand queue
-            final int oldLen = items.length;
-            Object[] tmp = new Object[ oldLen * 2 ];
-            System.arraycopy( items, 0, tmp, 0, size );
-            items = tmp;
-        }
-
-        items[ size ] = obj;
-        size++;
-    }
-
-    public void remove( Object o )
-    {
-        for( int i = size - 1; i >= 0; i-- )
-        {
-            if( items[ i ] == o )
-            {
-                System.arraycopy( items, i + 1, items, i, size - i - 1 );
-                items[ size - 1 ] = null;
-                size--;
-                break;
-            }
-        }
-    }
-
-    /**
-     * Returns the first element of the stack.
-     * 
-     * @return <code>null</code>, if the stack is empty, or the element is
-     *         really <code>null</code>.
-     */
-    public Object first()
-    {
-        if( size == 0 )
-        {
-            return null;
-        }
-
-        return items[ size - 1 ];
-    }
-
-    public Object last()
-    {
-        if( size == 0 )
-        {
-            return null;
-        }
-
-        return items[ 0 ];
-    }
-
-    /**
-     * Returns <code>true</code> if the stack is empty.
-     */
-    public boolean isEmpty()
-    {
-        return ( size == 0 );
-    }
-
-    /**
-     * Returns the number of elements in the stack.
-     */
-    public int size()
-    {
-        return size;
-    }
+/*
+ *   @(#) $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.util;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ * A unbounded stack.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class Stack implements Serializable
+{
+    private static final long serialVersionUID = 3546919169401434168L;
+
+	private static final int DEFAULT_CAPACITY = 4;
+
+    private Object[] items;
+
+    private int size = 0;
+
+    /**
+     * Construct a new, empty stack.
+     */
+    public Stack()
+    {
+        items = new Object[ DEFAULT_CAPACITY ];
+    }
+
+    /**
+     * Clears this stack.
+     */
+    public void clear()
+    {
+        Arrays.fill( items, null );
+        size = 0;
+    }
+
+    /**
+     * Pops from this stack.
+     * 
+     * @return <code>null</code>, if this stack is empty or the element is
+     *         really <code>null</code>.
+     */
+    public Object pop()
+    {
+        if( size == 0 )
+        {
+            return null;
+        }
+
+        int pos = size - 1;
+        Object ret = items[ pos ];
+        items[ pos ] = null;
+        size--;
+
+        return ret;
+    }
+
+    /**
+     * Push into this stack.
+     */
+    public void push( Object obj )
+    {
+        if( size == items.length )
+        {
+            // expand queue
+            final int oldLen = items.length;
+            Object[] tmp = new Object[ oldLen * 2 ];
+            System.arraycopy( items, 0, tmp, 0, size );
+            items = tmp;
+        }
+
+        items[ size ] = obj;
+        size++;
+    }
+
+    public void remove( Object o )
+    {
+        for( int i = size - 1; i >= 0; i-- )
+        {
+            if( items[ i ] == o )
+            {
+                System.arraycopy( items, i + 1, items, i, size - i - 1 );
+                items[ size - 1 ] = null;
+                size--;
+                break;
+            }
+        }
+    }
+
+    /**
+     * Returns the first element of the stack.
+     * 
+     * @return <code>null</code>, if the stack is empty, or the element is
+     *         really <code>null</code>.
+     */
+    public Object first()
+    {
+        if( size == 0 )
+        {
+            return null;
+        }
+
+        return items[ size - 1 ];
+    }
+
+    public Object last()
+    {
+        if( size == 0 )
+        {
+            return null;
+        }
+
+        return items[ 0 ];
+    }
+
+    /**
+     * Returns <code>true</code> if the stack is empty.
+     */
+    public boolean isEmpty()
+    {
+        return ( size == 0 );
+    }
+
+    /**
+     * Returns the number of elements in the stack.
+     */
+    public int size()
+    {
+        return size;
+    }
 }

Added: directory/network/trunk/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java?rev=350169&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java Wed Nov 30 21:17:41 2005
@@ -0,0 +1,153 @@
+/*
+ *   @(#) $Id: ExceptionMonitor.java 326586 2005-10-19 15:50:29Z trustin $
+ *
+ *   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;
+
+import java.util.Iterator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoFilterChain.Entry;
+
+/**
+ * Tests {@link DefaultIoFilterChainBuilder}.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DefaultIoFilterChainBuilderTest extends TestCase
+{
+    public static void main( String[] args )
+    {
+        junit.textui.TestRunner.run( DefaultIoFilterChainBuilderTest.class );
+    }
+
+    protected void setUp() throws Exception
+    {
+    }
+
+    protected void tearDown() throws Exception
+    {
+    }
+    
+    public void testAdd() throws Exception
+    {
+        DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+        
+        builder.addFirst( "A", new IoFilterAdapter() );
+        builder.addLast( "B", new IoFilterAdapter() );
+        builder.addFirst( "C", new IoFilterAdapter() );
+        builder.addLast( "D", new IoFilterAdapter() );
+        builder.addBefore( "B", "E", new IoFilterAdapter() );
+        builder.addBefore( "C", "F", new IoFilterAdapter() );
+        builder.addAfter( "B", "G", new IoFilterAdapter() );
+        builder.addAfter( "D", "H", new IoFilterAdapter() );
+        
+        String actual = "";
+        for( Iterator i = builder.getAll().iterator(); i.hasNext(); ) 
+        {
+            Entry e = ( Entry ) i.next();
+            actual += e.getName();
+        }
+        
+        Assert.assertEquals( "FCAEBGDH", actual );
+    }
+    
+    public void testGet() throws Exception
+    {
+        DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+        
+        IoFilter filterA = new IoFilterAdapter();
+        IoFilter filterB = new IoFilterAdapter();
+        IoFilter filterC = new IoFilterAdapter();
+        IoFilter filterD = new IoFilterAdapter();
+        
+        builder.addFirst( "A", filterA );
+        builder.addLast( "B", filterB );
+        builder.addBefore( "B", "C", filterC );
+        builder.addAfter( "A", "D", filterD );
+        
+        Assert.assertSame( filterA, builder.get( "A" ) );
+        Assert.assertSame( filterB, builder.get( "B" ) );
+        Assert.assertSame( filterC, builder.get( "C" ) );
+        Assert.assertSame( filterD, builder.get( "D" ) );
+    }
+    
+    public void testRemove() throws Exception
+    {
+        DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+        
+        builder.addLast( "A", new IoFilterAdapter() );
+        builder.addLast( "B", new IoFilterAdapter() );
+        builder.addLast( "C", new IoFilterAdapter() );
+        builder.addLast( "D", new IoFilterAdapter() );
+        builder.addLast( "E", new IoFilterAdapter() );
+        
+        builder.remove( "A" );
+        builder.remove( "E" );
+        builder.remove( "C" );
+        builder.remove( "B" );
+        builder.remove( "D" );
+        
+        Assert.assertEquals( 0, builder.getAll().size() );
+    }
+    
+    public void testClear() throws Exception
+    {
+        DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+        
+        builder.addLast( "A", new IoFilterAdapter() );
+        builder.addLast( "B", new IoFilterAdapter() );
+        builder.addLast( "C", new IoFilterAdapter() );
+        builder.addLast( "D", new IoFilterAdapter() );
+        builder.addLast( "E", new IoFilterAdapter() );
+        
+        builder.clear();
+        
+        Assert.assertEquals( 0, builder.getAll().size() );
+    }
+    
+    public void testToString()
+    {
+        DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+        
+        // When the chain is empty
+        Assert.assertEquals( "{ empty }", builder.toString() );
+        
+        // When there's one filter
+        builder.addLast( "A", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "B";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B) }", builder.toString() );
+        
+        // When there are two
+        builder.addLast( "C", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "D";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B), (C:D) }", builder.toString() );
+    }
+}



Mime
View raw message