Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 3113 invoked from network); 21 Jan 2006 04:34:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Jan 2006 04:34:23 -0000 Received: (qmail 22579 invoked by uid 500); 21 Jan 2006 04:34:22 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 22555 invoked by uid 500); 21 Jan 2006 04:34:22 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 22544 invoked by uid 99); 21 Jan 2006 04:34:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2006 20:34:22 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 20 Jan 2006 20:34:21 -0800 Received: (qmail 2932 invoked by uid 65534); 21 Jan 2006 04:34:01 -0000 Message-ID: <20060121043401.2931.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: trustin@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 address and handles incoming * connections with the specified handler. + * + * @throws IOException if failed to bind + */ + public static void bind( String address, IoHandler handler ) throws IOException + { + bind( createAddress( address ), handler ); + } + + /** + * Binds to the specified address and handles incoming + * connections with the specified handler. + * + * @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 address and handles incoming + * connections with the specified handler. * * @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 address 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 address 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 * localAddress and remoteAddress which reuses * the localAddress 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 + * localAddress and remoteAddress which reuses + * the localAddress that is already bound by {@link IoAcceptor} + * via {@link #bind(SocketAddress, IoHandler)}. + *

+ * 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 localAddress 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 * handler. * + * @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 address. If communication starts + * successfully, events are fired to the specified + * handler. + * * @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 * handler. * + * @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 address. If communication starts + * successfully, events are fired to the specified + * handler. + * * @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 * handler. * + * @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 address. If communication starts + * successfully, events are fired to the specified + * handler. + * * @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 address. If communication starts + * successfully, events are fired to the specified + * handler. + * + * @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() ); + } +}