directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r190245 - in /directory/network/branches/dirmina-39: ./ src/examples/org/apache/mina/examples/tennis/ src/java/org/apache/mina/common/ src/java/org/apache/mina/filter/ src/java/org/apache/mina/filter/codec/ src/java/org/apache/mina/transport/socket/nio/ src/java/org/apache/mina/transport/vmpipe/ src/test/org/apache/mina/common/ src/test/org/apache/mina/examples/echoserver/ src/test/org/apache/mina/filter/codec/
Date Sun, 12 Jun 2005 11:25:25 GMT
Author: trustin
Date: Sun Jun 12 04:25:23 2005
New Revision: 190245

URL: http://svn.apache.org/viewcvs?rev=190245&view=rev
Log:
Resolved DIRMINA-39

Added:
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/CloseFuture.java   (with props)
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java   (with props)
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFuture.java   (with props)
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/WriteFuture.java   (with props)
Modified:
    directory/network/branches/dirmina-39/project.xml
    directory/network/branches/dirmina-39/src/examples/org/apache/mina/examples/tennis/Main.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoConnector.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java
    directory/network/branches/dirmina-39/src/test/org/apache/mina/common/IoFilterChainTest.java
    directory/network/branches/dirmina-39/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
    directory/network/branches/dirmina-39/src/test/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java

Modified: directory/network/branches/dirmina-39/project.xml
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/project.xml?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/project.xml (original)
+++ directory/network/branches/dirmina-39/project.xml Sun Jun 12 04:25:23 2005
@@ -71,13 +71,6 @@
 
   <dependencies>
 
-    <dependency>
-      <groupId>concurrent</groupId>
-      <artifactId>concurrent</artifactId>
-      <version>1.3.4</version>
-      <url>http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html</url>
-    </dependency>
-
     <!-- ========================================================= -->
     <!-- Dependencies required for running test cases and examples -->
     <!-- ========================================================= -->

Modified: directory/network/branches/dirmina-39/src/examples/org/apache/mina/examples/tennis/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/examples/org/apache/mina/examples/tennis/Main.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/examples/org/apache/mina/examples/tennis/Main.java (original)
+++ directory/network/branches/dirmina-39/src/examples/org/apache/mina/examples/tennis/Main.java Sun Jun 12 04:25:23 2005
@@ -3,6 +3,7 @@
  */
 package org.apache.mina.examples.tennis;
 
+import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.registry.Service;
@@ -40,8 +41,10 @@
 
         // Connect to the server.
         VmPipeConnector connector = new VmPipeConnector();
-        IoSession session = connector.connect( address,
-                                                     new TennisPlayer() );
+        ConnectFuture future = connector.connect( address,
+                                                  new TennisPlayer() );
+        future.join();
+        IoSession session = future.getSession();
 
         // Send the first ping message
         session.write( new TennisBall( 10 ) );

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java Sun Jun 12 04:25:23 2005
@@ -26,10 +26,9 @@
 import java.util.Map;
 
 import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.ByteBufferUtil;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * An abstract implementation of {@link IoFilterChain} that provides
  * common operations for developers to extend protocol layer.
@@ -42,9 +41,9 @@
  * </ul>
  * 
  * The only method a developer should implement is
- * {@link #doWrite(IoSession, Object, FutureResult)}.  This method is invoked
+ * {@link #doWrite(IoSession, WriteRequest)}.  This method is invoked
  * when filter chain is evaluated for
- * {@link IoFilter#filterWrite(NextFilter, IoSession, Object, FutureResult)} and 
+ * {@link IoFilter#filterWrite(NextFilter, IoSession, WriteRequest)} and 
  * finally to be written out.
  * 
  * @author The Apache Directory Project
@@ -109,23 +108,18 @@
             }
             
             public void filterWrite( NextFilter nextFilter, IoSession session,
-                                     Object message, FutureResult future )
+                                     WriteRequest writeRequest )
             {
-                if( message == null )
-                {
-                    throw new NullPointerException( "Filtered message is null" );
-                }
-
-                if( session.getTransportType().getEnvelopeType().isAssignableFrom( message.getClass() ) )
+                if( session.getTransportType().getEnvelopeType().isAssignableFrom( writeRequest.getMessage().getClass() ) )
                 {
-                    doWrite( session, message, future );
+                    doWrite( session, writeRequest );
                 }
                 else
                 {
                     throw new IllegalStateException(
                             "Write requests must be transformed to " + 
                             session.getTransportType().getEnvelopeType() +
-                            ": " + message );
+                            ": " + writeRequest );
                 }
             }
         };
@@ -187,10 +181,9 @@
             }
 
             public void filterWrite( NextFilter nextFilter,
-                                     IoSession session, Object message,
-                                     FutureResult future ) throws Exception
+                                     IoSession session, WriteRequest writeRequest ) throws Exception
             {
-                nextFilter.filterWrite( session, message, future );
+                nextFilter.filterWrite( session, writeRequest );
             }
         };
     }
@@ -440,24 +433,19 @@
         }
     }
     
-    public void filterWrite( IoSession session, Object message, FutureResult future )
+    public void filterWrite( IoSession session, WriteRequest writeRequest )
     {
         Entry tail = this.tail;
-        callPreviousFilterWrite( tail, session, message, future );
+        callPreviousFilterWrite( tail, session, writeRequest );
     }
 
     private void callPreviousFilterWrite( Entry entry,
                                           IoSession session,
-                                          Object message, FutureResult future )
+                                          WriteRequest writeRequest )
     {
-        if( message == null )
-        {
-            return;
-        }
-        
         try
         {
-            entry.filter.filterWrite( entry.nextFilter, session, message, future );
+            entry.filter.filterWrite( entry.nextFilter, session, writeRequest );
         }
         catch( Throwable e )
         {
@@ -490,7 +478,7 @@
         return list;
     }
     
-    protected abstract void doWrite( IoSession session, Object message, FutureResult future );
+    protected abstract void doWrite( IoSession session, WriteRequest writeRequest );
 
     private class Entry
     {
@@ -560,10 +548,10 @@
                     callNextMessageSent( nextEntry, session, message );
                 }
                 
-                public void filterWrite( IoSession session, Object message, FutureResult future )
+                public void filterWrite( IoSession session, WriteRequest writeRequest )
                 {
                     Entry nextEntry = Entry.this.prevEntry;
-                    callPreviousFilterWrite( nextEntry, session, message, future );
+                    callPreviousFilterWrite( nextEntry, session, writeRequest );
                 }
             };
         }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java Sun Jun 12 04:25:23 2005
@@ -33,11 +33,10 @@
 import java.nio.charset.CoderResult;
 
 import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 import org.apache.mina.util.Stack;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * A pooled byte buffer used by MINA applications.
  * <p>
@@ -76,7 +75,7 @@
  * because MINA will release it automatically when:
  * <ul>
  *   <li>You pass the buffer by calling {@link IoSession#write(Object)}.</li>
- *   <li>You pass the buffer by calling {@link NextFilter#filterWrite(IoSession,Object,FutureResult)}.</li>
+ *   <li>You pass the buffer by calling {@link NextFilter#filterWrite(IoSession,WriteRequest)}.</li>
  *   <li>You pass the buffer by calling {@link ProtocolEncoderOutput#write(ByteBuffer)}.</li>
  * </ul>
  * And, you don't need to release any {@link ByteBuffer} which is passed as a parameter

Added: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/CloseFuture.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/CloseFuture.java?rev=190245&view=auto
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/CloseFuture.java (added)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/CloseFuture.java Sun Jun 12 04:25:23 2005
@@ -0,0 +1,21 @@
+package org.apache.mina.common;
+
+public class CloseFuture extends IoFuture
+{
+    public boolean isClosed()
+    {
+        if( isReady() )
+        {
+            return ( ( Boolean ) getValue() ).booleanValue();
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    public void setClosed( boolean closed )
+    {
+        setValue( closed? Boolean.TRUE : Boolean.FALSE );
+    }
+}

Propchange: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/CloseFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java?rev=190245&view=auto
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java (added)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java Sun Jun 12 04:25:23 2005
@@ -0,0 +1,32 @@
+package org.apache.mina.common;
+
+import java.io.IOException;
+
+import org.apache.mina.util.ExceptionUtil;
+
+public class ConnectFuture extends IoFuture
+{
+    public IoSession getSession() throws IOException
+    {
+        Object v = getValue();
+        if( v instanceof Throwable )
+        {
+            ExceptionUtil.throwException( ( Throwable ) v );
+            throw new InternalError(); // this cannot be executed
+        }
+        else
+        {
+            return ( IoSession ) v;
+        }
+    }
+    
+    public void setSession( IoSession session )
+    {
+        setValue( session );
+    }
+    
+    public void setException( Throwable exception )
+    {
+        setValue( exception );
+    }
+}

Propchange: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoConnector.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoConnector.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoConnector.java Sun Jun 12 04:25:23 2005
@@ -45,23 +45,23 @@
     /**
      * Connects to the specified <code>address</code>.  If communication starts
      * successfully, events are fired to the specified
-     * <code>handler</code>.  This method blocks.
+     * <code>handler</code>.
      * 
      * @throws IOException if failed to connect
      */
-    IoSession connect( SocketAddress address, IoHandler handler )
+    ConnectFuture connect( SocketAddress address, IoHandler handler )
             throws IOException;
 
     /**
      * Connects to the specified <code>address</code>.  If communication starts
      * successfully, events are fired to the specified
-     * <code>handler</code>.  This method blocks.
+     * <code>handler</code>.
      * 
      * @param localAddress the local address the channel is bound to
      * @throws IOException if failed to connect
      */
-    IoSession connect( SocketAddress address, SocketAddress localAddress,
-                       IoHandler handler ) throws IOException;
+    ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
+                           IoHandler handler ) throws IOException;
 
     /**
      * Connects to the specified <code>address</code> with timeout.  If
@@ -70,7 +70,7 @@
      * 
      * @throws IOException if failed to connect
      */
-    IoSession connect( SocketAddress address, int timeout, IoHandler handler )
+    ConnectFuture connect( SocketAddress address, int timeout, IoHandler handler )
             throws IOException;
     
     /**
@@ -81,6 +81,6 @@
      * @param localAddress the local address the channel is bound to
      * @throws IOException if failed to connect
      */
-    IoSession connect( SocketAddress address, SocketAddress localAddress,
-                       int timeout, IoHandler handler ) throws IOException;
+    ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
+                           int timeout, IoHandler handler ) throws IOException;
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java Sun Jun 12 04:25:23 2005
@@ -18,7 +18,6 @@
  */
 package org.apache.mina.common;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
 
 
 /**
@@ -85,7 +84,7 @@
     /**
      * Filters {@link IoSession#write(Object)} method invocation.
      */
-    void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult future ) throws Exception;
+    void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest ) throws Exception;
     
     public interface NextFilter
     {
@@ -95,6 +94,53 @@
         void exceptionCaught( IoSession session, Throwable cause );
         void messageReceived( IoSession session, Object message );
         void messageSent( IoSession session, Object message );
-        void filterWrite( IoSession session, Object message, FutureResult future );
+        void filterWrite( IoSession session, WriteRequest writeRequest );
+    }
+    
+    /**
+     * TODO doeument me
+     */
+    public static class WriteRequest
+    {
+        private static final WriteFuture UNUSED_FUTURE = new WriteFuture();
+        
+        private final Object message;
+        private final WriteFuture future;
+        
+        public WriteRequest( Object message )
+        {
+            this( message, null );
+        }
+
+        public WriteRequest( Object message, WriteFuture future )
+        {
+            if( message == null )
+            {
+                throw new NullPointerException( "message" );
+            }
+            
+            if( future == null )
+            {
+                future = UNUSED_FUTURE;
+            }
+            
+            this.message = message;
+            this.future = future;
+        }
+
+        public WriteFuture getFuture()
+        {
+            return future;
+        }
+
+        public Object getMessage()
+        {
+            return message;
+        }
+        
+        public String toString()
+        {
+            return message.toString();
+        }
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java Sun Jun 12 04:25:23 2005
@@ -18,8 +18,6 @@
  */
 package org.apache.mina.common;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 
 /**
  * An abstract adapter class for {@link IoFilter}.  You can extend
@@ -61,8 +59,8 @@
         nextFilter.messageSent( session, message );
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult future ) throws Exception
+    public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest ) throws Exception
     {
-        nextFilter.filterWrite( session, message, future );
+        nextFilter.filterWrite( session, writeRequest );
     }
 }

Added: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFuture.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFuture.java?rev=190245&view=auto
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFuture.java (added)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFuture.java Sun Jun 12 04:25:23 2005
@@ -0,0 +1,80 @@
+package org.apache.mina.common;
+
+
+public class IoFuture
+{
+    private Object result;
+    private boolean ready;
+
+    protected IoFuture()
+    {
+    }
+
+    public synchronized void join()
+    {
+        while( !ready )
+        {
+            try
+            {
+                wait();
+            }
+            catch( InterruptedException e )
+            {
+            }
+        }
+    }
+
+    public synchronized boolean join( long timeoutInMillis )
+    {
+        long startTime = ( timeoutInMillis <= 0 ) ? 0 : System
+                .currentTimeMillis();
+        long waitTime = timeoutInMillis;
+        if( ready )
+        {
+            return ready;
+        }
+        else if( waitTime <= 0 )
+        {
+            return ready;
+        }
+
+        for( ;; )
+        {
+            try
+            {
+                wait( waitTime );
+            }
+            catch( InterruptedException e )
+            {
+            }
+
+            if( ready )
+                return true;
+            else
+            {
+                waitTime = timeoutInMillis - ( System.currentTimeMillis() - startTime );
+                if( waitTime <= 0 )
+                {
+                    return ready;
+                }
+            }
+        }
+    }
+
+    public synchronized boolean isReady()
+    {
+        return ready;
+    }
+
+    protected synchronized void setValue( Object newValue )
+    {
+        result = newValue;
+        ready = true;
+        notifyAll();
+    }
+
+    protected synchronized Object getValue()
+    {
+        return result;
+    }
+}

Propchange: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java Sun Jun 12 04:25:23 2005
@@ -21,8 +21,6 @@
 import java.net.SocketAddress;
 import java.util.Set;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * A handle which represents connection between two endpoints regardless of 
  * transport types.
@@ -51,17 +49,17 @@
      * Writes the specified <code>message</code> to remote peer.  This
      * operation is asynchronous; {@link IoHandler#messageSent(IoSession, Object)}
      * will be invoked when the message is actually sent to remote peer.
-     * You can also ait for the returned {@link FutureResult} if you want
+     * You can also ait for the returned {@link WriteFuture} if you want
      * to wait for the session actually closed.
      */
-    FutureResult write( Object message );
+    WriteFuture write( Object message );
 
     /**
      * Closes this session immediately.  This operation is asynthronous.
-     * Wait for the returned {@link FutureResult} if you want to wait for
+     * Wait for the returned {@link CloseFuture} if you want to wait for
      * the session actually closed.
      */
-    FutureResult close();
+    CloseFuture close();
 
     /**
      * Returns an attachment of this session.

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java Sun Jun 12 04:25:23 2005
@@ -18,7 +18,7 @@
  */
 package org.apache.mina.common;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+import org.apache.mina.common.IoFilter.WriteRequest;
 
 /**
  * An {@link IoFilterChain} that forwards <tt>filterWrite</tt>
@@ -39,8 +39,8 @@
         this.managerChain = managerChain;
     }
     
-    protected void doWrite( IoSession session, Object message, FutureResult future )
+    protected void doWrite( IoSession session, WriteRequest writeRequest )
     {
-        managerChain.filterWrite( session, message, future );
+        managerChain.filterWrite( session, writeRequest );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java Sun Jun 12 04:25:23 2005
@@ -18,7 +18,6 @@
  */
 package org.apache.mina.common;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
 
 /**
  * An {@link IoFilterChain} that forwards all events
@@ -84,10 +83,9 @@
             }
 
             public void filterWrite( NextFilter nextFilter,
-                                     IoSession session, Object message,
-                                     FutureResult future )
+                                     IoSession session, WriteRequest writeRequest )
             {
-                nextFilter.filterWrite( session, message, future );
+                nextFilter.filterWrite( session, writeRequest );
             }
         };
     }

Added: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/WriteFuture.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/WriteFuture.java?rev=190245&view=auto
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/WriteFuture.java (added)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/WriteFuture.java Sun Jun 12 04:25:23 2005
@@ -0,0 +1,21 @@
+package org.apache.mina.common;
+
+public class WriteFuture extends IoFuture
+{
+    public boolean isWritten()
+    {
+        if( isReady() )
+        {
+            return ( ( Boolean ) getValue() ).booleanValue();
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    public void setWritten( boolean written )
+    {
+        setValue( written? Boolean.TRUE : Boolean.FALSE );
+    }
+}

Propchange: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/WriteFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java Sun Jun 12 04:25:23 2005
@@ -26,8 +26,6 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.SessionLog;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * Logs all MINA protocol events to {@link Logger}.
  * 
@@ -113,9 +111,9 @@
         nextFilter.messageSent( session, message );
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult future )
+    public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest )
     {
-        SessionLog.log( defaultLevel, session, "WRITE: " + message );
-        nextFilter.filterWrite( session, message, future );
+        SessionLog.log( defaultLevel, session, "WRITE: " + writeRequest );
+        nextFilter.filterWrite( session, writeRequest );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java Sun Jun 12 04:25:23 2005
@@ -32,8 +32,6 @@
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * An SSL filter that encrypts and decrypts the data exchanged in the session.
  * This filter uses an {@link SSLEngine} which was introduced in Java 5, so 
@@ -295,9 +293,9 @@
         }
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult future ) throws SSLException
+    public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest ) throws SSLException
     {
-        ByteBuffer buf = ( ByteBuffer ) message;
+        ByteBuffer buf = ( ByteBuffer ) writeRequest.getMessage();
 
         SSLHandler handler = createSSLSessionHandler( nextFilter, session );
         if( log.isLoggable( Level.FINEST ) )
@@ -314,7 +312,7 @@
                 {
                     log.log( Level.FINEST, session + "   already encrypted: " + buf );
                 }
-                nextFilter.filterWrite( session, buf, future );
+                nextFilter.filterWrite( session, writeRequest );
                 return;
             }
             
@@ -336,7 +334,7 @@
                 {
                     log.log( Level.FINEST, session + " encrypted buf: " + encryptedBuffer);
                 }
-                nextFilter.filterWrite( session, encryptedBuffer, future );
+                nextFilter.filterWrite( session, new WriteRequest( encryptedBuffer, writeRequest.getFuture() ) );
                 return;
             }
             else
@@ -354,7 +352,7 @@
                     {
                         log.log( Level.FINEST, session + " Handshaking is not complete yet. Buffering write request." );
                     }
-                    handler.scheduleWrite( nextFilter, buf, future );
+                    handler.scheduleWrite( nextFilter, writeRequest );
                 }
             }
         }
@@ -430,8 +428,7 @@
             }
             //debug("outNetBuffer (after copy): {0}", sslHandler.getOutNetBuffer());
             
-            // TODO: FutureResult is not used here. Can we reuse it?
-            filterWrite( nextFilter, session, writeBuffer, new FutureResult() );
+            filterWrite( nextFilter, session, new WriteRequest( writeBuffer, null ) );
 
             // loop while more writes required to complete handshake
             while( sslHandler.needToCompleteInitialHandshake() )

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java Sun Jun 12 04:25:23 2005
@@ -30,10 +30,9 @@
 
 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.Queue;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * A helper class using the SSLEngine API to decrypt/encrypt data.
  * <p>
@@ -185,9 +184,9 @@
         return ( initialHandshakeStatus == SSLEngineResult.HandshakeStatus.NEED_WRAP && !closed );
     }
     
-    public synchronized void scheduleWrite( NextFilter nextFilter, org.apache.mina.common.ByteBuffer buf, FutureResult future )
+    public synchronized void scheduleWrite( NextFilter nextFilter, WriteRequest writeRequest )
     {
-        scheduledWrites.push( new ScheduledWrite( nextFilter, buf, future ) );
+        scheduledWrites.push( new ScheduledWrite( nextFilter, writeRequest ) );
     }
     
     public synchronized void flushScheduledWrites() throws SSLException
@@ -198,9 +197,9 @@
         {
             if( log.isLoggable( Level.FINEST ) )
             {
-                log.log( Level.FINEST, session + " Flushing buffered write request: " + scheduledWrite.buf );
+                log.log( Level.FINEST, session + " Flushing buffered write request: " + scheduledWrite.writeRequest );
             }
-            parent.filterWrite( scheduledWrite.nextFilter, session, scheduledWrite.buf, scheduledWrite.future );
+            parent.filterWrite( scheduledWrite.nextFilter, session, scheduledWrite.writeRequest );
         }
     }
 
@@ -669,14 +668,12 @@
     private static class ScheduledWrite
     {
         private final NextFilter nextFilter;
-        private final org.apache.mina.common.ByteBuffer buf;
-        private final FutureResult future; 
+        private final WriteRequest writeRequest;
         
-        public ScheduledWrite( NextFilter nextFilter, org.apache.mina.common.ByteBuffer buf, FutureResult future )
+        public ScheduledWrite( NextFilter nextFilter, WriteRequest writeRequest )
         {
             this.nextFilter = nextFilter;
-            this.buf = buf;
-            this.future = future;
+            this.writeRequest = writeRequest;
         }
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java Sun Jun 12 04:25:23 2005
@@ -27,8 +27,6 @@
 import org.apache.mina.util.EventType;
 import org.apache.mina.util.ThreadPool;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * A Thread-pooling filter.  This filter forwards {@link IoHandler} events
  * to its thread pool.
@@ -120,8 +118,8 @@
         }
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult future )
+    public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest )
     {
-        nextFilter.filterWrite( session, message, future );
+        nextFilter.filterWrite( session, writeRequest );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Sun Jun 12 04:25:23 2005
@@ -4,10 +4,9 @@
 import org.apache.mina.common.ByteBufferProxy;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
 import org.apache.mina.util.Queue;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 public class ProtocolCodecFilter extends IoFilterAdapter
 {
     public static final String ENCODER = ProtocolCodecFilter.class.getName() + ".encoder";
@@ -76,20 +75,16 @@
         }
     }
     
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult future ) throws Exception
+    public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest ) throws Exception
     {
         ProtocolEncoder encoder = getEncoder( session );
-        if( message == null )
-        {
-            throw new NullPointerException( "message" );
-        }
-
         ProtocolEncoderOutputImpl encoderOut = getEncoderOut( session );
         encoderOut.nextFilter = nextFilter;
-        encoderOut.message = message;
-        encoderOut.future = future;
         
-        encoder.encode( session, message, encoderOut );
+        encoder.encode( session, writeRequest.getMessage(), encoderOut );
+
+        encoderOut.message = writeRequest.getMessage();
+        encoderOut.future = writeRequest.getFuture();
         encoderOut.flush();
     }
     
@@ -153,17 +148,27 @@
         private final IoSession session;
         private NextFilter nextFilter;
         private Object message;
-        private FutureResult future;
+        private WriteFuture future;
         
         public ProtocolEncoderOutputImpl( IoSession session )
         {
             this.session = session;
         }
 
-        protected FutureResult doFlush( ByteBuffer buf )
+        protected WriteFuture doFlush( ByteBuffer buf )
         {
-            nextFilter.filterWrite( session, new MessageByteBuffer( buf, message ), future );
-            return null;
+            WriteFuture future;
+            if( message != null )
+            {
+                future = this.future;
+                nextFilter.filterWrite( session, new WriteRequest( new MessageByteBuffer( buf, message ), future ) );
+            }
+            else
+            {
+                future = new WriteFuture();
+                nextFilter.filterWrite( session, new WriteRequest( buf, future ) );
+            }
+            return future;
         }
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java Sun Jun 12 04:25:23 2005
@@ -19,8 +19,7 @@
 package org.apache.mina.filter.codec;
 
 import org.apache.mina.common.ByteBuffer;
-
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+import org.apache.mina.common.WriteFuture;
 
 /**
  * Callback for {@link ProtocolEncoder} to generate encoded {@link ByteBuffer}s.
@@ -52,8 +51,8 @@
     /**
      * Flushes all buffers you wrote via {@link #write(ByteBuffer)} to
      * the session.  This operation is asynchronous; please wait for
-     * the returned {@link FutureResult} if you want to wait for
+     * the returned {@link WriteFuture} if you want to wait for
      * the buffers flushed.
      */
-    FutureResult flush();
+    WriteFuture flush();
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java Sun Jun 12 04:25:23 2005
@@ -4,10 +4,9 @@
 package org.apache.mina.filter.codec;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.WriteFuture;
 import org.apache.mina.util.Queue;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * A {@link ProtocolEncoderOutput} based on queue.
  *
@@ -71,30 +70,35 @@
         bufferQueue.push(newBuf);
     }
     
-    public FutureResult flush()
+    public WriteFuture flush()
     {
         Queue bufferQueue = this.bufferQueue;
-        FutureResult future = null;
-        for( ;; )
+        WriteFuture future = null;
+        if( bufferQueue.isEmpty() )
         {
-            ByteBuffer buf = ( ByteBuffer ) bufferQueue.pop();
-            if( buf == null )
+            future = doFlush( ByteBuffer.allocate( 0 ).flip() ); // write zero bytes
+        }
+        else
+        {
+            for( ;; )
             {
-                break;
+                ByteBuffer buf = ( ByteBuffer ) bufferQueue.pop();
+                if( buf == null )
+                {
+                    break;
+                }
+                
+                future = doFlush( buf );
             }
-            
-            future = doFlush( buf );
         }
         
         if( future == null )
         {
-            // Nothing is written; future is now.
-            future = new FutureResult();
-            future.set( Boolean.FALSE );
+            throw new IllegalStateException( "doFlush must return future." );
         }
         
         return future;
     }
     
-    protected abstract FutureResult doFlush( ByteBuffer buf );
+    protected abstract WriteFuture doFlush( ByteBuffer buf );
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java Sun Jun 12 04:25:23 2005
@@ -34,6 +34,7 @@
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSessionManagerFilterChain;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.ExceptionUtil;
 import org.apache.mina.util.Queue;
 
@@ -360,27 +361,29 @@
     {
         DatagramChannel ch = session.getChannel();
 
-        Queue writeBufferQueue = session.getWriteBufferQueue();
+        Queue writeRequestQueue = session.getWriteRequestQueue();
 
-        ByteBuffer buf;
+        WriteRequest req;
         for( ;; )
         {
-            synchronized( writeBufferQueue )
+            synchronized( writeRequestQueue )
             {
-                buf = ( ByteBuffer ) writeBufferQueue.first();
+                req = ( WriteRequest ) writeRequestQueue.first();
             }
 
-            if( buf == null )
+            if( req == null )
                 break;
 
+            ByteBuffer buf = ( ByteBuffer ) req.getMessage();
             if( buf.remaining() == 0 )
             {
                 // pop and fire event
-                synchronized( writeBufferQueue )
+                synchronized( writeRequestQueue )
                 {
-                    writeBufferQueue.pop();
+                    writeRequestQueue.pop();
                 }
 
+                req.getFuture().setWritten( true );
                 session.getManagerFilterChain().messageSent( session, buf );
                 continue;
             }
@@ -401,12 +404,13 @@
                                  & ( ~SelectionKey.OP_WRITE ) );
 
                 // pop and fire event
-                synchronized( writeBufferQueue )
+                synchronized( writeRequestQueue )
                 {
-                    writeBufferQueue.pop();
+                    writeRequestQueue.pop();
                 }
 
                 session.increaseWrittenBytes( writtenBytes );
+                req.getFuture().setWritten( true );
                 session.getManagerFilterChain().messageSent( session, buf.position( pos ) );
             }
         }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java Sun Jun 12 04:25:23 2005
@@ -28,12 +28,12 @@
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionManagerFilterChain;
-import org.apache.mina.util.ExceptionUtil;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.Queue;
 
 /**
@@ -68,22 +68,22 @@
     {
     }
 
-    public IoSession connect( SocketAddress address, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, IoHandler handler ) throws IOException
     {
         return connect( address, null, handler);
     }
 
-    public IoSession connect( SocketAddress address, int timeout, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, int timeout, IoHandler handler ) throws IOException
     {
         return connect( address, null, handler );
     }
 
-    public IoSession connect( SocketAddress address, SocketAddress localAddress, int timeout, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, int timeout, IoHandler handler ) throws IOException
     {
         return connect( address, localAddress, handler );
     }
 
-    public IoSession connect( SocketAddress address, SocketAddress localAddress,
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
                               IoHandler handler ) throws IOException
     {
         if( address == null )
@@ -133,27 +133,7 @@
         }
 
         selector.wakeup();
-
-        synchronized( request )
-        {
-            while( !request.done )
-            {
-                try
-                {
-                    request.wait();
-                }
-                catch( InterruptedException e )
-                {
-                }
-            }
-        }
-        
-        if( request.exception != null )
-        {
-            ExceptionUtil.throwException( request.exception );
-        }
-
-        return request.session;
+        return request;
     }
     
     private synchronized void startupWorker() throws IOException
@@ -357,27 +337,29 @@
     {
         DatagramChannel ch = session.getChannel();
 
-        Queue writeBufferQueue = session.getWriteBufferQueue();
+        Queue writeRequestQueue = session.getWriteRequestQueue();
 
-        ByteBuffer buf;
+        WriteRequest req;
         for( ;; )
         {
-            synchronized( writeBufferQueue )
+            synchronized( writeRequestQueue )
             {
-                buf = ( ByteBuffer ) writeBufferQueue.first();
+                req = ( WriteRequest ) writeRequestQueue.first();
             }
 
-            if( buf == null )
+            if( req == null )
                 break;
 
+            ByteBuffer buf = ( ByteBuffer ) req.getMessage();
             if( buf.remaining() == 0 )
             {
                 // pop and fire event
-                synchronized( writeBufferQueue )
+                synchronized( writeRequestQueue )
                 {
-                    writeBufferQueue.pop();
+                    writeRequestQueue.pop();
                 }
 
+                req.getFuture().setWritten( true );
                 session.getManagerFilterChain().messageSent( session, buf );
                 continue;
             }
@@ -397,12 +379,13 @@
                                  & ( ~SelectionKey.OP_WRITE ) );
 
                 // pop and fire event
-                synchronized( writeBufferQueue )
+                synchronized( writeRequestQueue )
                 {
-                    writeBufferQueue.pop();
+                    writeRequestQueue.pop();
                 }
 
                 session.increaseWrittenBytes( writtenBytes );
+                req.getFuture().setWritten( true );
                 session.getManagerFilterChain().messageSent( session, buf.position( pos ) );
             }
         }
@@ -427,6 +410,7 @@
             DatagramSession session = new DatagramSession(
                     filters, req.channel, req.handler );
 
+            boolean success = false;
             try
             {
                 req.handler.sessionCreated( session );
@@ -435,21 +419,17 @@
                         SelectionKey.OP_READ, session );
     
                 session.setSelectionKey( key );
+
+                req.setSession( session );
+                success = true;
             }
             catch( Throwable t )
             {
-                req.exception = t;
+                req.setException( t );
             }
             finally 
             {
-                synchronized( req )
-                {
-                    req.done = true;
-                    req.session = session;
-                    req.notify();
-                }
-                
-                if( req.exception != null )
+                if( !success )
                 {
                     try
                     {
@@ -503,17 +483,11 @@
         return filters;
     }
 
-    private static class RegistrationRequest
+    private static class RegistrationRequest extends ConnectFuture
     {
         private final DatagramChannel channel;
 
         private final IoHandler handler;
-        
-        private boolean done;
-        
-        private DatagramSession session;
-        
-        private Throwable exception;
 
         private RegistrationRequest( DatagramChannel channel,
                                      IoHandler handler )

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java Sun Jun 12 04:25:23 2005
@@ -23,6 +23,7 @@
 import java.nio.channels.SelectionKey;
 
 import org.apache.mina.common.BaseIoSession;
+import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
@@ -31,10 +32,10 @@
 import org.apache.mina.common.IoSessionManager;
 import org.apache.mina.common.IoSessionManagerFilterChain;
 import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.Queue;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * An {@link IoSession} for datagram transport (UDP/IP).
  * 
@@ -51,7 +52,7 @@
 
     private final DatagramSessionConfig config;
 
-    private final Queue writeBufferQueue;
+    private final Queue writeRequestQueue;
 
     private final IoHandler handler;
 
@@ -61,7 +62,7 @@
 
     private SelectionKey key;
     
-    private final FutureResult closeFuture = new FutureResult();
+    private final CloseFuture closeFuture = new CloseFuture();
 
     /**
      * Creates a new instance.
@@ -73,7 +74,7 @@
         this.filterChain = new IoSessionFilterChain( managerFilterChain );
         this.ch = ch;
         this.config = new DatagramSessionConfig( ch );
-        this.writeBufferQueue = new Queue();
+        this.writeRequestQueue = new Queue();
         this.handler = defaultHandler;
         this.remoteAddress = ch.socket().getRemoteSocketAddress();
         this.localAddress = ch.socket().getLocalSocketAddress();
@@ -109,7 +110,12 @@
         return handler;
     }
     
-    public synchronized FutureResult close()
+    public void notifyClose()
+    {
+        closeFuture.setClosed( true );
+    }
+    
+    public CloseFuture close()
     {
         if( !closeFuture.isReady() )
         {
@@ -120,21 +126,21 @@
             }
             else
             {
-                closeFuture.set( Boolean.TRUE );
+                closeFuture.setClosed( true );
             }
         }
         return closeFuture;
     }
 
-    Queue getWriteBufferQueue()
+    Queue getWriteRequestQueue()
     {
-        return writeBufferQueue;
+        return writeRequestQueue;
     }
 
-    public FutureResult write( Object message )
+    public WriteFuture write( Object message )
     {
-        FutureResult future = new FutureResult();
-        filterChain.filterWrite( this, message, future );
+        WriteFuture future = new WriteFuture();
+        filterChain.filterWrite( this, new WriteRequest( message, future ) );
         return future;
     }
 

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java Sun Jun 12 04:25:23 2005
@@ -3,10 +3,9 @@
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionManagerFilterChain;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.Queue;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * An {@link IoFilterChain} for datagram transport (UDP/IP).
  * 
@@ -19,16 +18,16 @@
         super( processor );
     }
     
-    protected void doWrite( IoSession session, Object message, FutureResult future )
+    protected void doWrite( IoSession session, WriteRequest writeRequest )
     {
         DatagramSession s = ( DatagramSession ) session;
-        Queue writeBufferQueue = s.getWriteBufferQueue();
+        Queue writeRequestQueue = s.getWriteRequestQueue();
         
-        synchronized( writeBufferQueue )
+        synchronized( writeRequestQueue )
         {
-            writeBufferQueue.push( message );
+            writeRequestQueue.push( writeRequest );
         }
 
-        ( ( DatagramSessionManager ) getManager() ).flushSession( s, future );
+        ( ( DatagramSessionManager ) getManager() ).flushSession( s );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java Sun Jun 12 04:25:23 2005
@@ -29,10 +29,10 @@
 import java.util.Set;
 
 import org.apache.mina.common.BaseIoSessionManager;
+import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionManagerFilterChain;
 import org.apache.mina.util.ExceptionUtil;
 import org.apache.mina.util.Queue;
@@ -64,22 +64,22 @@
     {
     }
 
-    public IoSession connect( SocketAddress address, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, IoHandler handler ) throws IOException
     {
         return connect( address, null, Integer.MAX_VALUE, handler);
     }
 
-    public IoSession connect( SocketAddress address, SocketAddress localAddress, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler handler ) throws IOException
     {
         return connect( address, localAddress, Integer.MAX_VALUE, handler);
     }
 
-    public IoSession connect( SocketAddress address, int timeout, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, int timeout, IoHandler handler ) throws IOException
     {
         return connect( address, null, timeout, handler);
     }
 
-    public IoSession connect( SocketAddress address, SocketAddress localAddress,
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
                               int timeout, IoHandler handler ) throws IOException
     {
         if( address == null )
@@ -114,7 +114,9 @@
             {
                 SocketSession session = newSession( ch, handler );
                 success = true;
-                return session;
+                ConnectFuture future = new ConnectFuture();
+                future.setSession( session );
+                return future;
             }
             
             success = true;
@@ -137,27 +139,8 @@
             startupWorker();
         }
         selector.wakeup();
-
-        synchronized( request )
-        {
-            while( !request.done )
-            {
-                try
-                {
-                    request.wait();
-                }
-                catch( InterruptedException e )
-                {
-                }
-            }
-        }
-
-        if( request.exception != null )
-        {
-            ExceptionUtil.throwException( request.exception );
-        }
-
-        return request.session;
+        
+        return request;
     }
     
     private synchronized void startupWorker() throws IOException
@@ -193,12 +176,7 @@
             }
             catch( IOException e )
             {
-                req.exception = e;
-                synchronized( req )
-                {
-                    req.done = true;
-                    req.notify();
-                }
+                req.setException( e );
             }
         }
     }
@@ -217,20 +195,22 @@
             SocketChannel ch = ( SocketChannel ) key.channel();
             ConnectionRequest entry = ( ConnectionRequest ) key.attachment();
 
+            boolean success = false;
             try
             {
                 ch.finishConnect();
                 SocketSession session = newSession( ch, entry.handler );
-                entry.session = session;
+                entry.setSession( session );
+                success = true;
             }
             catch( Throwable e )
             {
-                entry.exception = e;
+                entry.setException( e );
             }
             finally
             {
                 key.cancel();
-                if( entry.session == null )
+                if( !success )
                 {
                     try
                     {
@@ -241,12 +221,6 @@
                         exceptionMonitor.exceptionCaught( this, e );
                     }
                 }
-
-                synchronized( entry )
-                {
-                    entry.done = true;
-                    entry.notify();
-                }
             }
         }
 
@@ -269,14 +243,7 @@
 
             if( currentTime >= entry.deadline )
             {
-                entry.exception = new ConnectException();
-                entry.done = true;
-
-                synchronized( entry )
-                {
-                    entry.notify();
-                }
-
+                entry.setException( new ConnectException() );
                 key.cancel();
             }
         }
@@ -362,19 +329,13 @@
         }
     }
 
-    private static class ConnectionRequest
+    private static class ConnectionRequest extends ConnectFuture
     {
         private final SocketChannel channel;
         
         private final long deadline;
 
         private final IoHandler handler;
-        
-        private SocketSession session;
-
-        private boolean done;
-
-        private Throwable exception;
 
         private ConnectionRequest( SocketChannel channel, int timeout, IoHandler handler )
         {

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java Sun Jun 12 04:25:23 2005
@@ -29,6 +29,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.WriteTimeoutException;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.Queue;
 
 /**
@@ -432,19 +433,23 @@
     
     private void releaseWriteBuffers( SocketSession session )
     {
-        Queue writeBufferQueue = session.getWriteBufferQueue();
-        ByteBuffer buf;
+        Queue writeRequestQueue = session.getWriteRequestQueue();
+        WriteRequest req;
         
-        while( ( buf = (ByteBuffer) writeBufferQueue.pop() ) != null )
+        while( ( req = ( WriteRequest ) writeRequestQueue.pop() ) != null )
         {
             try
             {
-                buf.release();
+                ( ( ByteBuffer ) req.getMessage() ).release();
             }
             catch( IllegalStateException e )
             {
                 session.getManagerFilterChain().exceptionCaught( session, e );
             }
+            finally
+            {
+                req.getFuture().setWritten( false );
+            }
         }
     }
 
@@ -452,26 +457,28 @@
     {
         SocketChannel ch = session.getChannel();
 
-        Queue writeBufferQueue = session.getWriteBufferQueue();
+        Queue writeRequestQueue = session.getWriteRequestQueue();
 
-        ByteBuffer buf;
+        WriteRequest req;
         for( ;; )
         {
-            synchronized( writeBufferQueue )
+            synchronized( writeRequestQueue )
             {
-                buf = ( ByteBuffer ) writeBufferQueue.first();
+                req = ( WriteRequest ) writeRequestQueue.first();
             }
 
-            if( buf == null )
+            if( req == null )
                 break;
 
+            ByteBuffer buf = ( ByteBuffer ) req.getMessage();
             if( buf.remaining() == 0 )
             {
-                synchronized( writeBufferQueue )
+                synchronized( writeRequestQueue )
                 {
-                    writeBufferQueue.pop();
+                    writeRequestQueue.pop();
                 }
                 
+                req.getFuture().setWritten( true );
                 session.getManagerFilterChain().messageSent( session, buf.reset() );
                 continue;
             }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java Sun Jun 12 04:25:23 2005
@@ -23,6 +23,7 @@
 import java.nio.channels.SocketChannel;
 
 import org.apache.mina.common.BaseIoSession;
+import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
@@ -30,10 +31,10 @@
 import org.apache.mina.common.IoSessionFilterChain;
 import org.apache.mina.common.IoSessionManagerFilterChain;
 import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.Queue;
 
-import EDU.oswego.cs.dl.util.concurrent.FutureResult;
-
 /**
  * An {@link IoSession} for socket transport (TCP/IP).
  * 
@@ -50,7 +51,7 @@
 
     private final SocketSessionConfig config;
 
-    private final Queue writeBufferQueue;
+    private final Queue writeRequestQueue;
 
     private final IoHandler handler;
 
@@ -60,7 +61,7 @@
 
     private SelectionKey key;
     
-    private FutureResult closeFuture = new FutureResult();
+    private CloseFuture closeFuture = new CloseFuture();
 
     /**
      * Creates a new instance.
@@ -72,7 +73,7 @@
         this.filterChain = new IoSessionFilterChain( managerFilterChain );
         this.ch = ch;
         this.config = new SocketSessionConfig( this );
-        this.writeBufferQueue = new Queue();
+        this.writeRequestQueue = new Queue();
         this.handler = defaultHandler;
         this.remoteAddress = ch.socket().getRemoteSocketAddress();
         this.localAddress = ch.socket().getLocalSocketAddress();
@@ -108,7 +109,12 @@
         return handler;
     }
     
-    public synchronized FutureResult close( boolean wait )
+    public void notifyClose()
+    {
+        closeFuture.setClosed( true );
+    }
+    
+    public CloseFuture close()
     {
         if( !closeFuture.isReady() )
         {
@@ -118,14 +124,16 @@
         return closeFuture;
     }
 
-    Queue getWriteBufferQueue()
+    Queue getWriteRequestQueue()
     {
-        return writeBufferQueue;
+        return writeRequestQueue;
     }
 
-    public void write( Object message )
+    public WriteFuture write( Object message )
     {
-        filterChain.filterWrite( this, message );
+        WriteFuture future = new WriteFuture();
+        filterChain.filterWrite( this, new WriteRequest( message, future ) );
+        return future;
     }
 
     public TransportType getTransportType()

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java Sun Jun 12 04:25:23 2005
@@ -5,6 +5,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionManager;
 import org.apache.mina.common.IoSessionManagerFilterChain;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.Queue;
 
 /**
@@ -19,17 +20,17 @@
         super( manager );
     }
 
-    protected void doWrite( IoSession session, Object message, FutureResult future )
+    protected void doWrite( IoSession session, WriteRequest writeRequest )
     {
         SocketSession s = ( SocketSession ) session;
-        Queue writeBufferQueue = s.getWriteBufferQueue();
+        Queue writeRequestQueue = s.getWriteRequestQueue();
         
-        ( ( ByteBuffer ) message ).mark();
-        synchronized( writeBufferQueue )
+        ( ( ByteBuffer ) writeRequest.getMessage() ).mark();
+        synchronized( writeRequestQueue )
         {
-            writeBufferQueue.push( message );
+            writeRequestQueue.push( writeRequest );
         }
 
-        SocketIoProcessor.getInstance().flushSession( s, future );
+        SocketIoProcessor.getInstance().flushSession( s );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java Sun Jun 12 04:25:23 2005
@@ -7,10 +7,10 @@
 import java.net.SocketAddress;
 
 import org.apache.mina.common.BaseIoSessionManager;
+import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
 import org.apache.mina.transport.vmpipe.VmPipeAcceptor.Entry;
 import org.apache.mina.util.AnonymousSocketAddress;
 
@@ -39,22 +39,22 @@
         return filterChain;
     }
 
-    public IoSession connect( SocketAddress address, IoHandler handler ) throws IOException 
+    public ConnectFuture connect( SocketAddress address, IoHandler handler ) throws IOException 
     {
         return connect( address, null, Integer.MAX_VALUE, handler );
     }
 
-    public IoSession connect( SocketAddress address, SocketAddress localAddress, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler handler ) throws IOException
     {
         return connect( address, localAddress, Integer.MAX_VALUE, handler );
     }
 
-    public IoSession connect( SocketAddress address, int timeout, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, int timeout, IoHandler handler ) throws IOException
     {
         return connect( address, null, timeout, handler );
     }
 
-    public IoSession connect( SocketAddress address, SocketAddress localAddress, int timeout, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, int timeout, IoHandler handler ) throws IOException
     {
         if( address == null )
             throw new NullPointerException( "address" );
@@ -75,6 +75,8 @@
                                                    entry );
 
         VmPipeIdleStatusChecker.INSTANCE.addSession( session );
-        return session;
+        ConnectFuture future = new ConnectFuture();
+        future.setSession( session );
+        return future;
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java Sun Jun 12 04:25:23 2005
@@ -7,12 +7,15 @@
 import java.net.SocketAddress;
 
 import org.apache.mina.common.BaseIoSession;
+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.IoSessionConfig;
 import org.apache.mina.common.IoSessionFilterChain;
 import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolEncoder;
 import org.apache.mina.transport.vmpipe.VmPipeAcceptor.Entry;
@@ -127,22 +130,28 @@
         return null;
     }
 
-    public void close( boolean wait )
+    public CloseFuture close()
     {
         synchronized( lock )
         {
-            if( closed )
-                return;
-
-            closed = remoteSession.closed = true;
-            managerFilterChain.sessionClosed( this );
-            remoteSession.getManagerFilterChain().sessionClosed( remoteSession );
+            if( !closed )
+            {
+                closed = remoteSession.closed = true;
+                managerFilterChain.sessionClosed( this );
+                remoteSession.getManagerFilterChain().sessionClosed( remoteSession );
+            }
         }
+        
+        CloseFuture future = new CloseFuture();
+        future.setClosed( true );
+        return future;
     }
 
-    public void write( Object message )
+    public WriteFuture write( Object message )
     {
-        this.filterChain.filterWrite( this, message );
+        WriteFuture future = new WriteFuture();
+        this.filterChain.filterWrite( this, new WriteRequest( message, future ) );
+        return future;
     }
 
     public TransportType getTransportType()

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java Sun Jun 12 04:25:23 2005
@@ -3,6 +3,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionManager;
 import org.apache.mina.common.IoSessionManagerFilterChain;
+import org.apache.mina.common.IoFilter.WriteRequest;
 
 class VmPipeSessionManagerFilterChain extends IoSessionManagerFilterChain {
 
@@ -11,15 +12,20 @@
         super( manager );
     }
 
-    protected void doWrite( IoSession session, Object message )
+    protected void doWrite( IoSession session, WriteRequest writeRequest )
     {
         VmPipeSession s = ( VmPipeSession ) session;
-        
         synchronized( s.lock )
         {
             if( s.closed )
-                throw new IllegalStateException( "Session is closed." );
-            s.remoteSession.getManagerFilterChain().messageReceived( s.remoteSession, message );
+            {
+                writeRequest.getFuture().setWritten( false );
+            }
+            else 
+            {
+                s.remoteSession.getManagerFilterChain().messageReceived( s.remoteSession, writeRequest.getMessage() );
+                writeRequest.getFuture().setWritten( true );
+            }
         }
     }
 }

Modified: directory/network/branches/dirmina-39/src/test/org/apache/mina/common/IoFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/test/org/apache/mina/common/IoFilterChainTest.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/test/org/apache/mina/common/IoFilterChainTest.java (original)
+++ directory/network/branches/dirmina-39/src/test/org/apache/mina/common/IoFilterChainTest.java Sun Jun 12 04:25:23 2005
@@ -23,6 +23,8 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.mina.common.IoFilter.WriteRequest;
+
 /**
  * Tests {@link AbstractIoFilterChain}.
  * 
@@ -67,7 +69,7 @@
     {
         chain.sessionOpened( session );
         chain.messageReceived( session, new Object() );
-        chain.filterWrite( session, new Object() );
+        chain.filterWrite( session, new WriteRequest( new Object() ) );
         chain.sessionIdle( session, IdleStatus.READER_IDLE );
         chain.exceptionCaught( session, new Exception() );
         chain.sessionClosed( session );
@@ -133,10 +135,12 @@
             return handler;
         }
 
-        public void close( boolean wait ) {
+        public CloseFuture close() {
+            return null;
         }
 
-        public void write(Object message) {
+        public WriteFuture write(Object message) {
+            return null;
         }
 
         public TransportType getTransportType() {
@@ -194,9 +198,9 @@
             nextFilter.exceptionCaught( session, cause );
         }
 
-        public void filterWrite(NextFilter nextFilter, IoSession session, Object message) {
+        public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest ) {
             result += id + "FW";
-            nextFilter.filterWrite( session, message );
+            nextFilter.filterWrite( session, writeRequest );
         }
 
         public void messageReceived(NextFilter nextFilter, IoSession session, Object message) {
@@ -216,9 +220,9 @@
         {
         }
 
-        protected void doWrite( IoSession session, Object message )
+        protected void doWrite( IoSession session, WriteRequest writeRequest )
         {
-            messageSent( session, message );
+            messageSent( session, writeRequest.getMessage() );
         }
     }
     

Modified: directory/network/branches/dirmina-39/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java (original)
+++ directory/network/branches/dirmina-39/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java Sun Jun 12 04:25:23 2005
@@ -25,11 +25,13 @@
 import junit.framework.Assert;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
 import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
 import org.apache.mina.filter.SSLFilter;
 import org.apache.mina.transport.socket.nio.DatagramConnector;
@@ -127,11 +129,15 @@
     {
         EchoConnectorHandler handler = new EchoConnectorHandler();
         ByteBuffer readBuf = handler.readBuf;
-        IoSession session = connector.connect(
+        ConnectFuture future = connector.connect(
                 new InetSocketAddress( InetAddress.getLocalHost(), port ),
                 localAddress,
                 handler );
         
+        future.join();
+        IoSession session = future.getSession();
+        
+        WriteFuture writeFuture = null;
         for( int i = 0; i < 10; i ++ )
         {
             ByteBuffer buf = ByteBuffer.allocate( 16 );
@@ -139,7 +145,7 @@
             fillWriteBuffer( buf, i );
             buf.flip();
 
-            session.write( buf );
+            writeFuture = session.write( buf );
 
             // This will align message arrival order in UDP
             for( int j = 0; j < 30; j ++ )
@@ -163,7 +169,8 @@
             }
         }
 
-        session.close( true );
+        writeFuture.join();
+        session.close();
         
         Assert.assertEquals( 160, readBuf.position() );
         readBuf.flip();

Modified: directory/network/branches/dirmina-39/src/test/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/test/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java?rev=190245&r1=190244&r2=190245&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/test/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java (original)
+++ directory/network/branches/dirmina-39/src/test/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java Sun Jun 12 04:25:23 2005
@@ -27,16 +27,13 @@
 
 import org.apache.mina.common.BaseIoSession;
 import org.apache.mina.common.ByteBuffer;
+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.IoSessionConfig;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
-import org.apache.mina.filter.codec.ProtocolDecoder;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-import org.apache.mina.filter.codec.ProtocolEncoder;
-import org.apache.mina.filter.codec.ProtocolViolationException;
+import org.apache.mina.common.WriteFuture;
 
 /**
  * Tests {@link CumulativeProtocolDecoder}.
@@ -189,10 +186,12 @@
             return null;
         }
 
-        public void close( boolean wait ) {
+        public CloseFuture close() {
+            return null;
         }
 
-        public void write(Object message) {
+        public WriteFuture write( Object message ) {
+            return null;
         }
 
         public TransportType getTransportType() {



Mime
View raw message