directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r465510 [1/3] - in /directory/trunks/mina: core/src/main/java/org/apache/mina/common/ core/src/main/java/org/apache/mina/common/support/ core/src/main/java/org/apache/mina/management/ core/src/main/java/org/apache/mina/transport/socket/nio/...
Date Thu, 19 Oct 2006 06:42:11 GMT
Author: trustin
Date: Wed Oct 18 23:42:06 2006
New Revision: 465510

URL: http://svn.apache.org/viewvc?view=rev&rev=465510
Log:
Resolved issue: DIRMINA-290 (Make IoService (IoConnector and IoAcceptor) manage only one service.)
* IoService (IoAcceptor and IoConnector) now can handler only one service at once.
** No more default settings.
* Merged IoServiceConfig implementations into the respective IoService implementations as setters.
* Removed a few spring framework integration classes which is not necessary now.(Binding and IoAcceptorBeanFactory)


Added:
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramService.java   (with props)
Removed:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptorConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoConnectorConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptorConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoConnectorConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramAcceptorConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramConnectorConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramServiceConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptorConfig.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnectorConfig.java
    directory/trunks/mina/integration-spring/src/main/java/org/apache/mina/integration/spring/Binding.java
    directory/trunks/mina/integration-spring/src/main/java/org/apache/mina/integration/spring/IoAcceptorFactoryBean.java
    directory/trunks/mina/integration-spring/src/test/java/org/apache/mina/integration/spring/IoAcceptorFactoryBeanTest.java
Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoConnector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoService.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoConnector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoService.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.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/SocketSessionConfigImpl.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.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/socket/nio/support/DatagramService.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipe.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/IoServiceListenerSupportTest.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/codec/CumulativeProtocolDecoderTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/executor/ExecutorFilterRegressionTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractConnectorTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractTrafficControlTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramConfigTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramRecyclerTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramTrafficControlTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/SocketTrafficControlTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeTrafficControlTest.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ChatClientSupport.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/echoserver/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/Server.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/stream/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/netcat/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/proxy/ClientToProxyIoHandler.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/proxy/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/sumup/Client.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/sumup/Server.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/tennis/Main.java
    directory/trunks/mina/example/src/test/java/org/apache/mina/example/echoserver/AbstractTest.java
    directory/trunks/mina/example/src/test/java/org/apache/mina/example/echoserver/ConnectorTest.java
    directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManager.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptor.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptor.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptor.java Wed Oct 18 23:42:06 2006
@@ -44,46 +44,59 @@
 public interface IoAcceptor extends IoService
 {
     /**
-     * Binds to the specified <code>address</code> and handles incoming
-     * connections with the specified <code>handler</code>.
+     * Returns the local address to bind.
+     */
+    SocketAddress getLocalAddress();
+    
+    /**
+     * Sets the local address to bind.
      * 
-     * @throws IOException if failed to bind
+     * @throws IllegalStateException if this service is already running.
      */
-    void bind( SocketAddress address, IoHandler handler ) throws IOException;
-
+    void setLocalAddress( SocketAddress localAddress );
+    
     /**
-     * Binds to the specified <code>address</code> and handles incoming
-     * connections with the specified <code>handler</code>.
-     *
-     * @param config the configuration
-     * @throws IOException if failed to bind
+     * Returns <tt>true</tt> if and only if all clients are disconnected
+     * when this acceptor unbinds the related local address.
      */
-    void bind( SocketAddress address, IoHandler handler, IoServiceConfig config ) throws IOException;
-
+    boolean isDisconnectOnUnbind();
+    
     /**
-     * Unbinds from the specified <code>address</code> and disconnects all clients
-     * connected there.
+     * Sets whether all clients are disconnected when this acceptor unbinds the
+     * related local address.  The default value is <tt>true</tt>.
      */
-    void unbind( SocketAddress address );
+    void setDisconnectOnUnbind( boolean disconnectOnUnbind );
 
     /**
-     * Unbinds all addresses which were bound by this acceptor.
+     * Bind to the configured local address and start to accept incoming connections.
+     * 
+     * @throws IOException if failed to bind
+     */
+    void bind() throws IOException;
+    
+    /**
+     * Unbind from the configured local address and stop to accept incoming connections.
+     * All managed connections will be closed if <tt>disconnectOnUnbind</tt> property is set.
+     * This method does nothing if not bound yet.
      */
-    void unbindAll();
+    void unbind();
     
     /**
-     * (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)}.
+     * Returns <tt>true</tt> if and if only this service is bound to the local address.
+     */
+    boolean isBound();
+
+    /**
+     * (Optional) Returns an {@link IoSession} that is bound to the current
+     * local address and the specified <tt>remoteAddress</tt> which reuses
+     * the local address that is already bound by this service.
      * <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)})
+     * @throws IllegalStateException if this service is not running.
      */
-    IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress );
+    IoSession newSession( SocketAddress remoteAddress );
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoConnector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoConnector.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoConnector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoConnector.java Wed Oct 18 23:42:06 2006
@@ -43,44 +43,47 @@
 public interface IoConnector extends IoService
 {
     /**
-     * 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
+     * Returns the local address to bind.
+     * @return <tt>null</tt> if no local address is specified.
      */
-    ConnectFuture connect( SocketAddress address, IoHandler handler );
+    SocketAddress getLocalAddress();
     
     /**
-     * Connects to the specified <code>address</code>.  If communication starts
-     * successfully, events are fired to the specified
-     * <code>handler</code>.
-     * 
-     * @param config the configuration
-     * @return {@link ConnectFuture} that will tell the result of the connection attempt
+     * Sets the local address to bind.
+     * @param localAddress <tt>null</tt> to specify no specific local address 
+     */
+    void setLocalAddress( SocketAddress localAddress );
+    
+    /**
+     * Returns the address of the remote peer to connect to.
+     */
+    SocketAddress getRemoteAddress();
+    
+    /**
+     * Sets the address of the remote peer to connect to.
      */
-    ConnectFuture connect( SocketAddress address, IoHandler handler,
-                           IoServiceConfig config );
+    void setRemoteAddress( SocketAddress remoteAddress );
+    
+    /**
+     * Returns the connect timeout in seconds.  The default value is 1 minute.
+     */
+    int getConnectTimeout();
 
     /**
-     * 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
+     * Returns the connect timeout in milliseconds.  The default value is 1 minute.
      */
-    ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                           IoHandler handler );
+    long getConnectTimeoutMillis();
 
     /**
-     * Connects to the specified <code>address</code>.  If communication starts
-     * successfully, events are fired to the specified
-     * <code>handler</code>.
+     * Sets the connect timeout in seconds.  The default value is 1 minute.
+     */
+    void setConnectTimeout( int connectTimeout );
+    
+    /**
+     * Connects to the configured remote address.
      * 
-     * @param config the configuration
-     * @return {@link ConnectFuture} that will tell the result of the connection attempt
+     * @return the {@link ConnectFuture} instance which is completed when the 
+     *         connection attempt initiated by this call succeeds or fails.
      */
-    ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                           IoHandler handler, IoServiceConfig config );
+    ConnectFuture connect();
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoService.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoService.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoService.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoService.java Wed Oct 18 23:42:06 2006
@@ -45,52 +45,51 @@
     void removeListener( IoServiceListener listener );
     
     /**
-     * Returns all {@link SocketAddress}es this service is managing.
-     * If this service is an {@link IoAcceptor}, a set of bind addresses will
-     * be returned.  If this service is an {@link IoConnector}, a set of remote
-     * addresses will be returned.
+     * Returns the handler which will handle all connections managed by this service.
      */
-    Set getManagedServiceAddresses();
+    IoHandler getHandler();
     
     /**
-     * Returns <tt>true</tt> if this service is managing the specified <tt>serviceAddress</tt>.
-     * If this service is an {@link IoAcceptor}, <tt>serviceAddress</tt> is a bind address.
-     * If this service is an {@link IoConnector}, <tt>serviceAddress</tt> is a remote address.
+     * Sets the handler which will handle all connections managed by this service.
      */
-    boolean isManaged( SocketAddress serviceAddress );
+    void setHandler( IoHandler handler );
     
     /**
-     * Returns all sessions with the specified remote or local address,
-     * which are currently managed by this service.
+     * Returns the {@link SocketAddress} this service is managing.
+     * If this service is an {@link IoAcceptor}, the bind address will
+     * be returned.  If this service is an {@link IoConnector}, the remote
+     * address will be returned.
+     */
+    SocketAddress getServiceAddress();
+    
+    /**
+     * Returns all sessions which are currently managed by this service.
      * {@link IoAcceptor} will assume the specified <tt>address</tt> is a local
      * address, and {@link IoConnector} will assume it's a remote address.
      * 
-     * @param serviceAddress the address to return all sessions for.
      * @return the sessions. An empty collection if there's no session.
-     * @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 IoService}.
      */
-    Set getManagedSessions( SocketAddress serviceAddress );
+    Set getManagedSessions();
 
     /**
-     * Returns the default configuration which is used when you didn't specify
-     * any configuration.
+     * Resturns the default configuration of the new {@link IoSession}s
+     * created by this service.
      */
-    IoServiceConfig getDefaultConfig();
+    IoSessionConfig getSessionConfig();
     
     /**
-     * Returns the global {@link IoFilterChainBuilder} which will modify the
-     * {@link IoFilterChain} of all {@link IoSession}s which is managed
+     * Returns the {@link IoFilterChainBuilder} which will build the
+     * {@link IoFilterChain} of all {@link IoSession}s which is created
      * by this service.
      * The default value is an empty {@link DefaultIoFilterChainBuilder}.
      */
     IoFilterChainBuilder getFilterChainBuilder();
     
     /**
-     * Sets the global {@link IoFilterChainBuilder} which will modify the
-     * {@link IoFilterChain} of all {@link IoSession}s which is managed
+     * Sets the {@link IoFilterChainBuilder} which will build the
+     * {@link IoFilterChain} of all {@link IoSession}s which is created
      * by this service.
      * If you specify <tt>null</tt> this property will be set to
      * an empty {@link DefaultIoFilterChainBuilder}.
@@ -108,4 +107,24 @@
      *                               not a {@link DefaultIoFilterChainBuilder}
      */
     DefaultIoFilterChainBuilder getFilterChain();
+    
+    /**
+     * Returns the default {@link ThreadModel} of the {@link IoService}.
+     * The default value is an {@link ExecutorThreadModel} whose service name is
+     * <tt>'AnonymousIoService'</tt> and which has 16 maximum active threads.
+     * It is strongly recommended to set a new {@link ExecutorThreadModel} by calling
+     * {@link ExecutorThreadModel#getInstance(String)}.
+     */
+    ThreadModel getThreadModel();
+    
+    /**
+     * Sets the default {@link ThreadModel} of the {@link IoService}.
+     * If you specify <tt>null</tt>, this property will be set to the
+     * default value.
+     * The default value is an {@link ExecutorThreadModel} whose service name is
+     * <tt>'AnonymousIoService'</tt> with 16 threads.
+     * It is strongly recommended to set a new {@link ExecutorThreadModel} by calling
+     * {@link ExecutorThreadModel#getInstance(String)}.
+     */
+    void setThreadModel( ThreadModel threadModel );
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java Wed Oct 18 23:42:06 2006
@@ -19,7 +19,6 @@
  */
 package org.apache.mina.common;
 
-import java.net.SocketAddress;
 import java.util.EventListener;
 
 /**
@@ -35,27 +34,15 @@
      * Invoked when a new service is activated by an {@link IoService}.
      * 
      * @param service the {@link IoService}
-     * @param serviceAddress the socket address of the {@link IoService} listens
-     *                       to manage sessions.  If the service is an {@link IoAcceptor},
-     *                       it is a bind address.  If the service is an {@link IoConnector},
-     *                       it is a remote address.
-     * @param handler the {@link IoHandler} that serves the new service
-     * @param config  the {@link IoServiceConfig} of the new service
      */
-    void serviceActivated( IoService service, SocketAddress serviceAddress, IoHandler handler, IoServiceConfig config );
+    void serviceActivated( IoService service );
     
     /**
      * Invoked when a service is deactivated by an {@link IoService}.
      * 
      * @param service the {@link IoService}
-     * @param serviceAddress the socket address of the {@link IoService} listens
-     *                       to manage sessions.  If the service is an {@link IoAcceptor},
-     *                       it is a bind address.  If the service is an {@link IoConnector},
-     *                       it is a remote address.
-     * @param handler the {@link IoHandler} that serves the service
-     * @param config  the {@link IoServiceConfig} of the service
      */
-    void serviceDeactivated( IoService service, SocketAddress serviceAddress, IoHandler handler, IoServiceConfig config );
+    void serviceDeactivated( IoService service );
     
     /**
      * Invoked when a new session is created by an {@link IoService}.

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java Wed Oct 18 23:42:06 2006
@@ -56,11 +56,6 @@
     IoService getService();
     
     /**
-     * Returns the {@link IoServiceConfig} of this session.
-     */
-    IoServiceConfig getServiceConfig();
-
-    /**
      * Returns the {@link IoHandler} which handles this session.
      */
     IoHandler getHandler();

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java Wed Oct 18 23:42:06 2006
@@ -23,8 +23,6 @@
 import java.net.SocketAddress;
 
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
 
 /**
  * A base implementation of {@link IoAcceptor}.
@@ -34,17 +32,120 @@
  */
 public abstract class BaseIoAcceptor extends BaseIoService implements IoAcceptor
 {
+    private SocketAddress localAddress;
+    private boolean disconnectOnUnbind = true;
+    private boolean bound;
+
+    /**
+     * The lock object which is acquired while bind or unbind operation is performed.
+     * Acquire this lock in your property setters which shouldn't be changed while
+     * the service is bound.
+     */
+    protected final Object bindLock = new Object();
+
     protected BaseIoAcceptor()
     {
     }
     
-    public void bind( SocketAddress address, IoHandler handler ) throws IOException
+    public SocketAddress getServiceAddress()
+    {
+        return getLocalAddress();
+    }
+    
+    public SocketAddress getLocalAddress()
+    {
+        return localAddress;
+    }
+    
+    public void setLocalAddress( SocketAddress localAddress )
     {
-        this.bind( address, handler, getDefaultConfig() );
+        if( localAddress == null )
+        {
+            throw new NullPointerException( "localAddress" );
+        }
+        
+        if( !getAddressType().isAssignableFrom( localAddress.getClass() ) )
+        {
+            throw new IllegalArgumentException(
+                    "localAddress type: " + localAddress.getClass() + 
+                    " (expected: " + getAddressType() + ")");
+        }
+        
+        synchronized( bindLock )
+        {
+            if( bound )
+            {
+                throw new IllegalStateException(
+                        "localAddress can't be set while the acceptor is bound." );
+            }
+    
+            this.localAddress = localAddress;
+        }
     }
     
-    public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
+    public boolean isDisconnectOnUnbind()
+    {
+        return disconnectOnUnbind;
+    }
+
+    public void setDisconnectOnUnbind( boolean disconnectClientsOnUnbind )
     {
-        throw new UnsupportedOperationException();
+        this.disconnectOnUnbind = disconnectClientsOnUnbind;
     }
+    
+    public final void bind() throws IOException
+    {
+        synchronized( bindLock )
+        {
+            if( bound )
+            {
+                throw new IllegalStateException( "Already bound to: " + getLocalAddress() );
+            }
+            
+            if( getLocalAddress() == null )
+            {
+                throw new IllegalStateException( "localAddress is not set." );
+            }
+            
+            if( getHandler() == null )
+            {
+                throw new IllegalStateException( "handler is not set." );
+            }
+            
+            doBind();
+            bound = true;
+        }
+    }
+    
+    public final void unbind()
+    {
+        synchronized( bindLock )
+        {
+            if( !bound )
+            {
+                return;
+            }
+            
+            doUnbind();
+            bound = false;
+        }
+    }
+    
+    public boolean isBound()
+    {
+        synchronized( bindLock )
+        {
+            return bound;
+        }
+    }
+
+    /**
+     * Implement this method to perform the actual bind operation.
+     */
+    protected abstract void doBind() throws IOException;
+
+    /**
+     * Implement this method to perform the actual unbind operation.
+     */
+    protected abstract void doUnbind();
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoConnector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoConnector.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoConnector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoConnector.java Wed Oct 18 23:42:06 2006
@@ -23,7 +23,6 @@
 
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoConnector;
-import org.apache.mina.common.IoHandler;
 
 /**
  * A base implementation of {@link IoConnector}.
@@ -33,17 +32,89 @@
  */
 public abstract class BaseIoConnector extends BaseIoService implements IoConnector
 {
+    private SocketAddress localAddress;
+    private SocketAddress remoteAddress;
+    private int connectTimeout = 60; // 1 minute
+
     protected BaseIoConnector()
     {
     }
 
-    public ConnectFuture connect( SocketAddress address, IoHandler handler )
+    public SocketAddress getServiceAddress()
+    {
+        return getRemoteAddress();
+    }
+    
+    public SocketAddress getLocalAddress()
     {
-        return connect( address, handler, getDefaultConfig() );
+        return localAddress;
+    }
+
+    public void setLocalAddress( SocketAddress localAddress )
+    {
+        if( localAddress != null && !getAddressType().isAssignableFrom( localAddress.getClass() ) )
+        {
+            throw new IllegalArgumentException(
+                    "localAddress type: " + localAddress.getClass() + 
+                    " (expected: " + getAddressType() + ")");
+        }
+
+        this.localAddress = localAddress;
     }
 
-    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress, IoHandler handler )
+    public SocketAddress getRemoteAddress()
     {
-        return connect( address, localAddress, handler, getDefaultConfig() );
+        return remoteAddress;
     }
+
+    public void setRemoteAddress( SocketAddress remoteAddress )
+    {
+        if( remoteAddress == null )
+        {
+            throw new NullPointerException( "remoteAddress" );
+        }
+
+        if( !getAddressType().isAssignableFrom( remoteAddress.getClass() ) )
+        {
+            throw new IllegalArgumentException(
+                    "remoteAddress type: " + remoteAddress.getClass() + 
+                    " (expected: " + getAddressType() + ")");
+        }
+
+        this.remoteAddress = remoteAddress;
+    }
+
+    public int getConnectTimeout()
+    {
+        return connectTimeout;
+    }
+
+    public long getConnectTimeoutMillis()
+    {
+        return connectTimeout * 1000L;
+    }
+
+    public void setConnectTimeout( int connectTimeout )
+    {
+        if( connectTimeout <= 0 )
+        {
+            throw new IllegalArgumentException( "connectTimeout: " + connectTimeout );
+        }
+        this.connectTimeout = connectTimeout;
+    }
+    
+    public final ConnectFuture connect()
+    {
+        if( getRemoteAddress() == null )
+            throw new IllegalStateException( "remoteAddress is not set." );
+        if( getHandler() == null )
+            throw new IllegalStateException( "handler is not set." );
+
+        return doConnect();
+    }
+
+    /**
+     * Implement this method to perform the actual connect operation.
+     */
+    protected abstract ConnectFuture doConnect();
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoService.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoService.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoService.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoService.java Wed Oct 18 23:42:06 2006
@@ -19,13 +19,15 @@
  */
 package org.apache.mina.common.support;
 
-import java.net.SocketAddress;
 import java.util.Set;
 
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.ExecutorThreadModel;
 import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
 import org.apache.mina.common.IoServiceListener;
+import org.apache.mina.common.ThreadModel;
 
 /**
  * Base implementation of {@link IoService}s.
@@ -36,20 +38,40 @@
 public abstract class BaseIoService implements IoService
 {
     /**
+     * The default thread model.
+     */
+    private final ThreadModel defaultThreadModel = ExecutorThreadModel.getInstance("AnonymousIoService");
+    
+    /**
      * Current filter chain builder.
      */
     private IoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
 
     /**
+     * Current thread model.
+     */
+    private ThreadModel threadModel = defaultThreadModel;
+    
+    /**
+     * Current handler.
+     */    
+    private IoHandler handler;
+
+    /**
      * Maintains the {@link IoServiceListener}s of this service.
      */
     private final IoServiceListenerSupport listeners;
     
     protected BaseIoService()
     {
-        this.listeners = new IoServiceListenerSupport();
+        this.listeners = new IoServiceListenerSupport( this );
     }
     
+    /**
+     * Returns the type of {@link SocketAddress} this service uses.
+     */
+    protected abstract Class getAddressType();
+    
     public IoFilterChainBuilder getFilterChainBuilder()
     {
         return filterChainBuilder;
@@ -77,6 +99,22 @@
         }
     }
     
+    public ThreadModel getThreadModel()
+    {
+        return threadModel;
+    }
+
+    public void setThreadModel( ThreadModel threadModel )
+    {
+        if( threadModel == null )
+        {
+            // We reuse the previous default model to prevent too much
+            // daemon threads are created.
+            threadModel = defaultThreadModel;
+        }
+        this.threadModel = threadModel;
+    }
+
     public void addListener( IoServiceListener listener )
     {
         getListeners().add( listener );
@@ -87,19 +125,24 @@
         getListeners().remove( listener );
     }
     
-    public Set getManagedServiceAddresses()
+    public Set getManagedSessions()
     {
-        return getListeners().getManagedServiceAddresses();
+        return getListeners().getManagedSessions();
     }
-
-    public Set getManagedSessions( SocketAddress serviceAddress )
+    
+    public IoHandler getHandler()
     {
-        return getListeners().getManagedSessions( serviceAddress );
+        return handler;
     }
-
-    public boolean isManaged( SocketAddress serviceAddress )
+    
+    public void setHandler( IoHandler handler )
     {
-        return getListeners().isManaged( serviceAddress );
+        if( handler == null )
+        {
+            throw new NullPointerException( "handler" );
+        }
+
+        this.handler = handler;
     }
 
     protected IoServiceListenerSupport getListeners()

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java Wed Oct 18 23:42:06 2006
@@ -27,9 +27,10 @@
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoFilterChainBuilder;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoServiceListener;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.ThreadModel;
 
 /**
  * A delegated {@link IoAcceptor} that wraps the other {@link IoAcceptor}.
@@ -56,74 +57,104 @@
     {
         this.delegate = delegate;
     }
-    
-    public void bind( SocketAddress address, IoHandler handler ) throws IOException
+
+    public IoFilterChainBuilder getFilterChainBuilder()
     {
-        delegate.bind( address, handler );
+        return delegate.getFilterChainBuilder();
     }
 
-    public void bind( SocketAddress address, IoHandler handler, IoServiceConfig config ) throws IOException
+    public void setFilterChainBuilder( IoFilterChainBuilder builder )
     {
-        delegate.bind( address, handler, config );
+        delegate.setFilterChainBuilder( builder );
     }
 
-    public void unbind( SocketAddress address )
+    public DefaultIoFilterChainBuilder getFilterChain()
     {
-        delegate.unbind( address );
+        return delegate.getFilterChain();
     }
-    
-    public void unbindAll()
+
+    public void addListener( IoServiceListener listener )
     {
-        delegate.unbindAll();
+        delegate.addListener( listener );
     }
-    
-    public boolean isManaged( SocketAddress address )
+
+    public void removeListener( IoServiceListener listener )
     {
-        return delegate.isManaged( address );
+        delegate.removeListener( listener );
     }
 
-    public Set getManagedServiceAddresses()
+    public void bind() throws IOException
     {
-        return delegate.getManagedServiceAddresses();
+        delegate.bind();
     }
 
-    public Set getManagedSessions( SocketAddress serviceAddress )
+    public SocketAddress getLocalAddress()
     {
-        return delegate.getManagedSessions( serviceAddress );
+        return delegate.getLocalAddress();
     }
 
-    public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
+    public boolean isDisconnectOnUnbind()
     {
-        return delegate.newSession( remoteAddress, localAddress );
+        return delegate.isDisconnectOnUnbind();
     }
 
-    public IoServiceConfig getDefaultConfig()
+    public IoSession newSession( SocketAddress remoteAddress )
     {
-        return delegate.getDefaultConfig();
+        return delegate.newSession( remoteAddress );
     }
 
-    public IoFilterChainBuilder getFilterChainBuilder()
+    public void setDisconnectOnUnbind( boolean disconnectOnUnbind )
     {
-        return delegate.getFilterChainBuilder();
+        delegate.setDisconnectOnUnbind( disconnectOnUnbind );
     }
 
-    public void setFilterChainBuilder( IoFilterChainBuilder builder )
+    public void setLocalAddress( SocketAddress localAddress )
     {
-        delegate.setFilterChainBuilder( builder );
+        delegate.setLocalAddress( localAddress );
     }
 
-    public DefaultIoFilterChainBuilder getFilterChain()
+    public void unbind()
     {
-        return delegate.getFilterChain();
+        delegate.unbind();
     }
 
-    public void addListener( IoServiceListener listener )
+    public IoHandler getHandler()
     {
-        delegate.addListener( listener );
+        return delegate.getHandler();
     }
 
-    public void removeListener( IoServiceListener listener )
+    public Set getManagedSessions()
     {
-        delegate.removeListener( listener );
+        return delegate.getManagedSessions();
+    }
+
+    public SocketAddress getServiceAddress()
+    {
+        return delegate.getServiceAddress();
+    }
+
+    public IoSessionConfig getSessionConfig()
+    {
+        return delegate.getSessionConfig();
+    }
+
+    public ThreadModel getThreadModel()
+    {
+        return delegate.getThreadModel();
+    }
+
+    public void setHandler( IoHandler handler )
+    {
+        delegate.setHandler( handler );
+    }
+
+    public void setThreadModel( ThreadModel threadModel )
+    {
+        delegate.setThreadModel( threadModel );
+    }
+
+    public boolean isBound()
+    {
+        return delegate.isBound();
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java Wed Oct 18 23:42:06 2006
@@ -27,8 +27,9 @@
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoFilterChainBuilder;
 import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoServiceListener;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.ThreadModel;
 
 /**
  * A delegated {@link IoConnector} that wraps the other {@link IoConnector}.
@@ -56,70 +57,103 @@
         this.delegate = delegate;
     }
     
-    public ConnectFuture connect( SocketAddress address, IoHandler handler )
+    public IoFilterChainBuilder getFilterChainBuilder()
     {
-        return delegate.connect( address, handler );
+        return delegate.getFilterChainBuilder();
     }
 
-    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoServiceConfig config )
+    public void setFilterChainBuilder( IoFilterChainBuilder builder )
     {
-        return delegate.connect( address, handler, config );
+        delegate.setFilterChainBuilder( builder );
     }
 
-    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                                  IoHandler handler )
+    public DefaultIoFilterChainBuilder getFilterChain()
     {
-        return delegate.connect( address, localAddress, handler );
+        return delegate.getFilterChain();
     }
 
-    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                                  IoHandler handler, IoServiceConfig config )
+    public void addListener( IoServiceListener listener )
     {
-        return delegate.connect( address, localAddress, handler, config );
+        delegate.addListener( listener );
     }
 
-    public boolean isManaged( SocketAddress serviceAddress )
+    public void removeListener( IoServiceListener listener )
     {
-        return delegate.isManaged( serviceAddress );
+        delegate.removeListener( listener );
     }
-    
-    public Set getManagedServiceAddresses()
+
+    public ConnectFuture connect()
     {
-        return delegate.getManagedServiceAddresses();
+        return delegate.connect();
     }
 
-    public Set getManagedSessions( SocketAddress serviceAddress )
+    public int getConnectTimeout()
     {
-        return delegate.getManagedSessions( serviceAddress );
+        return delegate.getConnectTimeout();
     }
-    
-    public IoServiceConfig getDefaultConfig()
+
+    public long getConnectTimeoutMillis()
     {
-        return delegate.getDefaultConfig();
+        return delegate.getConnectTimeoutMillis();
     }
 
-    public IoFilterChainBuilder getFilterChainBuilder()
+    public SocketAddress getLocalAddress()
     {
-        return delegate.getFilterChainBuilder();
+        return delegate.getLocalAddress();
     }
 
-    public void setFilterChainBuilder( IoFilterChainBuilder builder )
+    public SocketAddress getRemoteAddress()
     {
-        delegate.setFilterChainBuilder( builder );
+        return delegate.getRemoteAddress();
     }
 
-    public DefaultIoFilterChainBuilder getFilterChain()
+    public void setConnectTimeout( int connectTimeout )
     {
-        return delegate.getFilterChain();
+        delegate.setConnectTimeout( connectTimeout );
     }
 
-    public void addListener( IoServiceListener listener )
+    public void setLocalAddress( SocketAddress localAddress )
     {
-        delegate.addListener( listener );
+        delegate.setLocalAddress( localAddress );
     }
 
-    public void removeListener( IoServiceListener listener )
+    public void setRemoteAddress( SocketAddress remoteAddress )
     {
-        delegate.removeListener( listener );
+        delegate.setRemoteAddress( remoteAddress );
+    }
+
+    public IoHandler getHandler()
+    {
+        return delegate.getHandler();
+    }
+
+    public Set getManagedSessions()
+    {
+        return delegate.getManagedSessions();
+    }
+
+    public SocketAddress getServiceAddress()
+    {
+        return delegate.getServiceAddress();
+    }
+
+    public IoSessionConfig getSessionConfig()
+    {
+        return delegate.getSessionConfig();
+    }
+
+    public ThreadModel getThreadModel()
+    {
+        return delegate.getThreadModel();
+    }
+
+    public void setHandler( IoHandler handler )
+    {
+        delegate.setHandler( handler );
+    }
+
+    public void setThreadModel( ThreadModel threadModel )
+    {
+        delegate.setThreadModel( threadModel );
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java Wed Oct 18 23:42:06 2006
@@ -19,23 +19,16 @@
  */
 package org.apache.mina.common.support;
 
-import java.net.SocketAddress;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
-import org.apache.mina.common.IoAcceptorConfig;
+import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoFuture;
 import org.apache.mina.common.IoFutureListener;
-import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
-import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoServiceListener;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.IdentityHashSet;
@@ -50,25 +43,32 @@
 public class IoServiceListenerSupport
 {
     /**
+     * The {@link IoService} that this instance manages.
+     */
+    private final IoService service;
+    
+    /**
      * A list of {@link IoServiceListener}s.
      */
     private final List listeners = new ArrayList();
 
     /**
-     * Tracks managed <tt>serviceAddress</tt>es.
+     * Tracks managed sesssions.
      */
-    private final Set managedServiceAddresses = new HashSet();
+    private final Set managedSessions = new IdentityHashSet();
     
-    /**
-     * Tracks managed sesssions with <tt>serviceAddress</tt> as a key.
-     */
-    private final Map managedSessions = new HashMap();
+    private boolean activated;
     
     /**
      * Creates a new instance.
      */
-    public IoServiceListenerSupport()
+    public IoServiceListenerSupport( IoService service )
     {
+        if( service == null )
+        {
+            throw new NullPointerException( "service" );
+        }
+        this.service = service;
     }
     
     /**
@@ -93,93 +93,78 @@
         }
     }
     
-    public Set getManagedServiceAddresses()
-    {
-        return Collections.unmodifiableSet( managedServiceAddresses );
-    }
-
-    public boolean isManaged( SocketAddress serviceAddress )
+    public Set getManagedSessions()
     {
-        synchronized( managedServiceAddresses )
-        {
-            return managedServiceAddresses.contains( serviceAddress );
-        }
-    }
-
-    public Set getManagedSessions( SocketAddress serviceAddress )
-    {
-        Set sessions;
         synchronized( managedSessions )
         {
-            sessions = ( Set ) managedSessions.get( serviceAddress );
-            if( sessions == null )
-            {
-                sessions = new IdentityHashSet();
-            }
-        }
-        
-        synchronized( sessions )
-        {
-            return new IdentityHashSet( sessions );
+            return new IdentityHashSet( managedSessions );
         }
     }
 
     /**
-     * Calls {@link IoServiceListener#serviceActivated(IoService, SocketAddress, IoHandler, IoServiceConfig)}
+     * Calls {@link IoServiceListener#serviceActivated(IoService)}
      * for all registered listeners.
      */
-    public void fireServiceActivated(
-            IoService service, SocketAddress serviceAddress,
-            IoHandler handler, IoServiceConfig config )
+    public void fireServiceActivated()
     {
-        synchronized( managedServiceAddresses )
+        synchronized( listeners )
         {
-            if( !managedServiceAddresses.add( serviceAddress ) )
+            if( activated )
             {
                 return;
             }
-        }
-
-        synchronized( listeners )
-        {
-            for( Iterator i = listeners.iterator(); i.hasNext(); )
+            
+            try
             {
-                ( ( IoServiceListener ) i.next() ).serviceActivated(
-                        service, serviceAddress, handler, config );
+                for( Iterator i = listeners.iterator(); i.hasNext(); )
+                {
+                    ( ( IoServiceListener ) i.next() ).serviceActivated( service );
+                }
+            }
+            finally
+            {
+                activated = true;
             }
         }
     }
     
     /**
-     * Calls {@link IoServiceListener#serviceDeactivated(IoService, SocketAddress, IoHandler, IoServiceConfig)}
+     * Calls {@link IoServiceListener#serviceDeactivated(IoService)}
      * for all registered listeners.
      */
-    public synchronized void fireServiceDeactivated(
-            IoService service, SocketAddress serviceAddress,
-            IoHandler handler, IoServiceConfig config )
+    public void fireServiceDeactivated()
     {
-        synchronized( managedServiceAddresses )
-        {
-            if( !managedServiceAddresses.remove( serviceAddress ) )
-            {
-                return;
-            }
-        }
-        
+        boolean disconnect = false;
         try
         {
             synchronized( listeners )
             {
-                for( Iterator i = listeners.iterator(); i.hasNext(); )
+                if( !activated )
+                {
+                    return;
+                }
+                
+                disconnect = true;
+
+                try
+                {
+                    for( Iterator i = listeners.iterator(); i.hasNext(); )
+                    {
+                        ( ( IoServiceListener ) i.next() ).serviceDeactivated( service );
+                    }
+                }
+                finally
                 {
-                    ( ( IoServiceListener ) i.next() ).serviceDeactivated(
-                            service, serviceAddress, handler, config );
+                    activated = false;
                 }
             }
         }
         finally
         {
-            disconnectSessions( serviceAddress, config );
+            if( disconnect )
+            {
+                disconnectSessions();
+            }
         }
     }
     
@@ -189,26 +174,13 @@
      */
     public void fireSessionCreated( IoSession session )
     {
-        SocketAddress serviceAddress = session.getServiceAddress();
-        
-        // Get the session set.
         boolean firstSession = false;
-        Set sessions;
         synchronized( managedSessions )
         {
-            sessions = ( Set ) managedSessions.get( serviceAddress );
-            if( sessions == null )
-            {
-                sessions = new IdentityHashSet();
-                managedSessions.put( serviceAddress, sessions );
-                firstSession = true;
-            }
-        }
-        
-        // If already registered, ignore.
-        synchronized( sessions )
-        {
-            if ( !sessions.add( session ) )
+            firstSession = managedSessions.isEmpty();
+
+            // If already registered, ignore.
+            if ( !managedSessions.add( session ) )
             {
                 return;
             }
@@ -217,9 +189,7 @@
         // If the first connector session, fire a virtual service activation event.
         if( session.getService() instanceof IoConnector && firstSession )
         {
-            fireServiceActivated(
-                    session.getService(), session.getServiceAddress(),
-                    session.getHandler(), session.getServiceConfig() );
+            fireServiceActivated();
         }
 
         // Fire session events.
@@ -241,30 +211,16 @@
      */
     public void fireSessionDestroyed( IoSession session )
     {
-        SocketAddress serviceAddress = session.getServiceAddress();
-        
-        // Get the session set.
-        Set sessions;
         boolean lastSession = false;
         synchronized( managedSessions )
         {
-            sessions = ( Set ) managedSessions.get( serviceAddress );
-            // Ignore if unknown.
-            if( sessions == null )
+            // Try to remove the remaining empty seession set after removal.
+            if( !managedSessions.remove( session ) )
             {
                 return;
             }
             
-            // Try to remove the remaining empty seession set after removal.
-            synchronized( sessions )
-            {
-                sessions.remove( session );
-                if( sessions.isEmpty() )
-                {
-                    managedSessions.remove( serviceAddress );
-                    lastSession = true;
-                }
-            }
+            lastSession = managedSessions.isEmpty();
         }
         
         // Fire session events.
@@ -284,46 +240,30 @@
         finally
         {
             // Fire a virtual service deactivation event for the last session of the connector.
-            //TODO double-check that this is *STILL* the last session. May not be the case
             if( session.getService() instanceof IoConnector && lastSession )
             {
-                fireServiceDeactivated(
-                        session.getService(), session.getServiceAddress(),
-                        session.getHandler(), session.getServiceConfig() );
+                fireServiceDeactivated();
             }
         }
     }
 
-    private void disconnectSessions( SocketAddress serviceAddress, IoServiceConfig config )
+    private void disconnectSessions()
     {
-        if( !( config instanceof IoAcceptorConfig ) )
+        if( !( service instanceof IoAcceptor ) )
         {
             return;
         }
 
-        if( !( ( IoAcceptorConfig ) config ).isDisconnectOnUnbind() )
-        {
-            return;
-        }
-
-        Set sessions;
-        synchronized( managedSessions )
-        {
-            sessions = ( Set ) managedSessions.get( serviceAddress );
-        }
-        
-        if( sessions == null )
+        if( !( ( IoAcceptor ) service ).isDisconnectOnUnbind() )
         {
             return;
         }
 
         final Object lock = new Object();
         Set sessionsCopy;
-        
-        // Create a copy to avoid ConcurrentModificationException
-        synchronized( sessions )
+        synchronized( managedSessions )
         {
-            sessionsCopy = new IdentityHashSet( sessions );
+            sessionsCopy = new IdentityHashSet( managedSessions );
         }
         
         for( Iterator i = sessionsCopy.iterator(); i.hasNext(); )

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java Wed Oct 18 23:42:06 2006
@@ -20,14 +20,11 @@
 package org.apache.mina.management;
 
 
-import java.net.SocketAddress;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
-import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoServiceListener;
 import org.apache.mina.common.IoSession;
 
@@ -71,13 +68,11 @@
 
     private final IoServiceListener serviceListener = new IoServiceListener()
     {
-        public void serviceActivated( IoService service, SocketAddress serviceAddress, IoHandler handler,
-            IoServiceConfig config )
+        public void serviceActivated( IoService service )
         {
         }
 
-        public void serviceDeactivated( IoService service, SocketAddress serviceAddress, IoHandler handler,
-            IoServiceConfig config )
+        public void serviceDeactivated( IoService service )
         {
         }
 
@@ -128,15 +123,9 @@
     
             polledSessions = new ArrayList();
     
-            for ( Iterator iter = service.getManagedServiceAddresses().iterator(); iter.hasNext(); )
+            for ( Iterator iter = service.getManagedSessions().iterator(); iter.hasNext(); )
             {
-                SocketAddress element = ( SocketAddress ) iter.next();
-    
-                for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext(); )
-                {
-                    addSession( ( IoSession ) iter2.next() );
-    
-                }
+                addSession( ( IoSession ) iter.next() );
             }
 
             // listen for new ones

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java Wed Oct 18 23:42:06 2006
@@ -20,6 +20,7 @@
 package org.apache.mina.transport.socket.nio;
 
 import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoSessionRecycler;
 import org.apache.mina.common.support.DelegatedIoAcceptor;
 import org.apache.mina.transport.socket.nio.support.DatagramAcceptorDelegate;
 import org.apache.mina.util.NewThreadExecutor;
@@ -32,7 +33,7 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class DatagramAcceptor extends DelegatedIoAcceptor
+public class DatagramAcceptor extends DelegatedIoAcceptor implements DatagramService
 {
     /**
      * Creates a new instance using a NewThreadExecutor
@@ -51,15 +52,14 @@
     {
         init( new DatagramAcceptorDelegate( this, executor ) );
     }
-    
-    /**
-     * Sets the config this acceptor will use by default.
-     * 
-     * @param defaultConfig the default config.
-     * @throws NullPointerException if the specified value is <code>null</code>.
-     */
-    public void setDefaultConfig( DatagramAcceptorConfig defaultConfig )
+
+    public IoSessionRecycler getSessionRecycler()
     {
-        ( ( DatagramAcceptorDelegate ) delegate ).setDefaultConfig( defaultConfig );
-    }    
+        return ( ( DatagramAcceptorDelegate ) delegate ).getSessionRecycler();
+    }
+
+    public void setSessionRecycler( IoSessionRecycler sessionRecycler )
+    {
+        ( ( DatagramAcceptorDelegate ) delegate ).setSessionRecycler( sessionRecycler );
+    }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramConnector.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramConnector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramConnector.java Wed Oct 18 23:42:06 2006
@@ -20,9 +20,11 @@
 package org.apache.mina.transport.socket.nio;
 
 import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoSessionRecycler;
 import org.apache.mina.common.support.DelegatedIoConnector;
 import org.apache.mina.transport.socket.nio.support.DatagramConnectorDelegate;
 import org.apache.mina.util.NewThreadExecutor;
+
 import edu.emory.mathcs.backport.java.util.concurrent.Executor;
 
 /**
@@ -31,7 +33,7 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class DatagramConnector extends DelegatedIoConnector
+public class DatagramConnector extends DelegatedIoConnector implements DatagramService
 {
     /**
      * Creates a new instance using a NewThreadExecutor 
@@ -51,14 +53,13 @@
         init( new DatagramConnectorDelegate( this, executor ) );
     }
     
-    /**
-     * Sets the default config this connector should use.
-     * 
-     * @param defaultConfig the default config.
-     * @throws NullPointerException if the specified value is <code>null</code>.
-     */
-    public void setDefaultConfig( DatagramConnectorConfig defaultConfig )
+    public IoSessionRecycler getSessionRecycler()
+    {
+        return ( ( DatagramConnectorDelegate ) delegate ).getSessionRecycler();
+    }
+
+    public void setSessionRecycler( IoSessionRecycler sessionRecycler )
     {
-        ( ( DatagramConnectorDelegate ) delegate ).setDefaultConfig( defaultConfig );
+        ( ( DatagramConnectorDelegate ) delegate ).setSessionRecycler( sessionRecycler );
     }
 }

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramService.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramService.java?view=auto&rev=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramService.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramService.java Wed Oct 18 23:42:06 2006
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.mina.common.IoSessionRecycler;
+
+
+/**
+ * A base interface for {@link DatagramAcceptor} and {@link DatagramConnector}.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface DatagramService
+{
+    /**
+     * Returns the {@link IoSessionRecycler} for this service.
+     */
+    IoSessionRecycler getSessionRecycler();
+
+    /**
+     * Sets the {@link IoSessionRecycler} for this service.
+     * 
+     * @param sessionRecycler <tt>null</tt> to use the default recycler
+     */
+    void setSessionRecycler( IoSessionRecycler sessionRecycler );
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/DatagramService.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java Wed Oct 18 23:42:06 2006
@@ -21,26 +21,25 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.ServerSocket;
 import java.net.SocketAddress;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.mina.common.ExceptionMonitor;
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.RuntimeIOException;
 import org.apache.mina.common.support.BaseIoAcceptor;
-import org.apache.mina.util.Queue;
-import org.apache.mina.util.NewThreadExecutor;
 import org.apache.mina.util.NamePreservingRunnable;
+import org.apache.mina.util.NewThreadExecutor;
+import org.apache.mina.util.Queue;
+
 import edu.emory.mathcs.backport.java.util.concurrent.Executor;
 
 /**
@@ -56,13 +55,16 @@
      */
     private static volatile int nextId = 0;
 
+    private IoSessionConfig sessionConfig = new SocketSessionConfigImpl();
+    private int backlog = 50;
+    private boolean reuseAddress;
+
     private final Executor executor;
     private final Object lock = new Object();
     private final int id = nextId ++;
     private final String threadName = "SocketAcceptor-" + id;
-    private SocketAcceptorConfig defaultConfig = new SocketAcceptorConfig();
-    private final Map channels = new HashMap();
 
+    private ServerSocketChannel serverSocketChannel;
     private final Queue registerQueue = new Queue();
     private final Queue cancelQueue = new Queue();
 
@@ -96,7 +98,34 @@
         {
             throw new IllegalArgumentException( "Must have at least one processor" );
         }
-
+        
+        // Get the default configuration
+        ServerSocket s = null;
+        try
+        {
+            s = new ServerSocket();
+            reuseAddress = s.getReuseAddress();
+        }
+        catch( IOException e )
+        {
+            throw new RuntimeIOException( "Failed to get the default configuration.", e );
+        }
+        finally
+        {
+            if( s != null )
+            {
+                try
+                {
+                    s.close();
+                }
+                catch( IOException e )
+                {
+                    ExceptionMonitor.getInstance().exceptionCaught( e );
+                }
+            }
+        }
+        
+        // Set other properties and initialize
         this.executor = executor;
         this.processorCount = processorCount;
         ioProcessors = new SocketIoProcessor[processorCount];
@@ -107,40 +136,68 @@
         }
     }
 
+    protected Class getAddressType()
+    {
+        return InetSocketAddress.class;
+    }
+
+    public IoSessionConfig getSessionConfig()
+    {
+        return sessionConfig;
+    }
+
     /**
-     * Binds to the specified <code>address</code> and handles incoming connections with the specified
-     * <code>handler</code>.  Backlog value is configured to the value of <code>backlog</code> property.
-     *
-     * @throws IOException if failed to bind
+     * @see ServerSocket#getReuseAddress()
      */
-    public void bind( SocketAddress address, IoHandler handler, IoServiceConfig config ) throws IOException
+    public boolean isReuseAddress()
     {
-        if( address == null )
-        {
-            throw new NullPointerException( "address" );
-        }
+        return reuseAddress;
+    }
 
-        if( handler == null )
+    /**
+     * @see ServerSocket#setReuseAddress(boolean)
+     */
+    public void setReuseAddress( boolean reuseAddress )
+    {
+        synchronized( bindLock )
         {
-            throw new NullPointerException( "handler" );
+            if( isBound() )
+            {
+                throw new IllegalStateException(
+                        "backlog can't be set while the acceptor is bound." );
+            }
+    
+            this.reuseAddress = reuseAddress;
         }
+    }
 
-        if( !( address instanceof InetSocketAddress ) )
-        {
-            throw new IllegalArgumentException( "Unexpected address type: " + address.getClass() );
-        }
+    public int getBacklog()
+    {
+        return backlog;
+    }
 
-        if( ( ( InetSocketAddress ) address ).getPort() == 0 )
+    public void setBacklog( int backlog )
+    {
+        synchronized( bindLock )
         {
-            throw new IllegalArgumentException( "Unsupported port number: 0" );
+            if( isBound() )
+            {
+                throw new IllegalStateException(
+                        "backlog can't be set while the acceptor is bound." );
+            }
+    
+            this.backlog = backlog;
         }
-
-        if( config == null )
+    }
+    
+    protected void doBind() throws IOException
+    {
+        if( ( ( InetSocketAddress ) getLocalAddress() ).getPort() == 0 )
         {
-            config = getDefaultConfig();
+            throw new IllegalStateException( "Unsupported port number: 0" );
         }
 
-        RegistrationRequest request = new RegistrationRequest( address, handler, config );
+        RegistrationRequest request = new RegistrationRequest();
 
         synchronized( registerQueue )
         {
@@ -168,7 +225,19 @@
 
         if( request.exception != null )
         {
-            throw request.exception;
+            // TODO better excaption handling.
+            if( request.exception instanceof RuntimeException )
+            {
+                throw ( RuntimeException ) request.exception;
+            }
+            else if( request.exception instanceof IOException )
+            {
+                throw ( IOException ) request.exception;
+            }
+            else
+            {
+                throw new RuntimeIOException( request.exception );
+            }
         }
     }
 
@@ -187,14 +256,9 @@
         }
     }
 
-    public void unbind( SocketAddress address )
+    protected void doUnbind()
     {
-        if( address == null )
-        {
-            throw new NullPointerException( "address" );
-        }
-
-        CancellationRequest request = new CancellationRequest( address );
+        CancellationRequest request = new CancellationRequest();
 
         try
         {
@@ -206,7 +270,7 @@
             // running and failed to open a selector.  We simply throw
             // IllegalArgumentException here because we can simply
             // conclude that nothing is bound to the selector.
-            throw new IllegalArgumentException( "Address not bound: " + address );
+            throw new IllegalArgumentException( "Address not bound: " + getLocalAddress() );
         }
 
         synchronized( cancelQueue )
@@ -239,20 +303,6 @@
         }
     }
 
-    public void unbindAll()
-    {
-        List addresses;
-        synchronized( channels )
-        {
-            addresses = new ArrayList( channels.keySet() );
-        }
-
-        for( Iterator i = addresses.iterator(); i.hasNext(); )
-        {
-            unbind( ( SocketAddress ) i.next() );
-        }
-    }
-
     private class Worker implements Runnable
     {
         public void run()
@@ -342,13 +392,10 @@
                 boolean success = false;
                 try
                 {
-                    RegistrationRequest req = ( RegistrationRequest ) key.attachment();
                     SocketSessionImpl session = new SocketSessionImpl(
-                            SocketAcceptor.this, nextProcessor(), getListeners(),
-                            req.config, ch, req.handler, req.address );
+                            SocketAcceptor.this, getListeners(), nextProcessor(), ch );
                     getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
-                    req.config.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
-                    req.config.getThreadModel().buildFilterChain( session.getFilterChain() );
+                    getThreadModel().buildFilterChain( session.getFilterChain() );
                     session.getIoProcessor().addNew( session );
                     success = true;
                 }
@@ -372,26 +419,6 @@
         return ioProcessors[processorDistributor++ % processorCount];
     }
 
-    public IoServiceConfig getDefaultConfig()
-    {
-        return defaultConfig;
-    }
-
-    /**
-     * Sets the config this acceptor will use by default.
-     * 
-     * @param defaultConfig the default config.
-     * @throws NullPointerException if the specified value is <code>null</code>.
-     */
-    public void setDefaultConfig( SocketAcceptorConfig defaultConfig )
-    {
-        if( defaultConfig == null )
-        {
-            throw new NullPointerException( "defaultConfig" );
-        }
-        this.defaultConfig = defaultConfig;
-    }
-
     private void registerNew()
     {
         if( registerQueue.isEmpty() )
@@ -421,33 +448,20 @@
                 ssc.configureBlocking( false );
 
                 // Configure the server socket,
-                SocketAcceptorConfig cfg;
-                if( req.config instanceof SocketAcceptorConfig )
-                {
-                    cfg = ( SocketAcceptorConfig ) req.config;
-                }
-                else
-                {
-                    cfg = ( SocketAcceptorConfig ) getDefaultConfig();
-                }
-
-                ssc.socket().setReuseAddress( cfg.isReuseAddress() );
+                ssc.socket().setReuseAddress( isReuseAddress() );
                 ssc.socket().setReceiveBufferSize(
-                    ( ( SocketSessionConfig ) cfg.getSessionConfig() ).getReceiveBufferSize() );
+                    ( ( SocketSessionConfig ) getSessionConfig() ).getReceiveBufferSize() );
 
                 // and bind.
-                ssc.socket().bind( req.address, cfg.getBacklog() );
+                ssc.socket().bind( getLocalAddress(), getBacklog() );
                 ssc.register( selector, SelectionKey.OP_ACCEPT, req );
-
-                synchronized( channels )
-                {
-                    channels.put( req.address, ssc );
-                }
-
-                getListeners().fireServiceActivated(
-                        this, req.address, req.handler, req.config );
+                
+                serverSocketChannel = ssc;
+                
+                // and notify.
+                getListeners().fireServiceActivated();
             }
-            catch( IOException e )
+            catch( Throwable e )  // TODO better exception handling.
             {
                 req.exception = e;
             }
@@ -497,29 +511,16 @@
                 break;
             }
 
-            ServerSocketChannel ssc;
-            synchronized( channels )
-            {
-                ssc = ( ServerSocketChannel ) channels.remove( request.address );
-            }
-
             // close the channel
             try
             {
-                if( ssc == null )
-                {
-                    request.exception = new IllegalArgumentException( "Address not bound: " + request.address );
-                }
-                else
-                {
-                    SelectionKey key = ssc.keyFor( selector );
-                    request.registrationRequest = ( RegistrationRequest ) key.attachment();
-                    key.cancel();
+                SelectionKey key = serverSocketChannel.keyFor( selector );
+                key.cancel();
 
-                    selector.wakeup(); // wake up again to trigger thread death
+                selector.wakeup(); // wake up again to trigger thread death
 
-                    ssc.close();
-                }
+                serverSocketChannel.close();
+                serverSocketChannel = null;
             }
             catch( IOException e )
             {
@@ -535,10 +536,7 @@
 
                 if( request.exception == null )
                 {
-                    getListeners().fireServiceDeactivated(
-                            this, request.address,
-                            request.registrationRequest.handler,
-                            request.registrationRequest.config );
+                    getListeners().fireServiceDeactivated();
                 }
             }
         }
@@ -546,31 +544,19 @@
 
     private static class RegistrationRequest
     {
-        private final SocketAddress address;
-        private final IoHandler handler;
-        private final IoServiceConfig config;
-        private IOException exception;
+        private Throwable exception;
         private boolean done;
-
-        private RegistrationRequest( SocketAddress address, IoHandler handler, IoServiceConfig config )
-        {
-            this.address = address;
-            this.handler = handler;
-            this.config = config;
-        }
     }
 
 
     private static class CancellationRequest
     {
-        private final SocketAddress address;
         private boolean done;
-        private RegistrationRequest registrationRequest;
         private RuntimeException exception;
+    }
 
-        private CancellationRequest( SocketAddress address )
-        {
-            this.address = address;
-        }
+    public IoSession newSession( SocketAddress remoteAddress )
+    {
+        throw new UnsupportedOperationException();
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- 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 Wed Oct 18 23:42:06 2006
@@ -22,7 +22,6 @@
 import java.io.IOException;
 import java.net.ConnectException;
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
@@ -32,15 +31,14 @@
 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.IoSessionConfig;
 import org.apache.mina.common.support.AbstractIoFilterChain;
 import org.apache.mina.common.support.BaseIoConnector;
 import org.apache.mina.common.support.DefaultConnectFuture;
-import org.apache.mina.util.Queue;
-import org.apache.mina.util.NewThreadExecutor;
 import org.apache.mina.util.NamePreservingRunnable;
+import org.apache.mina.util.NewThreadExecutor;
+import org.apache.mina.util.Queue;
+
 import edu.emory.mathcs.backport.java.util.concurrent.Executor;
 
 /**
@@ -56,10 +54,11 @@
      */
     private static volatile int nextId = 0;
 
+    private IoSessionConfig sessionConfig = new SocketSessionConfigImpl();
+
     private final Object lock = new Object();
     private final int id = nextId++;
     private final String threadName = "SocketConnector-" + id;
-    private SocketConnectorConfig defaultConfig = new SocketConnectorConfig();
     private final Queue connectQueue = new Queue();
     private final SocketIoProcessor[] ioProcessors;
     private final int processorCount;
@@ -104,6 +103,16 @@
         }
     }
 
+    protected Class getAddressType()
+    {
+        return InetSocketAddress.class;
+    }
+
+    public IoSessionConfig getSessionConfig()
+    {
+        return sessionConfig;
+    }
+
     /**
      * How many seconds to keep the connection thread alive between connection requests
      *
@@ -128,49 +137,25 @@
         this.workerTimeout = workerTimeout;
     }
 
-    public ConnectFuture connect( SocketAddress address, IoHandler handler, IoServiceConfig config )
+    protected ConnectFuture doConnect()
     {
-        return connect( address, null, handler, config );
-    }
-
-    public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
-                                  IoHandler handler, IoServiceConfig config )
-    {
-        if( address == null )
-            throw new NullPointerException( "address" );
-        if( handler == null )
-            throw new NullPointerException( "handler" );
-
-        if( ! ( address instanceof InetSocketAddress ) )
-            throw new IllegalArgumentException( "Unexpected address type: "
-                                                + address.getClass() );
-
-        if( localAddress != null && !( localAddress instanceof InetSocketAddress ) )
-            throw new IllegalArgumentException( "Unexpected local address type: "
-                                                + localAddress.getClass() );
-
-        if( config == null )
-        {
-            config = getDefaultConfig();
-        }
-
         SocketChannel ch = null;
         boolean success = false;
         try
         {
             ch = SocketChannel.open();
             ch.socket().setReuseAddress( true );
-            if( localAddress != null )
+            if( getLocalAddress() != null )
             {
-                ch.socket().bind( localAddress );
+                ch.socket().bind( getLocalAddress() );
             }
 
             ch.configureBlocking( false );
 
-            if( ch.connect( address ) )
+            if( ch.connect( getRemoteAddress() ) )
             {
                 DefaultConnectFuture future = new DefaultConnectFuture();
-                newSession( ch, handler, config, future );
+                newSession( ch, future );
                 success = true;
                 return future;
             }
@@ -196,7 +181,7 @@
             }
         }
 
-        ConnectionRequest request = new ConnectionRequest( ch, handler, config );
+        ConnectionRequest request = new ConnectionRequest( ch );
         synchronized( lock )
         {
             try
@@ -226,26 +211,6 @@
 
         return request;
     }
-
-    public IoServiceConfig getDefaultConfig()
-    {
-        return defaultConfig;
-    }
-
-    /**
-     * Sets the config this connector will use by default.
-     * 
-     * @param defaultConfig the default config.
-     * @throws NullPointerException if the specified value is <code>null</code>.
-     */
-    public void setDefaultConfig( SocketConnectorConfig defaultConfig )
-    {
-        if( defaultConfig == null )
-        {
-            throw new NullPointerException( "defaultConfig" );
-        }
-        this.defaultConfig = defaultConfig;
-    }
     
     private synchronized void startupWorker() throws IOException
     {
@@ -303,7 +268,7 @@
             try
             {
                 ch.finishConnect();
-                newSession( ch, entry.handler, entry.config, entry );
+                newSession( ch, entry );
                 success = true;
             }
             catch( Throwable e )
@@ -363,17 +328,16 @@
         }
     }
 
-    private void newSession( SocketChannel ch, IoHandler handler, IoServiceConfig config, ConnectFuture connectFuture )
+    private void newSession( SocketChannel ch, ConnectFuture connectFuture )
         throws IOException
     {
-        SocketSessionImpl session = new SocketSessionImpl(
-                this, nextProcessor(), getListeners(),
-                config, ch, handler, ch.socket().getRemoteSocketAddress() );
+        SocketSessionImpl session =
+            new SocketSessionImpl( this, getListeners(), nextProcessor(), ch );
+
         try
         {
             getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
-            config.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
-            config.getThreadModel().buildFilterChain( session.getFilterChain() );
+            getThreadModel().buildFilterChain( session.getFilterChain() );
         }
         catch( Throwable e )
         {
@@ -469,24 +433,11 @@
     {
         private final SocketChannel channel;
         private final long deadline;
-        private final IoHandler handler;
-        private final IoServiceConfig config;
 
-        private ConnectionRequest( SocketChannel channel, IoHandler handler, IoServiceConfig config )
+        private ConnectionRequest( SocketChannel channel )
         {
             this.channel = channel;
-            long timeout;
-            if( config instanceof IoConnectorConfig )
-            {
-                timeout = ( ( IoConnectorConfig ) config ).getConnectTimeoutMillis();
-            }
-            else
-            {
-                timeout = ( ( IoConnectorConfig ) getDefaultConfig() ).getConnectTimeoutMillis();
-            }
-            this.deadline = System.currentTimeMillis() + timeout;
-            this.handler = handler;
-            this.config = config;
+            this.deadline = System.currentTimeMillis() + getConnectTimeoutMillis();
         }
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java?view=diff&rev=465510&r1=465509&r2=465510
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java Wed Oct 18 23:42:06 2006
@@ -19,21 +19,20 @@
  */
 package org.apache.mina.transport.socket.nio;
 
-import org.apache.mina.common.ExceptionMonitor;
-import org.apache.mina.common.IoConnectorConfig;
-import org.apache.mina.common.support.BaseIoSessionConfig;
-
 import java.io.IOException;
 import java.net.Socket;
 import java.net.SocketException;
 
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.support.BaseIoSessionConfig;
+
 /**
- * An {@link IoConnectorConfig} for {@link SocketConnector}.
+ * The default implementation of {@link SocketSessionConfig}.
  *
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class SocketSessionConfigImpl extends BaseIoSessionConfig implements SocketSessionConfig
+class SocketSessionConfigImpl extends BaseIoSessionConfig implements SocketSessionConfig
 {
     private static boolean SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false;
     private static boolean SET_SEND_BUFFER_SIZE_AVAILABLE = false;
@@ -152,7 +151,7 @@
     /**
      * Creates a new instance.
      */
-    public SocketSessionConfigImpl()
+    SocketSessionConfigImpl()
     {
     }
 



Mime
View raw message