directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r370957 - in /directory/sandbox/trustin/mina-spi/core/src: main/java/org/apache/mina/common/ main/java/org/apache/mina/transport/socket/nio/ main/java/org/apache/mina/transport/vmpipe/ test/java/org/apache/mina/common/
Date Sat, 21 Jan 2006 02:18:50 GMT
Author: trustin
Date: Fri Jan 20 18:18:41 2006
New Revision: 370957

URL: http://svn.apache.org/viewcvs?rev=370957&view=rev
Log:
* Moved most methods in acceptor and connector to MINA
* Moved IoAcceptor and IoConnector interface into under IoServiceProvider

Removed:
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoAcceptor.java
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoConnector.java
Modified:
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoAddress.java
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoServiceProvider.java
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/MINA.java
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramServiceProvider.java
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketServiceProvider.java
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeServiceProvider.java
    directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/common/IoAddressTest.java

Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoAddress.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoAddress.java?rev=370957&r1=370956&r2=370957&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoAddress.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoAddress.java
Fri Jan 20 18:18:41 2006
@@ -26,15 +26,15 @@
  */
 public class IoAddress
 {
-    private final String provider;
+    private final String providerType;
     private final String transportType;
     private final String address;
     
-    public IoAddress( String provider, String transportType, String address )
+    public IoAddress( String providerType, String transportType, String address )
     {
-        if( provider == null )
+        if( providerType == null )
         {
-            throw new NullPointerException( "provider" );
+            throw new NullPointerException( "providerType" );
         }
         if( transportType == null )
         {
@@ -45,20 +45,20 @@
             throw new NullPointerException( "address" );
         }
         
-        provider = provider.trim().toLowerCase();
+        providerType = providerType.trim().toLowerCase();
         transportType = transportType.trim().toLowerCase();
         address = address.trim();
         
-        if( provider.indexOf( ':' ) >= 0 )
+        if( providerType.indexOf( ':' ) >= 0 )
         {
-            throw new IllegalArgumentException( "provider: " + provider );
+            throw new IllegalArgumentException( "providerType: " + providerType );
         }
         if( transportType.indexOf( ':' ) >= 0 )
         {
             throw new IllegalArgumentException( "transportType: " + transportType );
         }
         
-        this.provider = provider;
+        this.providerType = providerType;
         this.transportType = transportType;
         this.address = address;
     }
@@ -73,7 +73,7 @@
         int startPos;
         int colonPos = uri.indexOf( ':' );
         checkColonPos( uri, colonPos );
-        provider = uri.substring( 0, colonPos ).trim().toLowerCase();
+        providerType = uri.substring( 0, colonPos ).trim().toLowerCase();
         startPos = colonPos + 1;
         
         colonPos = uri.indexOf( ':', startPos );
@@ -92,9 +92,9 @@
         }
     }
     
-    public String getProvider()
+    public String getProviderType()
     {
-        return provider;
+        return providerType;
     }
     
     public String getTransportType()
@@ -109,6 +109,6 @@
     
     public String toString()
     {
-        return provider + ':' + transportType + ':' + address;
+        return providerType + ':' + transportType + ':' + address;
     }
 }

Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoServiceProvider.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoServiceProvider.java?rev=370957&r1=370956&r2=370957&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoServiceProvider.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/IoServiceProvider.java
Fri Jan 20 18:18:41 2006
@@ -18,6 +18,10 @@
  */
 package org.apache.mina.common;
 
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.util.Collection;
+
 /**
  * TODO Document me
  * 
@@ -26,8 +30,74 @@
  */
 public interface IoServiceProvider
 {
-    String getName();
+    String getProviderType();
     String getTransportType();
-    IoAcceptor newAcceptor();
-    IoConnector newConnector();
+    IoAcceptor getAcceptor();
+    IoConnector getConnector();
+    
+    public interface IoAcceptor
+    {
+        /**
+         * Binds to the specified <code>address</code> and handles incoming
+         * connections with the specified <code>handler</code>.
+         *
+         * @param filterChainBuilder
+         *            an {@link IoFilterChainBuilder} that will modify the
+         *            {@link IoFilterChain} of a newly created {@link IoSession}
+         * @throws IOException if failed to bind
+         */
+        void bind( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder
) throws IOException;
+
+        /**
+         * Unbinds from the specified <code>address</code> and disconnects all
clients
+         * connected there.
+         */
+        void unbind( SocketAddress address );
+        
+        /**
+         * Returns all sessions currently connected to the specified local address.
+         * 
+         * @param address the local address to return all sessions for. Must have
+         *        been bound previously.
+         * @return the sessions.
+         * @throws IllegalArgumentException if the specified <tt>address</tt>
has 
+         *         not been bound.
+         * @throws UnsupportedOperationException if this operation isn't supported
+         *         for the particular transport type implemented by this 
+         *         {@link IoAcceptor}.
+         */
+        Collection getManagedSessions( SocketAddress address );
+        
+        /**
+         * (Optional) Returns an {@link IoSession} that is bound to the specified
+         * <tt>localAddress</tt> and <tt>remoteAddress</tt> which
reuses
+         * the <tt>localAddress</tt> that is already bound by {@link IoAcceptor}
+         * via {@link #bind(SocketAddress, IoHandler)}.
+         * <p>
+         * This operation is optional.  Please throw {@link UnsupportedOperationException}
+         * if the transport type doesn't support this operation.  This operation is
+         * usually implemented for connectionless transport types.
+         * 
+         * @throws UnsupportedOperationException if this operation is not supported
+         * @throws IllegalArgumentException if the specified <tt>localAddress</tt>
is
+         *                                  not bound yet. (see {@link #bind(SocketAddress,
IoHandler)})
+         */
+        IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress );
+    }
+    
+    public interface IoConnector
+    {
+        /**
+         * Connects to the specified <code>address</code>.  If communication
starts
+         * successfully, events are fired to the specified
+         * <code>handler</code>.
+         * 
+         * @param filterChainBuilder
+         *            an {@link IoFilterChainBuilder} that will modify the
+         *            {@link IoFilterChain} of a newly created {@link IoSession}
+         * @return {@link ConnectFuture} that will tell the result of the connection attempt
+         */
+        ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
+                               IoHandler handler, IoFilterChainBuilder filterChainBuilder
);
+    }
 }

Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/MINA.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/MINA.java?rev=370957&r1=370956&r2=370957&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/MINA.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/MINA.java
Fri Jan 20 18:18:41 2006
@@ -18,6 +18,9 @@
  */
 package org.apache.mina.common;
 
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
@@ -26,6 +29,13 @@
 import org.apache.mina.common.support.discovery.tools.Service;
 import org.apache.mina.util.IdentityHashSet;
 
+/**
+ * TODO Document me
+ * TODO Add UnsupportedAddressException
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
 public class MINA
 {
     private static final Map providers = new HashMap();
@@ -61,16 +71,12 @@
         {
             if( providers.get( key ) != null )
             {
-                throw new IllegalArgumentException( "Provider '" + provider.getName() + "'
is already registered." );
+                throw new IllegalArgumentException( "Provider '" + key + "' is already registered."
);
             }
             providers.put( key, provider );
         }
     }
 
-	private static String getProviderKey(IoServiceProvider provider) {
-		return provider.getName() + ':' + provider.getTransportType();
-	}
-    
     public static boolean deregisterProvider( IoServiceProvider provider )
     {
         if( provider == null )
@@ -90,5 +96,166 @@
         {
             return new IdentityHashSet( providers.values() );
         }
+    }
+    
+    public static IoServiceProvider getProvider( String providerType, String transportType
)
+    {
+    	return ( IoServiceProvider ) providers.get( getProviderKey( providerType, transportType
) );
+    }
+    
+    private static IoServiceProvider getProviderSafely( IoAddress address )
+    {
+    	IoServiceProvider p = getProvider( address.getProviderType(), address.getTransportType()
);
+    	if( p != null )
+    	{
+    		return p;
+    	}
+    	
+    	throw new IllegalArgumentException( "Unsupported address: " + address );
+    }
+    
+	private static String getProviderKey( IoServiceProvider provider ) {
+		return getProviderKey( provider.getProviderType(), provider.getTransportType() );
+	}
+	
+	private static String getProviderKey( String providerType, String transportType )
+	{
+		return providerType + ':' + transportType;
+	}
+    
+	// Acceptor side
+	
+    /**
+     * Binds to the specified <code>address</code> and handles incoming
+     * connections with the specified <code>handler</code>.
+     * 
+     * @throws IOException if failed to bind
+     */
+    public static void bind( IoAddress address, IoHandler handler ) throws IOException
+    {
+    	bind( address, handler, IoFilterChainBuilder.NOOP );
+    }
+
+    /**
+     * Binds to the specified <code>address</code> and handles incoming
+     * connections with the specified <code>handler</code>.
+     *
+     * @param filterChainBuilder
+     *            an {@link IoFilterChainBuilder} that will modify the
+     *            {@link IoFilterChain} of a newly created {@link IoSession}
+     * @throws IOException if failed to bind
+     */
+    public static void bind( IoAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder
) throws IOException
+    {
+    	IoAcceptor acceptor = getProviderSafely( address ).getAcceptor();
+    	acceptor.bind( address, handler, filterChainBuilder );
+    }
+
+    /**
+     * Unbinds from the specified <code>address</code> and disconnects all clients
+     * connected there.
+     */
+    public static void unbind( IoAddress address )
+    {
+    	IoAcceptor acceptor = getProviderSafely( address ).getAcceptor();
+    	acceptor.unbind( address );
+    }
+    
+    /**
+     * Returns all sessions currently connected to the specified local address.
+     * 
+     * @param address the local address to return all sessions for. Must have
+     *        been bound previously.
+     * @return the sessions.
+     * @throws IllegalArgumentException if the specified <tt>address</tt> has

+     *         not been bound.
+     * @throws UnsupportedOperationException if this operation isn't supported
+     *         for the particular transport type implemented by this 
+     *         {@link IoAcceptor}.
+     */
+    public static Collection getManagedSessions( IoAddress address )
+    {
+    	IoAcceptor acceptor = getProviderSafely( address ).getAcceptor();
+    	return acceptor.getManagedSessions( address );
+    }
+    
+    /**
+     * (Optional) Returns an {@link IoSession} that is bound to the specified
+     * <tt>localAddress</tt> and <tt>remoteAddress</tt> which reuses
+     * the <tt>localAddress</tt> that is already bound by {@link IoAcceptor}
+     * via {@link #bind(SocketAddress, IoHandler)}.
+     * <p>
+     * This operation is optional.  Please throw {@link UnsupportedOperationException}
+     * if the transport type doesn't support this operation.  This operation is
+     * usually implemented for connectionless transport types.
+     * 
+     * @throws UnsupportedOperationException if this operation is not supported
+     * @throws IllegalArgumentException if the specified <tt>localAddress</tt>
is
+     *                                  not bound yet. (see {@link #bind(SocketAddress, IoHandler)})
+     */
+    public static IoSession newSession( IoAddress remoteAddress, IoAddress localAddress )
+    {
+    	IoAcceptor acceptor = getProviderSafely( localAddress ).getAcceptor();
+    	return acceptor.newSession( remoteAddress, localAddress );
+    }
+    
+    // Connector side
+    
+    /**
+     * Connects to the specified <code>address</code>.  If communication starts
+     * successfully, events are fired to the specified
+     * <code>handler</code>.
+     * 
+     * @return {@link ConnectFuture} that will tell the result of the connection attempt
+     */
+    public static ConnectFuture connect( IoAddress address, IoHandler handler )
+    {
+    	return connect( address, handler, IoFilterChainBuilder.NOOP );
+    }
+    
+    /**
+     * Connects to the specified <code>address</code>.  If communication starts
+     * successfully, events are fired to the specified
+     * <code>handler</code>.
+     * 
+     * @param filterChainBuilder
+     *            an {@link IoFilterChainBuilder} that will modify the
+     *            {@link IoFilterChain} of a newly created {@link IoSession}
+     * @return {@link ConnectFuture} that will tell the result of the connection attempt
+     */
+    public static ConnectFuture connect( IoAddress address, IoHandler handler,
+                           IoFilterChainBuilder filterChainBuilder )
+    {
+    	return connect( address, null, handler, filterChainBuilder );
+    }
+
+    /**
+     * Connects to the specified <code>address</code>.  If communication starts
+     * successfully, events are fired to the specified
+     * <code>handler</code>.
+     * 
+     * @param localAddress the local address the channel is bound to
+     * @return {@link ConnectFuture} that will tell the result of the connection attempt
+     */
+    public static ConnectFuture connect( IoAddress address, IoAddress localAddress, IoHandler
handler )
+    {
+    	return connect( address, localAddress, handler, IoFilterChainBuilder.NOOP );
+    }
+
+    /**
+     * Connects to the specified <code>address</code>.  If communication starts
+     * successfully, events are fired to the specified
+     * <code>handler</code>.
+     * 
+     * @param filterChainBuilder
+     *            an {@link IoFilterChainBuilder} that will modify the
+     *            {@link IoFilterChain} of a newly created {@link IoSession}
+     * @return {@link ConnectFuture} that will tell the result of the connection attempt
+     */
+    public static ConnectFuture connect( IoAddress address, IoAddress localAddress,
+                                         IoHandler handler, IoFilterChainBuilder filterChainBuilder
)
+    {
+    	IoConnector connector = getProviderSafely( address ).getConnector();
+    	return connector.connect( address, localAddress, handler, filterChainBuilder );
     }
 }

Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramServiceProvider.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramServiceProvider.java?rev=370957&r1=370956&r2=370957&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramServiceProvider.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramServiceProvider.java
Fri Jan 20 18:18:41 2006
@@ -24,7 +24,10 @@
 
 public class DatagramServiceProvider implements IoServiceProvider
 {
-    public String getName()
+	private final IoAcceptor acceptor = new DatagramAcceptor();
+	private final IoConnector connector = new DatagramConnector();
+	
+    public String getProviderType()
     {
         return "nio";
     }
@@ -34,13 +37,13 @@
     	return "datagram";
     }
 
-    public IoAcceptor newAcceptor()
+    public IoAcceptor getAcceptor()
     {
-        return new DatagramAcceptor();
+        return acceptor;
     }
 
-    public IoConnector newConnector()
+    public IoConnector getConnector()
     {
-        return new DatagramConnector();
+        return connector;
     }
 }

Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketServiceProvider.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketServiceProvider.java?rev=370957&r1=370956&r2=370957&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketServiceProvider.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketServiceProvider.java
Fri Jan 20 18:18:41 2006
@@ -24,7 +24,10 @@
 
 public class SocketServiceProvider implements IoServiceProvider
 {
-    public String getName()
+	private final IoAcceptor acceptor = new SocketAcceptor();
+	private final IoConnector connector = new SocketConnector();
+	
+    public String getProviderType()
     {
         return "nio";
     }
@@ -34,13 +37,13 @@
     	return "socket";
     }
 
-    public IoAcceptor newAcceptor()
+    public IoAcceptor getAcceptor()
     {
-        return new SocketAcceptor();
+        return acceptor;
     }
 
-    public IoConnector newConnector()
+    public IoConnector getConnector()
     {
-        return new SocketConnector();
+        return connector;
     }
 }

Modified: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeServiceProvider.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeServiceProvider.java?rev=370957&r1=370956&r2=370957&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeServiceProvider.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeServiceProvider.java
Fri Jan 20 18:18:41 2006
@@ -24,8 +24,10 @@
 
 public class VmPipeServiceProvider implements IoServiceProvider
 {
+	private final IoAcceptor acceptor = new VmPipeAcceptor();
+	private final IoConnector connector = new VmPipeConnector();
 
-    public String getName()
+    public String getProviderType()
     {
         return "vm";
     }
@@ -35,13 +37,13 @@
     	return "pipe";
     }
 
-    public IoAcceptor newAcceptor()
+    public IoAcceptor getAcceptor()
     {
-        return new VmPipeAcceptor();
+        return acceptor;
     }
 
-    public IoConnector newConnector()
+    public IoConnector getConnector()
     {
-        return new VmPipeConnector();
+        return connector;
     }
 }

Modified: directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/common/IoAddressTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/common/IoAddressTest.java?rev=370957&r1=370956&r2=370957&view=diff
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/common/IoAddressTest.java
(original)
+++ directory/sandbox/trustin/mina-spi/core/src/test/java/org/apache/mina/common/IoAddressTest.java
Fri Jan 20 18:18:41 2006
@@ -70,7 +70,7 @@
     public void testConstructor2() throws Exception
     {
         IoAddress uri = new IoAddress( "nio:socket:192.168.0.1:8080" );
-        Assert.assertEquals( "nio", uri.getProvider() );
+        Assert.assertEquals( "nio", uri.getProviderType() );
         Assert.assertEquals( "socket", uri.getTransportType() );
         Assert.assertEquals( "192.168.0.1:8080", uri.getAddress() );
     }



Mime
View raw message