directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r370979 - in /directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina: common/MINA.java transport/socket/nio/SocketAddresses.java
Date Sat, 21 Jan 2006 04:34:00 GMT
Author: trustin
Date: Fri Jan 20 20:33:57 2006
New Revision: 370979

URL: http://svn.apache.org/viewcvs?rev=370979&view=rev
Log: (empty)

Added:
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAddresses.java
Modified:
    directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/MINA.java

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=370979&r1=370978&r2=370979&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 20:33:57 2006
@@ -156,6 +156,31 @@
     /**
      * 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( String address, IoHandler handler ) throws IOException
+    {
+        bind( createAddress( address ), handler );
+    }
+
+    /**
+     * 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( String address, IoHandler handler, IoFilterChainBuilder filterChainBuilder
) throws IOException
+    {
+        bind( createAddress( address ), handler, filterChainBuilder );
+    }
+    
+    /**
+     * 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
@@ -182,8 +207,17 @@
      */
     public static void unbind( IoAddress address )
     {
-    	IoAcceptor acceptor = getProviderSafely( address ).getAcceptor();
-    	acceptor.unbind( address );
+        IoAcceptor acceptor = getProviderSafely( address ).getAcceptor();
+        acceptor.unbind( address );
+    }
+    
+    /**
+     * Unbinds from the specified <code>address</code> and disconnects all clients
+     * connected there.
+     */
+    public static void unbind( String address )
+    {
+        unbind( createAddress( address ) );
     }
     
     /**
@@ -205,6 +239,23 @@
     }
     
     /**
+     * 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( String address )
+    {
+        return getManagedSessions( createAddress( 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}
@@ -232,6 +283,25 @@
     	return acceptor.newSession( remoteAddress, localAddress );
     }
     
+    /**
+     * (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( String remoteAddress, String localAddress )
+    {
+        return newSession( createAddress( remoteAddress ), createAddress( localAddress )
);
+    }
+    
     // Connector side
     
     /**
@@ -251,6 +321,18 @@
      * 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( String address, IoHandler handler )
+    {
+        return connect( createAddress( address ), handler );
+    }
+    
+    /**
+     * 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}
@@ -267,6 +349,22 @@
      * 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( String address, IoHandler handler,
+                           IoFilterChainBuilder filterChainBuilder )
+    {
+        return connect( createAddress( address ), 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
      */
@@ -280,6 +378,19 @@
      * 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( String address, String localAddress, IoHandler handler
)
+    {
+        return connect( createAddress( address ), createAddress( localAddress ), handler
);
+    }
+
+    /**
+     * 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}
@@ -298,5 +409,31 @@
             filterChainBuilder = IoFilterChainBuilder.NOOP;
         }
     	return connector.connect( address, localAddress, handler, filterChainBuilder );
+    }
+
+    /**
+     * 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( String address, String localAddress,
+                                         IoHandler handler, IoFilterChainBuilder filterChainBuilder
)
+    {
+        return connect( createAddress( address ), createAddress( localAddress ), handler,
filterChainBuilder );
+    }
+    
+    private static IoAddress createAddress( String addr )
+    {
+        if( addr == null )
+        {
+            return null;
+        }
+
+        return new IoAddress( addr );
     }
 }

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAddresses.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAddresses.java?rev=370979&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAddresses.java
(added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAddresses.java
Fri Jan 20 20:33:57 2006
@@ -0,0 +1,94 @@
+/*
+ *   @(#) $Id: SocketAcceptor.java 370960 2006-01-21 02:28:45Z trustin $
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.transport.socket.nio;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.IoAddress;
+
+/**
+ * TODO Document me
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+class SocketAddresses
+{
+	public static SocketAddress parse( IoAddress address )
+	{
+		if( address == null )
+		{
+			throw new NullPointerException( "address" );
+		}
+		
+		String addrStr = address.getAddress();
+		int colonPos = addrStr.lastIndexOf( ':' );
+		if( colonPos < 0 )
+		{
+			throw new IllegalArgumentException( "no port: " + address );
+		}
+		
+        String portStr = addrStr.substring( colonPos + 1 );
+		int port;
+		try
+		{
+			port = Integer.parseInt( portStr );
+		}
+		catch( NumberFormatException e )
+		{
+			throw new IllegalArgumentException( "Invalid port: " + portStr + " (in " + address + ')'
);
+		}
+		
+		if( port == 0 )
+		{
+			throw new IllegalArgumentException( "Unsupported port number: 0" );
+		}
+		
+		String hostname = addrStr.substring( 0, colonPos ).trim();
+		if( hostname.length() == 0 )
+		{
+			throw new IllegalArgumentException( "no hostname: " + address );
+		}
+		
+		if( hostname.equals( "*" ) )
+		{
+			return new InetSocketAddress( port );
+		}
+		else
+		{
+			return new InetSocketAddress( addrStr.substring( 0, colonPos ), port );
+		}
+	}
+    
+    public static IoAddress compose( String transportType, SocketAddress address )
+    {
+        if( address == null )
+        {
+            throw new NullPointerException( "address" );
+        }
+        if( !(address instanceof InetSocketAddress) )
+        {
+            throw new IllegalArgumentException( "Invalid address type: " + address.getClass()
);
+        }
+        
+        InetSocketAddress inetAddr = ( InetSocketAddress ) address;
+        return new IoAddress( "nio", transportType, inetAddr.getHostName() + ':' + inetAddr.getPort()
);
+    }
+}



Mime
View raw message