directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r350141 - in /directory/network/branches/chain_refactor/src/java/org/apache/mina: common/ common/support/ transport/socket/nio/support/ transport/vmpipe/
Date Thu, 01 Dec 2005 03:55:12 GMT
Author: trustin
Date: Wed Nov 30 19:55:04 2005
New Revision: 350141

URL: http://svn.apache.org/viewcvs?rev=350141&view=rev
Log:
Fixed that not all connection exceptions are transmitted to ConnectFuture

Modified:
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/ConnectFuture.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoConnector.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/BaseIoConnector.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/DelegatedIoConnector.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/ConnectFuture.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/ConnectFuture.java?rev=350141&r1=350140&r2=350141&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/ConnectFuture.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/ConnectFuture.java
Wed Nov 30 19:55:04 2005
@@ -40,6 +40,26 @@
 public class 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;
+    }
+
+    /**
+     * 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;
+    }
+
+    /**
      * Returns {@link IoSession} which is the result of connect operation.
      * 
      * @return <tt>null</tt> if the connect operation is not finished yet

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoConnector.java?rev=350141&r1=350140&r2=350141&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoConnector.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/IoConnector.java
Wed Nov 30 19:55:04 2005
@@ -18,7 +18,6 @@
  */
 package org.apache.mina.common;
 
-import java.io.IOException;
 import java.net.SocketAddress;
 
 /**
@@ -47,10 +46,9 @@
      * successfully, events are fired to the specified
      * <code>handler</code>.
      * 
-     * @throws IOException if failed to connect
+     * @returns {@link ConnectFuture} that will tell the result of the connection attempt
      */
-    ConnectFuture connect( SocketAddress address, IoHandler handler )
-            throws IOException;
+    ConnectFuture connect( SocketAddress address, IoHandler handler );
     
     /**
      * Connects to the specified <code>address</code>.  If communication starts
@@ -60,10 +58,10 @@
      * @param filterChainBuilder
      *            an {@link IoFilterChainBuilder} that will modify the
      *            {@link IoFilterChain} of a newly created {@link IoSession}
-     * @throws IOException if failed to connect
+     * @returns {@link ConnectFuture} that will tell the result of the connection attempt
      */
     ConnectFuture connect( SocketAddress address, IoHandler handler,
-                           IoFilterChainBuilder filterChainBuilder ) throws IOException;
+                           IoFilterChainBuilder filterChainBuilder );
 
     /**
      * Connects to the specified <code>address</code>.  If communication starts
@@ -71,10 +69,10 @@
      * <code>handler</code>.
      * 
      * @param localAddress the local address the channel is bound to
-     * @throws IOException if failed to connect
+     * @returns {@link ConnectFuture} that will tell the result of the connection attempt
      */
     ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                           IoHandler handler ) throws IOException;
+                           IoHandler handler );
 
     /**
      * Connects to the specified <code>address</code>.  If communication starts
@@ -84,10 +82,10 @@
      * @param filterChainBuilder
      *            an {@link IoFilterChainBuilder} that will modify the
      *            {@link IoFilterChain} of a newly created {@link IoSession}
-     * @throws IOException if failed to connect
+     * @returns {@link ConnectFuture} that will tell the result of the connection attempt
      */
     ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                           IoHandler handler, IoFilterChainBuilder filterChainBuilder ) throws
IOException;
+                           IoHandler handler, IoFilterChainBuilder filterChainBuilder );
     
     /**
      * Returns the connect timeout in seconds.

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/BaseIoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/BaseIoConnector.java?rev=350141&r1=350140&r2=350141&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/BaseIoConnector.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/BaseIoConnector.java
Wed Nov 30 19:55:04 2005
@@ -18,7 +18,6 @@
  */
 package org.apache.mina.common.support;
 
-import java.io.IOException;
 import java.net.SocketAddress;
 
 import org.apache.mina.common.ConnectFuture;
@@ -40,12 +39,12 @@
     {
     }
     
-    public ConnectFuture connect( SocketAddress address, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, IoHandler handler )
     {
         return connect( address, handler, IoFilterChainBuilder.NOOP );
     }
 
-    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler
handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler
handler )
     {
         return connect( address, localAddress, handler, IoFilterChainBuilder.NOOP );
     }

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/DelegatedIoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/DelegatedIoConnector.java?rev=350141&r1=350140&r2=350141&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/DelegatedIoConnector.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/DelegatedIoConnector.java
Wed Nov 30 19:55:04 2005
@@ -18,7 +18,6 @@
  */
 package org.apache.mina.common.support;
 
-import java.io.IOException;
 import java.net.SocketAddress;
 
 import org.apache.mina.common.ConnectFuture;
@@ -54,24 +53,24 @@
         this.delegate = delegate;
     }
     
-    public ConnectFuture connect( SocketAddress address, IoHandler handler ) throws IOException
+    public ConnectFuture connect( SocketAddress address, IoHandler handler )
     {
         return delegate.connect( address, handler );
     }
 
-    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder ) throws IOException
+    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder )
     {
         return delegate.connect( address, handler, filterChainBuilder );
     }
 
     public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                                  IoHandler handler ) throws IOException
+                                  IoHandler handler )
     {
         return delegate.connect( address, localAddress, handler );
     }
 
     public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                                  IoHandler handler, IoFilterChainBuilder filterChainBuilder
) throws IOException
+                                  IoHandler handler, IoFilterChainBuilder filterChainBuilder
)
     {
         return delegate.connect( address, localAddress, handler, filterChainBuilder );
     }

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java?rev=350141&r1=350140&r2=350141&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
Wed Nov 30 19:55:04 2005
@@ -63,13 +63,13 @@
         this.wrapper = wrapper;
     }
 
-    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder ) throws IOException
+    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder )
     {
         return connect( address, null, handler, filterChainBuilder );
     }
 
     public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                                  IoHandler handler, IoFilterChainBuilder filterChainBuilder
) throws IOException
+                                  IoHandler handler, IoFilterChainBuilder filterChainBuilder
)
     {
         if( address == null )
             throw new NullPointerException( "address" );
@@ -91,10 +91,11 @@
             filterChainBuilder = IoFilterChainBuilder.NOOP;
         }
         
-        DatagramChannel ch = DatagramChannel.open();
+        DatagramChannel ch = null;
         boolean initialized = false;
         try
         {
+            ch = DatagramChannel.open();
             ch.socket().setReuseAddress( true );
             if( localAddress != null )
             {
@@ -104,22 +105,50 @@
             ch.configureBlocking( false );
             initialized = true;
         }
+        catch( IOException e )
+        {
+            return ConnectFuture.newFailedFuture( e );
+        }
         finally
         {
-            if( !initialized )
+            if( !initialized && ch != null )
             {
-                ch.close();
+                try
+                {
+                    ch.close();
+                }
+                catch( IOException e )
+                {
+                    exceptionMonitor.exceptionCaught( this, e );
+                }
             }
         }
 
         RegistrationRequest request = new RegistrationRequest( ch, handler, filterChainBuilder
);
         synchronized( this )
         {
+            try
+            {
+                startupWorker();
+            }
+            catch( IOException e )
+            {
+                try
+                {
+                    ch.close();
+                }
+                catch( IOException e2 )
+                {
+                    exceptionMonitor.exceptionCaught( this, e2 );
+                }
+
+                return ConnectFuture.newFailedFuture( e );
+            }
+            
             synchronized( registerQueue )
             {
                 registerQueue.push( request );
             }
-            startupWorker();
         }
 
         selector.wakeup();

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java?rev=350141&r1=350140&r2=350141&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
Wed Nov 30 19:55:04 2005
@@ -63,13 +63,13 @@
         this.wrapper = wrapper;
     }
 
-    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder ) throws IOException
+    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder )
     {
         return connect( address, null, handler, filterChainBuilder );
     }
 
     public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                                  IoHandler handler, IoFilterChainBuilder filterChainBuilder
) throws IOException
+                                  IoHandler handler, IoFilterChainBuilder filterChainBuilder
)
     {
         if( address == null )
             throw new NullPointerException( "address" );
@@ -89,10 +89,11 @@
             filterChainBuilder = IoFilterChainBuilder.NOOP;
         }
         
-        SocketChannel ch = SocketChannel.open();
+        SocketChannel ch = null;
         boolean success = false;
         try
         {
+            ch = SocketChannel.open();
             ch.socket().setReuseAddress( true );
             if( localAddress != null )
             {
@@ -112,22 +113,49 @@
             
             success = true;
         }
+        catch( IOException e )
+        {
+            return ConnectFuture.newFailedFuture( e );
+        }
         finally
         {
-            if( !success )
+            if( !success && ch != null )
             {
-                ch.close();
+                try
+                {
+                    ch.close();
+                }
+                catch( IOException e )
+                {
+                    exceptionMonitor.exceptionCaught( this, e );
+                }
             }
         }
         
         ConnectionRequest request = new ConnectionRequest( ch, getConnectTimeout(), handler,
filterChainBuilder );
         synchronized( this )
         {
+            try
+            {
+                startupWorker();
+            }
+            catch( IOException e )
+            {
+                try
+                {
+                    ch.close();
+                }
+                catch( IOException e2 )
+                {
+                    exceptionMonitor.exceptionCaught( this, e2 );
+                }
+
+                return ConnectFuture.newFailedFuture( e );
+            }
             synchronized( connectQueue )
             {
                 connectQueue.push( request );
             }
-            startupWorker();
             selector.wakeup();
         }
         

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?rev=350141&r1=350140&r2=350141&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
Wed Nov 30 19:55:04 2005
@@ -23,12 +23,12 @@
  */
 public class VmPipeConnector extends BaseIoConnector
 {
-    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder ) throws IOException 
+    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder
filterChainBuilder ) 
     {
         return connect( address, null, handler, filterChainBuilder );
     }
 
-    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler
handler, IoFilterChainBuilder filterChainBuilder ) throws IOException
+    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler
handler, IoFilterChainBuilder filterChainBuilder )
     {
         if( address == null )
             throw new NullPointerException( "address" );
@@ -45,19 +45,28 @@
 
         VmPipe entry = ( VmPipe ) VmPipeAcceptor.boundHandlers.get( address );
         if( entry == null )
-            throw new IOException( "Endpoint unavailable: " + address );
-
-        VmPipeSessionImpl session =
-            new VmPipeSessionImpl(
-                    this,
-                    new Object(), // lock
-                    AnonymousSocketAddress.INSTANCE,
-                    handler,
-                    filterChainBuilder,
-                    entry );
+        {
+            return ConnectFuture.newFailedFuture(
+                    new IOException( "Endpoint unavailable: " + address ) );
+        }
 
         ConnectFuture future = new ConnectFuture();
-        future.setSession( session );
+        try
+        {
+            VmPipeSessionImpl session =
+                new VmPipeSessionImpl(
+                        this,
+                        new Object(), // lock
+                        AnonymousSocketAddress.INSTANCE,
+                        handler,
+                        filterChainBuilder,
+                        entry );
+            future.setSession( session );
+        }
+        catch( IOException e )
+        {
+            future.setException( e );
+        }
         return future;
     }
 }



Mime
View raw message