directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r407136 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/common/ main/java/org/apache/mina/common/support/ main/java/org/apache/mina/filter/ main/java/org/apache/mina/filter/codec/ main/java/org/apache/mina/transport/socket/n...
Date Wed, 17 May 2006 03:18:16 GMT
Author: trustin
Date: Tue May 16 20:18:15 2006
New Revision: 407136

URL: http://svn.apache.org/viewcvs?rev=407136&view=rev
Log:
Resolved issue: DIRMINA-217 (Make IoFuture and its subclasses interfaces)
* Changed IoFuture and its subclasses into interfaces
* Extracted their implementations to common.support.DefaultXxxFuture
* IoFilter.WriteRequest.UNUSED_FUTURE directly implements WriteFuture now.
  * This change broke StreamWriterFilterTest. I fixed it, too.

Added:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultCloseFuture.java   (with props)
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultConnectFuture.java   (with props)
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java   (with props)
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultWriteFuture.java   (with props)
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java
      - copied, changed from r407121, directory/trunks/mina/core/src/test/java/org/apache/mina/common/FutureTest.java
Removed:
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/FutureTest.java
Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/CloseFuture.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/ConnectFuture.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/WriteFuture.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/CloseFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/CloseFuture.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/CloseFuture.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/CloseFuture.java Tue May 16 20:18:15 2006
@@ -34,44 +34,17 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class CloseFuture extends IoFuture
+public interface CloseFuture extends IoFuture
 {
     /**
-     * Creates a new instance.
-     */
-    public CloseFuture()
-    {
-    }
-    
-    /**
-     * Creates a new instance which uses the specified object as a lock.
-     */
-    public CloseFuture( Object lock )
-    {
-        super( lock );
-    }
-    
-    /**
      * Returns <tt>true</tt> if the close request is finished and the session is closed.
      */
-    public boolean isClosed()
-    {
-        if( isReady() )
-        {
-            return ( ( Boolean ) getValue() ).booleanValue();
-        }
-        else
-        {
-            return false;
-        }
-    }
+    boolean isClosed();
     
     /**
-     * This method is invoked by MINA internally.  Please do not call this method
-     * directly.
+     * Marks this future as closed and notifies all threads waiting for this
+     * future.  This method is invoked by MINA internally.  Please do not call
+     * this method directly.
      */
-    public void setClosed()
-    {
-        setValue( Boolean.TRUE );
-    }
+    void setClosed();
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/ConnectFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/ConnectFuture.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/ConnectFuture.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/ConnectFuture.java Tue May 16 20:18:15 2006
@@ -18,8 +18,6 @@
  */
 package org.apache.mina.common;
 
-import java.io.IOException;
-
 /**
  * An {@link IoFuture} for asynchronous connect requests.
  *
@@ -35,72 +33,32 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class ConnectFuture extends IoFuture
+public interface ConnectFuture extends IoFuture
 {
     /**
-     * Returns a new {@link ConnectFuture} which is already marked as 'failed to connect'.
-     */
-    public static ConnectFuture newFailedFuture( IOException exception )
-    {
-        ConnectFuture failedFuture = new ConnectFuture();
-        failedFuture.setException( exception );
-        return failedFuture;
-    }
-    
-    public ConnectFuture()
-    {
-    }
-    
-    /**
-     * Creates a new instance which uses the specified object as a lock.
-     */
-    public ConnectFuture( Object lock )
-    {
-        super( lock );
-    }
-
-    /**
      * Returns {@link IoSession} which is the result of connect operation.
      * 
      * @return <tt>null</tt> if the connect operation is not finished yet
-     * @throws IOException if connection attempt failed by an exception
+     * @throws RuntimeIOException if connection attempt failed by an exception
      */
-    public IoSession getSession() throws IOException
-    {
-        Object v = getValue();
-        if( v instanceof Throwable )
-        {
-            throw ( IOException ) new IOException( "Failed to get the session." ).initCause( ( Throwable ) v );
-        }
-        else
-        {
-            return ( IoSession ) v;
-        }
-    }
+    IoSession getSession() throws RuntimeIOException;
 
     /**
      * Returns <tt>true</tt> if the connect operation is finished successfully.
      */
-    public boolean isConnected()
-    {
-        return getValue() instanceof IoSession;
-    }
+    boolean isConnected();
     
     /**
-     * This method is invoked by MINA internally.  Please do not call this method
-     * directly.
+     * Sets the newly connected session and notifies all threads waiting for
+     * this future.  This method is invoked by MINA internally.  Please do not
+     * call this method directly.
      */
-    public void setSession( IoSession session )
-    {
-        setValue( session );
-    }
+    void setSession( IoSession session );
     
     /**
-     * This method is invoked by MINA internally.  Please do not call this method
-     * directly.
+     * Sets the exception caught due to connection failure and notifies all
+     * threads waiting for this future.  This method is invoked by MINA
+     * internally.  Please do not call this method directly.
      */
-    public void setException( Throwable exception )
-    {
-        setValue( exception );
-    }
+    void setException( Throwable exception );
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java Tue May 16 20:18:15 2006
@@ -245,7 +245,51 @@
      */
     public static class WriteRequest
     {
-        private static final WriteFuture UNUSED_FUTURE = new WriteFuture();
+        private static final WriteFuture UNUSED_FUTURE = new WriteFuture()
+        {
+            public boolean isWritten()
+            {
+                return false;
+            }
+
+            public void setWritten( boolean written )
+            {
+            }
+            
+            public IoSession getSession()
+            {
+                return null;
+            }
+
+            public Object getLock()
+            {
+                return this;
+            }
+
+            public void join()
+            {
+            }
+
+            public boolean join( long timeoutInMillis )
+            {
+                return true;
+            }
+
+            public boolean isReady()
+            {
+                return true;
+            }
+
+            public Callback getCallback()
+            {
+                return null;
+            }
+
+            public void setCallback( Callback callback )
+            {
+                throw new IllegalStateException( "You can't set a callback for a dummy future." );
+            }
+        };
         
         private final Object message;
         private final WriteFuture future;

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java Tue May 16 20:18:15 2006
@@ -25,13 +25,8 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class IoFuture
+public interface IoFuture
 {
-    private final Object lock;
-    private Object result;
-    private Callback callback;
-    private boolean ready;
-
     /**
      * Something interested in being notified when the result
      * of an {@link IoFuture} becomes available.
@@ -45,184 +40,45 @@
          * @param future  The source {@link IoFuture} which called this
          *                callback.
          */
-        public void operationComplete( IoFuture future );
+        void operationComplete( IoFuture future );
     }
 
     /**
-     * Creates a new instance.
-     */
-    public IoFuture()
-    {
-        this.lock = this;
-    }
-    
-    /**
-     * Creates a new instance which uses the specified object as a lock.
+     * Returns the {@link IoSession} which is associated with this future.
      */
-    public IoFuture( Object lock )
-    {
-        if( lock == null )
-        {
-            throw new NullPointerException( "lock" );
-        }
-        this.lock = lock;
-    }
+    IoSession getSession();
     
     /**
      * Returns the lock object this future acquires.
      */
-    public Object getLock()
-    {
-        return lock;
-    }
+    Object getLock();
     
     /**
      * Wait for the asynchronous operation to end.
      */
-    public void join()
-    {
-        synchronized( lock )
-        {
-            while( !ready )
-            {
-                try
-                {
-                    lock.wait();
-                }
-                catch( InterruptedException e )
-                {
-                }
-            }
-        }
-    }
+    void join();
 
     /**
      * Wait for the asynchronous operation to end with the specified timeout.
      * 
      * @return <tt>true</tt> if the operation is finished.
      */
-    public boolean join( long timeoutInMillis )
-    {
-        long startTime = ( timeoutInMillis <= 0 ) ? 0 : System
-                .currentTimeMillis();
-        long waitTime = timeoutInMillis;
-        
-        synchronized( lock )
-        {
-            if( ready )
-            {
-                return ready;
-            }
-            else if( waitTime <= 0 )
-            {
-                return ready;
-            }
-
-            for( ;; )
-            {
-                try
-                {
-                    lock.wait( waitTime );
-                }
-                catch( InterruptedException e )
-                {
-                }
-
-                if( ready )
-                    return true;
-                else
-                {
-                    waitTime = timeoutInMillis - ( System.currentTimeMillis() - startTime );
-                    if( waitTime <= 0 )
-                    {
-                        return ready;
-                    }
-                }
-            }
-        }
-    }
+    boolean join( long timeoutInMillis );
 
     /**
      * Returns if the asynchronous operation is finished.
      */
-    public boolean isReady()
-    {
-        synchronized( lock )
-        {
-            return ready;
-        }
-    }
-
-    /**
-     * Sets the result of the asynchronous operation, and mark it as finished.
-     */
-    protected void setValue( Object newValue )
-    {
-        synchronized( lock )
-        {
-            // Allow only once.
-            if( ready )
-            {
-                return;
-            }
-
-            result = newValue;
-            ready = true;
-            lock.notifyAll();
-    
-            if( callback != null )
-            {
-                invokeCallback();
-            }
-        }
-    }
+    boolean isReady();
 
     /**
-     * Returns the result of the asynchronous operation.
-     */
-    protected Object getValue()
-    {
-        synchronized( lock )
-        {
-            return result;
-        }
-    }
-    
-    /**
      * Returns a {@link Callback} which is associated with this future.
      */
-    public Callback getCallback()
-    {
-        synchronized( lock )
-        {
-            return callback;
-        }
-    }
+    Callback getCallback();
     
     /**
      * Sets a {@link Callback} to be notified when a result
      * becomes available.  If tth result has already become obtained,
      * the specified callback is notified immediately
      */
-    public void setCallback( Callback callback ) 
-    {
-        if( callback == null )
-        {
-            throw new NullPointerException( "callback" );
-        }
-
-        synchronized( lock )
-        {
-            this.callback = callback;
-            if( ready )
-            {
-                invokeCallback();
-            }
-        }
-    }
-
-    private void invokeCallback()
-    {
-        callback.operationComplete( this );
-    }
+    void setCallback( Callback callback );
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/WriteFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/WriteFuture.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/WriteFuture.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/WriteFuture.java Tue May 16 20:18:15 2006
@@ -41,64 +41,17 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class WriteFuture extends IoFuture
+public interface WriteFuture extends IoFuture
 {
     /**
-     * Returns a new {@link WriteFuture} which is already marked as 'written'.
-     */
-    public static WriteFuture newWrittenFuture()
-    {
-        WriteFuture unwrittenFuture = new WriteFuture();
-        unwrittenFuture.setWritten( true );
-        return unwrittenFuture;
-    }
-
-    /**
-     * Returns a new {@link WriteFuture} which is already marked as 'not written'.
-     */
-    public static WriteFuture newNotWrittenFuture()
-    {
-        WriteFuture unwrittenFuture = new WriteFuture();
-        unwrittenFuture.setWritten( false );
-        return unwrittenFuture;
-    }
-    
-    /**
-     * Creates a new instance.
-     */
-    public WriteFuture()
-    {
-    }
-    
-    /**
-     * Creates a new instance which uses the specified object as a lock.
-     */
-    public WriteFuture( Object lock )
-    {
-        super( lock );
-    }
-    
-    /**
      * Returns <tt>true</tt> if the write operation is finished successfully.
      */
-    public boolean isWritten()
-    {
-        if( isReady() )
-        {
-            return ( ( Boolean ) getValue() ).booleanValue();
-        }
-        else
-        {
-            return false;
-        }
-    }
+    boolean isWritten();
 
     /**
-     * This method is invoked by MINA internally.  Please do not call this method
-     * directly.
+     * Sets whether the message is written or not, and notifies all threads
+     * waiting for this future.  This method is invoked by MINA internally.
+     * Please do not call this method directly.
      */
-    public void setWritten( boolean written )
-    {
-        setValue( written? Boolean.TRUE : Boolean.FALSE );
-    }
+    void setWritten( boolean written );
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java Tue May 16 20:18:15 2006
@@ -18,23 +18,23 @@
  */
 package org.apache.mina.common.support;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoFilter;
-import org.apache.mina.common.IoFilter.NextFilter;
-import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoFilterLifeCycleException;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.ByteBufferUtil;
 import org.apache.mina.util.SessionLog;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * An abstract implementation of {@link IoFilterChain} that provides
  * common operations for developers to implement their own transport layer.
@@ -528,6 +528,7 @@
         {
             exceptionCaught( session, t );
         }
+        
         Entry head = this.head;
         callNextMessageSent( head, session, request.getMessage() );
     }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java Tue May 16 20:18:15 2006
@@ -46,7 +46,7 @@
     /** 
      * A future that will be set 'closed' when the connection is closed.
      */
-    private final CloseFuture closeFuture = new CloseFuture( this );
+    private final CloseFuture closeFuture = new DefaultCloseFuture( this );
     private boolean closing;
 
     // Configuration variables
@@ -134,11 +134,11 @@
         {
             if( isClosing() || !isConnected() )
             {
-                return WriteFuture.newNotWrittenFuture();
+                return DefaultWriteFuture.newNotWrittenFuture( this );
             }
         }
 
-        WriteFuture future = new WriteFuture();
+        WriteFuture future = new DefaultWriteFuture( this );
         write0( new WriteRequest( message, future, remoteAddress ) );
         
         return future;

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultCloseFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultCloseFuture.java?rev=407136&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultCloseFuture.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultCloseFuture.java Tue May 16 20:18:15 2006
@@ -0,0 +1,64 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A default implementation of {@link CloseFuture}.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DefaultCloseFuture extends DefaultIoFuture implements CloseFuture
+{
+    /**
+     * Creates a new instance.
+     */
+    public DefaultCloseFuture( IoSession session )
+    {
+        super( session );
+    }
+    
+    /**
+     * Creates a new instance which uses the specified object as a lock.
+     */
+    public DefaultCloseFuture( IoSession session, Object lock )
+    {
+        super( session, lock );
+    }
+    
+    public boolean isClosed()
+    {
+        if( isReady() )
+        {
+            return ( ( Boolean ) getValue() ).booleanValue();
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    public void setClosed()
+    {
+        setValue( Boolean.TRUE );
+    }
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultCloseFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultConnectFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultConnectFuture.java?rev=407136&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultConnectFuture.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultConnectFuture.java Tue May 16 20:18:15 2006
@@ -0,0 +1,90 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.RuntimeIOException;
+
+/**
+ * A default implementation of {@link ConnectFuture}.
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DefaultConnectFuture extends DefaultIoFuture implements ConnectFuture
+{
+    /**
+     * Returns a new {@link ConnectFuture} which is already marked as 'failed to connect'.
+     */
+    public static ConnectFuture newFailedFuture( Throwable exception )
+    {
+        DefaultConnectFuture failedFuture = new DefaultConnectFuture();
+        failedFuture.setException( exception );
+        return failedFuture;
+    }
+    
+    /**
+     * Creates a new instance.
+     */
+    public DefaultConnectFuture()
+    {
+        super( null );
+    }
+    
+    /**
+     * Creates a new instance which uses the specified object as a lock.
+     */
+    public DefaultConnectFuture( Object lock )
+    {
+        super( null, lock );
+    }
+
+    public IoSession getSession() throws RuntimeIOException
+    {
+        Object v = getValue();
+        if( v instanceof RuntimeIOException )
+        {
+            throw ( RuntimeIOException ) v;
+        }
+        else if( v instanceof Throwable )
+        {
+            throw ( RuntimeIOException ) new RuntimeIOException( "Failed to get the session." ).initCause( ( Throwable ) v );
+        }
+        else
+        {
+            return ( IoSession ) v;
+        }
+    }
+
+    public boolean isConnected()
+    {
+        return getValue() instanceof IoSession;
+    }
+    
+    public void setSession( IoSession session )
+    {
+        setValue( session );
+    }
+    
+    public void setException( Throwable exception )
+    {
+        setValue( exception );
+    }
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultConnectFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java?rev=407136&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java Tue May 16 20:18:15 2006
@@ -0,0 +1,202 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import org.apache.mina.common.IoFuture;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A default implementation of {@link IoFuture}.
+ *  
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DefaultIoFuture implements IoFuture
+{
+    private final IoSession session;
+    private final Object lock;
+    private Object result;
+    private Callback callback;
+    private boolean ready;
+
+    /**
+     * Creates a new instance.
+     * 
+     * @param session an {@link IoSession} which is associated with this future
+     */
+    public DefaultIoFuture( IoSession session )
+    {
+        this.session = session;
+        this.lock = this;
+    }
+    
+    /**
+     * Creates a new instance which uses the specified object as a lock.
+     */
+    public DefaultIoFuture( IoSession session, Object lock )
+    {
+        if( lock == null )
+        {
+            throw new NullPointerException( "lock" );
+        }
+        this.session = session;
+        this.lock = lock;
+    }
+    
+    public IoSession getSession()
+    {
+        return session;
+    }
+    
+    public Object getLock()
+    {
+        return lock;
+    }
+    
+    public void join()
+    {
+        synchronized( lock )
+        {
+            while( !ready )
+            {
+                try
+                {
+                    lock.wait();
+                }
+                catch( InterruptedException e )
+                {
+                }
+            }
+        }
+    }
+
+    public boolean join( long timeoutInMillis )
+    {
+        long startTime = ( timeoutInMillis <= 0 ) ? 0 : System
+                .currentTimeMillis();
+        long waitTime = timeoutInMillis;
+        
+        synchronized( lock )
+        {
+            if( ready )
+            {
+                return ready;
+            }
+            else if( waitTime <= 0 )
+            {
+                return ready;
+            }
+
+            for( ;; )
+            {
+                try
+                {
+                    lock.wait( waitTime );
+                }
+                catch( InterruptedException e )
+                {
+                }
+
+                if( ready )
+                    return true;
+                else
+                {
+                    waitTime = timeoutInMillis - ( System.currentTimeMillis() - startTime );
+                    if( waitTime <= 0 )
+                    {
+                        return ready;
+                    }
+                }
+            }
+        }
+    }
+
+    public boolean isReady()
+    {
+        synchronized( lock )
+        {
+            return ready;
+        }
+    }
+
+    /**
+     * Sets the result of the asynchronous operation, and mark it as finished.
+     */
+    protected void setValue( Object newValue )
+    {
+        synchronized( lock )
+        {
+            // Allow only once.
+            if( ready )
+            {
+                return;
+            }
+
+            result = newValue;
+            ready = true;
+            lock.notifyAll();
+    
+            if( callback != null )
+            {
+                invokeCallback();
+            }
+        }
+    }
+
+    /**
+     * Returns the result of the asynchronous operation.
+     */
+    protected Object getValue()
+    {
+        synchronized( lock )
+        {
+            return result;
+        }
+    }
+    
+    public Callback getCallback()
+    {
+        synchronized( lock )
+        {
+            return callback;
+        }
+    }
+    
+    public void setCallback( Callback callback ) 
+    {
+        if( callback == null )
+        {
+            throw new NullPointerException( "callback" );
+        }
+
+        synchronized( lock )
+        {
+            this.callback = callback;
+            if( ready )
+            {
+                invokeCallback();
+            }
+        }
+    }
+
+    private void invokeCallback()
+    {
+        callback.operationComplete( this );
+    }
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultWriteFuture.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultWriteFuture.java?rev=407136&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultWriteFuture.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultWriteFuture.java Tue May 16 20:18:15 2006
@@ -0,0 +1,84 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common.support;
+
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+
+/**
+ * A default implementation of {@link WriteFuture}.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DefaultWriteFuture extends DefaultIoFuture implements WriteFuture
+{
+    /**
+     * Returns a new {@link DefaultWriteFuture} which is already marked as 'written'.
+     */
+    public static WriteFuture newWrittenFuture( IoSession session )
+    {
+        DefaultWriteFuture unwrittenFuture = new DefaultWriteFuture( session );
+        unwrittenFuture.setWritten( true );
+        return unwrittenFuture;
+    }
+
+    /**
+     * Returns a new {@link DefaultWriteFuture} which is already marked as 'not written'.
+     */
+    public static WriteFuture newNotWrittenFuture( IoSession session )
+    {
+        DefaultWriteFuture unwrittenFuture = new DefaultWriteFuture( session );
+        unwrittenFuture.setWritten( false );
+        return unwrittenFuture;
+    }
+    
+    /**
+     * Creates a new instance.
+     */
+    public DefaultWriteFuture( IoSession session )
+    {
+        super( session );
+    }
+    
+    /**
+     * Creates a new instance which uses the specified object as a lock.
+     */
+    public DefaultWriteFuture( IoSession session, Object lock )
+    {
+        super( session, lock );
+    }
+    
+    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/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultWriteFuture.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java Tue May 16 20:18:15 2006
@@ -34,8 +34,8 @@
  * from the stream into {@link ByteBuffer} objects and write those buffers
  * to the next filter. When end of stream has been reached this filter will
  * call {@link NextFilter#messageSent(IoSession, Object)} using the original
- * {@link InputStream} written to the session and call 
- * {@link org.apache.mina.common.WriteFuture#setWritten(boolean)} on the 
+ * {@link InputStream} written to the session and notifies 
+ * {@link org.apache.mina.common.WriteFuture} on the 
  * original {@link org.apache.mina.common.IoFilter.WriteRequest}.
  * <p>
  * This filter will ignore written messages which aren't {@link InputStream}

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Tue May 16 20:18:15 2006
@@ -25,6 +25,7 @@
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.support.DefaultWriteFuture;
 import org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput;
 import org.apache.mina.filter.codec.support.SimpleProtocolEncoderOutput;
 import org.apache.mina.util.Queue;
@@ -382,7 +383,7 @@
             }
             else
             {
-                future = new WriteFuture();
+                future = new DefaultWriteFuture( session );
                 nextFilter.filterWrite( session, new WriteRequest( buf, future ) );
             }
             return future;

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java Tue May 16 20:18:15 2006
@@ -18,15 +18,6 @@
  */
 package org.apache.mina.transport.socket.nio;
 
-import org.apache.mina.common.ConnectFuture;
-import org.apache.mina.common.ExceptionMonitor;
-import org.apache.mina.common.IoConnector;
-import org.apache.mina.common.IoConnectorConfig;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoServiceConfig;
-import org.apache.mina.common.support.BaseIoConnector;
-import org.apache.mina.util.Queue;
-
 import java.io.IOException;
 import java.net.ConnectException;
 import java.net.InetSocketAddress;
@@ -39,6 +30,16 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoConnectorConfig;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.support.BaseIoConnector;
+import org.apache.mina.common.support.DefaultConnectFuture;
+import org.apache.mina.util.Queue;
+
 /**
  * {@link IoConnector} for socket transport (TCP/IP).
  *
@@ -165,7 +166,7 @@
             {
                 SocketSessionImpl session = newSession( ch, handler, config );
                 success = true;
-                ConnectFuture future = new ConnectFuture();
+                DefaultConnectFuture future = new DefaultConnectFuture();
                 future.setSession( session );
                 return future;
             }
@@ -174,7 +175,7 @@
         }
         catch( IOException e )
         {
-            return ConnectFuture.newFailedFuture( e );
+            return DefaultConnectFuture.newFailedFuture( e );
         }
         finally
         {
@@ -209,7 +210,7 @@
                     ExceptionMonitor.getInstance().exceptionCaught( e2 );
                 }
 
-                return ConnectFuture.newFailedFuture( e );
+                return DefaultConnectFuture.newFailedFuture( e );
             }
         }
 
@@ -450,7 +451,7 @@
         }
     }
 
-    private class ConnectionRequest extends ConnectFuture
+    private class ConnectionRequest extends DefaultConnectFuture
     {
         private final SocketChannel channel;
         private final long deadline;

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java Tue May 16 20:18:15 2006
@@ -35,6 +35,7 @@
 import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoConnector;
+import org.apache.mina.common.support.DefaultConnectFuture;
 import org.apache.mina.transport.socket.nio.DatagramConnectorConfig;
 import org.apache.mina.transport.socket.nio.DatagramSessionConfig;
 import org.apache.mina.util.Queue;
@@ -130,7 +131,7 @@
         }
         catch( IOException e )
         {
-            return ConnectFuture.newFailedFuture( e );
+            return DefaultConnectFuture.newFailedFuture( e );
         }
         finally
         {
@@ -167,7 +168,7 @@
                     ExceptionMonitor.getInstance().exceptionCaught( e2 );
                 }
 
-                return ConnectFuture.newFailedFuture( e );
+                return DefaultConnectFuture.newFailedFuture( e );
             }
             
             synchronized( registerQueue )
@@ -612,6 +613,7 @@
                 {
                     ExceptionMonitor.getInstance().exceptionCaught( e );
                 }
+                
                 session.getCloseFuture().setClosed();
                 key.cancel();
                 selector.wakeup(); // wake up again to trigger thread death
@@ -619,7 +621,7 @@
         }
     }
 
-    private static class RegistrationRequest extends ConnectFuture
+    private static class RegistrationRequest extends DefaultConnectFuture
     {
         private final DatagramChannel channel;
         private final IoHandler handler;

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java Tue May 16 20:18:15 2006
@@ -28,6 +28,7 @@
 import org.apache.mina.common.support.BaseIoConnector;
 import org.apache.mina.common.support.BaseIoConnectorConfig;
 import org.apache.mina.common.support.BaseIoSessionConfig;
+import org.apache.mina.common.support.DefaultConnectFuture;
 import org.apache.mina.transport.vmpipe.support.VmPipe;
 import org.apache.mina.transport.vmpipe.support.VmPipeSessionImpl;
 import org.apache.mina.util.AnonymousSocketAddress;
@@ -73,11 +74,11 @@
         VmPipe entry = ( VmPipe ) VmPipeAcceptor.boundHandlers.get( address );
         if( entry == null )
         {
-            return ConnectFuture.newFailedFuture(
+            return DefaultConnectFuture.newFailedFuture(
                     new IOException( "Endpoint unavailable: " + address ) );
         }
 
-        ConnectFuture future = new ConnectFuture();
+        DefaultConnectFuture future = new DefaultConnectFuture();
         try
         {
             VmPipeSessionImpl session =

Copied: directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java (from r407121, directory/trunks/mina/core/src/test/java/org/apache/mina/common/FutureTest.java)
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java?p2=directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java&p1=directory/trunks/mina/core/src/test/java/org/apache/mina/common/FutureTest.java&r1=407121&r2=407136&rev=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/common/FutureTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java Tue May 16 20:18:15 2006
@@ -16,17 +16,23 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.common;
+package org.apache.mina.common.support;
 
 import java.io.IOException;
 import java.net.SocketAddress;
 
 import junit.framework.TestCase;
 
-import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFuture;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.TransportType;
 
 /**
- * Tests {@link IoFuture}s.
+ * Tests {@link IoFuture} implementations.
  * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$ 
@@ -36,7 +42,7 @@
     
     public void testCloseFuture() throws Exception
     {
-        CloseFuture future = new CloseFuture();
+        DefaultCloseFuture future = new DefaultCloseFuture( null );
         assertFalse( future.isReady() );
         assertFalse( future.isClosed() );
         
@@ -53,7 +59,7 @@
     
     public void testConnectFuture() throws Exception
     {
-        ConnectFuture future = new ConnectFuture();
+        DefaultConnectFuture future = new DefaultConnectFuture();
         assertFalse( future.isReady() );
         assertFalse( future.isConnected() );
         assertNull( future.getSession() );
@@ -131,7 +137,7 @@
         assertTrue( future.isConnected() );
         assertEquals( session, future.getSession() );
         
-        future = new ConnectFuture();
+        future = new DefaultConnectFuture();
         thread = new TestThread( future );
         thread.start();
         future.setException( new IOException() );
@@ -146,14 +152,14 @@
             future.getSession();
             fail( "IOException should be thrown." );
         }
-        catch( IOException e )
+        catch( Exception e )
         {
         }
     }
     
     public void testWriteFuture() throws Exception
     {
-        WriteFuture future = new WriteFuture();
+        DefaultWriteFuture future = new DefaultWriteFuture( null );
         assertFalse( future.isReady() );
         assertFalse( future.isWritten() );
         
@@ -167,7 +173,7 @@
         assertTrue( future.isReady() );
         assertTrue( future.isWritten() );
 
-        future = new WriteFuture();
+        future = new DefaultWriteFuture( null );
         thread = new TestThread( future );
         thread.start();
         

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java Tue May 16 20:18:15 2006
@@ -37,6 +37,7 @@
 import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.NextFilter;
 import org.apache.mina.common.IoFilter.WriteRequest;
+import org.apache.mina.common.support.DefaultWriteFuture;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 import org.apache.mina.transport.socket.nio.SocketConnector;
@@ -78,7 +79,7 @@
         StreamWriteFilter filter = new StreamWriteFilter();
         
         InputStream stream = new ByteArrayInputStream( new byte[ 0 ] );
-        WriteRequest writeRequest = new WriteRequest( stream );
+        WriteRequest writeRequest = new WriteRequest( stream, new DummyWriteFuture() );
         
         /*
          * Record expectations
@@ -111,7 +112,7 @@
         StreamWriteFilter filter = new StreamWriteFilter();
         
         Object message = new Object();
-        WriteRequest writeRequest = new WriteRequest( message );
+        WriteRequest writeRequest = new WriteRequest( message, new DummyWriteFuture() );
         
         /*
          * Record expectations
@@ -135,8 +136,6 @@
          */
         mockNextFilter.verify();
         mockSession.verify();
-        
-        assertTrue( writeRequest.getFuture().isWritten() );
     }
     
     /**
@@ -149,7 +148,7 @@
         byte[] data = new byte[] { 1, 2, 3, 4 };
         
         InputStream stream = new ByteArrayInputStream( data );
-        WriteRequest writeRequest = new WriteRequest( stream );
+        WriteRequest writeRequest = new WriteRequest( stream, new DummyWriteFuture() );
         
         /*
          * Record expectations
@@ -203,7 +202,7 @@
         byte[] chunk3 = new byte[] { 9, 10 };
         
         InputStream stream = new ByteArrayInputStream( data );
-        WriteRequest writeRequest = new WriteRequest( stream );
+        WriteRequest writeRequest = new WriteRequest( stream, new DummyWriteFuture() );
         
         /*
          * Record expectations
@@ -275,7 +274,7 @@
         mockNextFilter.replay();
         mockSession.replay();
 
-        WriteRequest wr = new WriteRequest( new Object() );
+        WriteRequest wr = new WriteRequest( new Object(), new DummyWriteFuture() );
         filter.filterWrite( nextFilter, session, wr );
         assertEquals( 1, queue.size() );
         assertSame( wr, queue.pop() );
@@ -292,9 +291,9 @@
         StreamWriteFilter filter = new StreamWriteFilter();
 
         WriteRequest wrs[] = new WriteRequest[] { 
-                new WriteRequest( new Object() ),
-                new WriteRequest( new Object() ),
-                new WriteRequest( new Object() )
+                new WriteRequest( new Object(), new DummyWriteFuture() ),
+                new WriteRequest( new Object(), new DummyWriteFuture() ),
+                new WriteRequest( new Object(), new DummyWriteFuture() )
         };
         Queue queue = new Queue();
         queue.push( wrs[ 0 ] );
@@ -312,7 +311,7 @@
         session.removeAttribute( StreamWriteFilter.CURRENT_STREAM );
         mockSession.setReturnValue( stream );
         session.removeAttribute( StreamWriteFilter.INITIAL_WRITE_FUTURE );
-        mockSession.setReturnValue( new WriteFuture() );
+        mockSession.setReturnValue( new DefaultWriteFuture( session ) );
         session.removeAttribute( StreamWriteFilter.WRITE_REQUEST_QUEUE );
         mockSession.setReturnValue( queue );
         
@@ -579,6 +578,55 @@
                     && w1.getFuture().isWritten() == w2.getFuture().isWritten();
             }
             return super.argumentMatches( expected, actual );
+        }
+    }
+    
+    private static class DummyWriteFuture implements WriteFuture
+    {
+        private boolean written;
+        
+        public boolean isWritten()
+        {
+            return written;
+        }
+
+        public void setWritten( boolean written )
+        {
+            this.written = written;
+        }
+        
+        public IoSession getSession()
+        {
+            return null;
+        }
+
+        public Object getLock()
+        {
+            return this;
+        }
+
+        public void join()
+        {
+        }
+
+        public boolean join( long timeoutInMillis )
+        {
+            return true;
+        }
+
+        public boolean isReady()
+        {
+            return true;
+        }
+
+        public Callback getCallback()
+        {
+            return null;
+        }
+
+        public void setCallback( Callback callback )
+        {
+            throw new IllegalStateException( "You can't set a callback for a dummy future." );
         }
     }
 }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java?rev=407136&r1=407135&r2=407136&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java Tue May 16 20:18:15 2006
@@ -18,6 +18,7 @@
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.AbstractIoFilterChain;
 import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.common.support.DefaultWriteFuture;
 
 public class ThreadPoolFilterRegressionTest extends TestCase
 {
@@ -118,7 +119,7 @@
             WriteFuture future = null;
             for( int j = end; j >= 0; j-- )
             {
-                future = new WriteFuture();
+                future = new DefaultWriteFuture( sessions[ j ] );
                 filter.messageReceived( nextFilter, sessions[ j ], future );
             }
             
@@ -351,7 +352,7 @@
 
         public void messageReceived( IoSession session, Object message )
         {
-            ( ( WriteFuture ) message ).setWritten( true );
+            ( ( DefaultWriteFuture ) message ).setWritten( true );
         }
 
         public void messageSent( IoSession session, Object message )



Mime
View raw message