directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r440315 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/common/ main/java/org/apache/mina/common/support/ main/java/org/apache/mina/transport/socket/nio/ main/java/org/apache/mina/transport/socket/nio/support/ main/java/org/...
Date Tue, 05 Sep 2006 10:14:54 GMT
Author: trustin
Date: Tue Sep  5 03:14:53 2006
New Revision: 440315

URL: http://svn.apache.org/viewvc?view=rev&rev=440315
Log:
* Added IoSession.getServiceConfig()
* Added many methods to IoService
** add/removeListener( IoSericeListener )
** getManagedServiceAddresses() - this replaces IoAcceptor.getBoundAddresses()
** isManaged( SocketAddress ) - this replaces IoAcceptor.isBound()
** getManagedSessions( SocketAddress ) is retained as before
* Added IoServiceListener which listens to any changes in IoService and IoSession life cycle
* Added IoServiceListenerSupport which helps the implementation of IoServiceListener event notification for all transports
* Added IoServiceListenerSupportTest

Added:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java   (with props)
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java   (with props)
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/IoServiceListenerSupportTest.java   (with props)
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/IoService.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/BaseIoService.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/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/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/SocketIoProcessor.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/DatagramSessionImpl.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/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/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/thread/ThreadPoolFilterRegressionTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -21,7 +21,6 @@
 
 import java.io.IOException;
 import java.net.SocketAddress;
-import java.util.Set;
 
 /**
  * Accepts incoming connection, communicates with clients, and fires events to
@@ -71,21 +70,6 @@
      * Unbinds all addresses which were bound by this acceptor.
      */
     void unbindAll();
-    
-    /**
-     * Returns <tt>true</tt> if and only if the specified <tt>address</tt> is
-     * bound by this acceptor.
-     */
-    boolean isBound( SocketAddress address );
-    
-    /**
-     * Returns a set of {@link SocketAddress} objects representing the addresses 
-     * which have been bound by this acceptor.
-     * 
-     * @return the set of {@link SocketAddress} objects or an empty set if 
-     *         nothing has been bound.
-     */
-    Set getBoundAddresses();
     
     /**
      * (Optional) Returns an {@link IoSession} that is bound to the specified

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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -33,19 +33,46 @@
 public interface IoService
 {
     /**
+     * Adds an {@link IoServiceListener} that listens any events related with
+     * this service.
+     */
+    void addListener( IoServiceListener listener );
+    
+    /**
+     * Removed an existing {@link IoServiceListener} that listens any events
+     * related with this service.
+     */
+    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.
+     */
+    Set getManagedServiceAddresses();
+    
+    /**
+     * 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.
+     */
+    boolean isManaged( SocketAddress serviceAddress );
+    
+    /**
      * Returns all sessions with the specified remote or local address,
      * 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 address the address to return all sessions for.
+     * @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 address );
+    Set getManagedSessions( SocketAddress serviceAddress );
 
     /**
      * Returns the default configuration which is used when you didn't specify

Added: 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=auto&rev=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java Tue Sep  5 03:14:53 2006
@@ -0,0 +1,73 @@
+/*
+ *  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.common;
+
+import java.net.SocketAddress;
+import java.util.EventListener;
+
+/**
+ * Something interested in being notified when the result
+ * of an {@link IoFuture} becomes available.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface IoServiceListener extends EventListener
+{
+    /**
+     * 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 );
+    
+    /**
+     * 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 );
+    
+    /**
+     * Invoked when a new session is created by an {@link IoService}.
+     * 
+     * @param session the new session
+     */
+    void sessionCreated( IoSession session );
+    
+    /**
+     * Invoked when a session is being destroyed by an {@link IoService}.
+     * 
+     * @param session the session to be destroyed
+     */
+    void sessionDestroyed( IoSession session );
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoServiceListener.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -54,6 +54,11 @@
      * Returns the {@link IoService} which provides I/O service to this session.
      */
     IoService getService();
+    
+    /**
+     * Returns the {@link IoServiceConfig} of this session.
+     */
+    IoServiceConfig getServiceConfig();
 
     /**
      * Returns the {@link IoHandler} which handles this session.

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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -25,6 +25,7 @@
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoFilterChainBuilder;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceListener;
 
 /**
  * Base implementation of {@link IoService}s.
@@ -39,13 +40,13 @@
      */
     private IoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
 
-    protected BaseIoService()
-    {
-    }
+    /**
+     * Maintains the {@link IoServiceListener}s of this service.
+     */
+    private final IoServiceListenerSupport listeners = new IoServiceListenerSupport();
     
-    public Set getManagedSessions( SocketAddress address )
+    protected BaseIoService()
     {
-        throw new UnsupportedOperationException();
     }
     
     public IoFilterChainBuilder getFilterChainBuilder()
@@ -73,5 +74,35 @@
             throw new IllegalStateException(
                     "Current filter chain builder is not a DefaultIoFilterChainBuilder." );
         }
+    }
+    
+    public void addListener( IoServiceListener listener )
+    {
+        getListeners().add( listener );
+    }
+    
+    public void removeListener( IoServiceListener listener )
+    {
+        getListeners().remove( listener );
+    }
+    
+    public Set getManagedServiceAddresses()
+    {
+        return getListeners().getManagedServiceAddresses();
+    }
+
+    public Set getManagedSessions( SocketAddress serviceAddress )
+    {
+        return getListeners().getManagedSessions( serviceAddress );
+    }
+
+    public boolean isManaged( SocketAddress serviceAddress )
+    {
+        return getListeners().isManaged( serviceAddress );
+    }
+
+    protected IoServiceListenerSupport getListeners()
+    {
+        return listeners;
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java Tue Sep  5 03:14:53 2006
@@ -40,7 +40,11 @@
      */
     private IoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
     
+    /**
+     * The default thread model.
+     */
     private final ThreadModel defaultThreadModel = PooledThreadModel.getInstance("AnonymousIoService");
+    
     /**
      * Current thread model.
      */

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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -28,6 +28,7 @@
 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;
 
 /**
@@ -76,19 +77,19 @@
         delegate.unbindAll();
     }
     
-    public boolean isBound( SocketAddress address )
+    public boolean isManaged( SocketAddress address )
     {
-        return delegate.isBound( address );
+        return delegate.isManaged( address );
     }
 
-    public Set getBoundAddresses()
+    public Set getManagedServiceAddresses()
     {
-        return delegate.getBoundAddresses();
+        return delegate.getManagedServiceAddresses();
     }
 
-    public Set getManagedSessions( SocketAddress address )
+    public Set getManagedSessions( SocketAddress serviceAddress )
     {
-        return delegate.getManagedSessions( address );
+        return delegate.getManagedSessions( serviceAddress );
     }
 
     public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
@@ -114,5 +115,15 @@
     public DefaultIoFilterChainBuilder getFilterChain()
     {
         return delegate.getFilterChain();
+    }
+
+    public void addListener( IoServiceListener listener )
+    {
+        delegate.addListener( listener );
+    }
+
+    public void removeListener( IoServiceListener listener )
+    {
+        delegate.removeListener( listener );
     }
 }

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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -28,6 +28,7 @@
 import org.apache.mina.common.IoFilterChainBuilder;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.IoServiceListener;
 
 /**
  * A delegated {@link IoConnector} that wraps the other {@link IoConnector}.
@@ -77,9 +78,19 @@
         return delegate.connect( address, localAddress, handler, config );
     }
 
-    public Set getManagedSessions( SocketAddress address )
+    public boolean isManaged( SocketAddress serviceAddress )
     {
-        return delegate.getManagedSessions( address );
+        return delegate.isManaged( serviceAddress );
+    }
+    
+    public Set getManagedServiceAddresses()
+    {
+        return delegate.getManagedServiceAddresses();
+    }
+
+    public Set getManagedSessions( SocketAddress serviceAddress )
+    {
+        return delegate.getManagedSessions( serviceAddress );
     }
     
     public IoServiceConfig getDefaultConfig()
@@ -100,5 +111,15 @@
     public DefaultIoFilterChainBuilder getFilterChain()
     {
         return delegate.getFilterChain();
+    }
+
+    public void addListener( IoServiceListener listener )
+    {
+        delegate.addListener( listener );
+    }
+
+    public void removeListener( IoServiceListener listener )
+    {
+        delegate.removeListener( listener );
     }
 }

Added: 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=auto&rev=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java Tue Sep  5 03:14:53 2006
@@ -0,0 +1,339 @@
+/*
+ *  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.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.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;
+
+/**
+ * A helper which provides addition and removal of {@link IoServiceListener}s and firing
+ * events.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoServiceListenerSupport
+{
+    /**
+     * A list of {@link IoServiceListener}s.
+     */
+    private final List listeners = new ArrayList();
+
+    /**
+     * Tracks managed <tt>serviceAddress</tt>es.
+     */
+    private final Set managedServiceAddresses = new HashSet();
+    
+    /**
+     * Tracks managed sesssions with <tt>serviceAddress</tt> as a key.
+     */
+    private final Map managedSessions = new HashMap();
+    
+    /**
+     * Creates a new instance.
+     */
+    public IoServiceListenerSupport()
+    {
+    }
+    
+    /**
+     * Adds a new listener.
+     */
+    public void add( IoServiceListener listener )
+    {
+        synchronized( listeners )
+        {
+            listeners.add( listener );
+        }
+    }
+
+    /**
+     * Removes an existing listener.
+     */
+    public void remove( IoServiceListener listener )
+    {
+        synchronized( listeners )
+        {
+            listeners.remove( listener );
+        }
+    }
+    
+    public Set getManagedServiceAddresses()
+    {
+        return Collections.unmodifiableSet( managedServiceAddresses );
+    }
+
+    public boolean isManaged( SocketAddress serviceAddress )
+    {
+        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();
+            }
+        }
+        
+        return Collections.unmodifiableSet( sessions );
+    }
+
+    /**
+     * Calls {@link IoServiceListener#serviceActivated(IoService, SocketAddress, IoHandler, IoServiceConfig)}
+     * for all registered listeners.
+     */
+    public void fireServiceActivated(
+            IoService service, SocketAddress serviceAddress,
+            IoHandler handler, IoServiceConfig config )
+    {
+        synchronized( managedServiceAddresses )
+        {
+            if( !managedServiceAddresses.add( serviceAddress ) )
+            {
+                return;
+            }
+        }
+
+        synchronized( listeners )
+        {
+            for( Iterator i = listeners.iterator(); i.hasNext(); )
+            {
+                ( ( IoServiceListener ) i.next() ).serviceActivated(
+                        service, serviceAddress, handler, config );
+            }
+        }
+    }
+    
+    /**
+     * Calls {@link IoServiceListener#serviceDeactivated(IoService, SocketAddress, IoHandler, IoServiceConfig)}
+     * for all registered listeners.
+     */
+    public synchronized void fireServiceDeactivated(
+            IoService service, SocketAddress serviceAddress,
+            IoHandler handler, IoServiceConfig config )
+    {
+        synchronized( managedServiceAddresses )
+        {
+            if( !managedServiceAddresses.remove( serviceAddress ) )
+            {
+                return;
+            }
+        }
+        
+        try
+        {
+            synchronized( listeners )
+            {
+                for( Iterator i = listeners.iterator(); i.hasNext(); )
+                {
+                    ( ( IoServiceListener ) i.next() ).serviceDeactivated(
+                            service, serviceAddress, handler, config );
+                }
+            }
+        }
+        finally
+        {
+            disconnectSessions( serviceAddress, config );
+        }
+    }
+    
+    
+    /**
+     * Calls {@link IoServiceListener#sessionCreated(IoSession)} for all registered listeners.
+     */
+    public void fireSessionCreated( IoSession session )
+    {
+        SocketAddress serviceAddress = session.getServiceAddress();
+        
+        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( session.getService() instanceof IoConnector && firstSession )
+        {
+            fireServiceActivated(
+                    session.getService(), session.getServiceAddress(),
+                    session.getHandler(), session.getServiceConfig() );
+        }
+
+        synchronized( sessions )
+        {
+            if ( !sessions.add( session ) )
+            {
+                return;
+            }
+        }
+
+        synchronized( listeners )
+        {
+            for( Iterator i = listeners.iterator(); i.hasNext(); )
+            {
+                ( ( IoServiceListener ) i.next() ).sessionCreated( session );
+            }
+        }
+    }
+    
+    /**
+     * Calls {@link IoServiceListener#sessionDestroyed(IoSession)} for all registered listeners.
+     */
+    public void fireSessionDestroyed( IoSession session )
+    {
+        SocketAddress serviceAddress = session.getServiceAddress();
+        
+        Set sessions;
+        synchronized( managedSessions )
+        {
+            sessions = ( Set ) managedSessions.get( serviceAddress );
+        }
+        
+        if( sessions == null )
+        {
+            return;
+        }
+        
+        boolean lastSession = false;
+        synchronized( sessions )
+        {
+            sessions.remove( session );
+            if( sessions.isEmpty() )
+            {
+                synchronized( managedSessions )
+                {
+                    managedSessions.remove( serviceAddress );
+                }
+                lastSession = true;
+            }
+        }
+        
+
+        try
+        {
+            synchronized( listeners )
+            {
+                for( Iterator i = listeners.iterator(); i.hasNext(); )
+                {
+                    ( ( IoServiceListener ) i.next() ).sessionDestroyed( session );
+                }
+            }
+        }
+        finally
+        {
+            if( session.getService() instanceof IoConnector && lastSession )
+            {
+                fireServiceDeactivated(
+                        session.getService(), session.getServiceAddress(),
+                        session.getHandler(), session.getServiceConfig() );
+            }
+        }
+    }
+
+    private void disconnectSessions( SocketAddress serviceAddress, IoServiceConfig config )
+    {
+        if( !( config instanceof IoAcceptorConfig ) )
+        {
+            return;
+        }
+
+        if( !( ( IoAcceptorConfig ) config ).isDisconnectOnUnbind() )
+        {
+            return;
+        }
+
+        Set sessions;
+        synchronized( managedSessions )
+        {
+            sessions = ( Set ) managedSessions.get( serviceAddress );
+        }
+        
+        if( sessions == null )
+        {
+            return;
+        }
+
+        final Object lock = new Object();
+        synchronized( sessions )
+        {
+            for( Iterator i = sessions.iterator(); i.hasNext(); )
+            {
+                ( ( IoSession ) i.next() ).close().addListener( new IoFutureListener()
+                {
+                    public void operationComplete( IoFuture future )
+                    {
+                        synchronized( lock )
+                        {
+                            //noinspection NakedNotify
+                            lock.notifyAll();
+                        }
+                    }
+                } );
+            }
+        }
+
+        try
+        {
+            synchronized( lock )
+            {
+                while( !managedSessions.isEmpty() )
+                {
+                    lock.wait( 1000 );
+                }
+            }
+        }
+        catch( InterruptedException ie )
+        {
+            // Ignored
+        }
+    }
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -27,11 +27,7 @@
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -39,14 +35,9 @@
 
 import org.apache.mina.common.ExceptionMonitor;
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoAcceptorConfig;
-import org.apache.mina.common.IoFuture;
-import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoServiceConfig;
-import org.apache.mina.common.IoSession;
 import org.apache.mina.common.support.BaseIoAcceptor;
-import org.apache.mina.util.IdentityHashSet;
 import org.apache.mina.util.Queue;
 
 /**
@@ -67,7 +58,6 @@
     private final String threadName = "SocketAcceptor-" + id;
     private final IoServiceConfig defaultConfig = new SocketAcceptorConfig();
     private final Map channels = new HashMap();
-    private final Hashtable sessions = new Hashtable();
 
     private final Queue registerQueue = new Queue();
     private final Queue cancelQueue = new Queue();
@@ -191,24 +181,6 @@
         }
     }
 
-    public Set getManagedSessions( SocketAddress address )
-    {
-        if( address == null )
-        {
-            throw new NullPointerException( "address" );
-        }
-
-        Set managedSessions = ( Set ) sessions.get( address );
-
-        if( managedSessions == null )
-        {
-            throw new IllegalArgumentException( "Address not bound: " + address );
-        }
-
-        return Collections.unmodifiableSet(
-            new IdentityHashSet( Arrays.asList( managedSessions.toArray() ) ) );
-    }
-
     public void unbind( SocketAddress address )
     {
         if( address == null )
@@ -216,7 +188,6 @@
             throw new NullPointerException( "address" );
         }
 
-        final Set managedSessions = ( Set ) sessions.get( address );
         CancellationRequest request = new CancellationRequest( address );
 
         try
@@ -260,63 +231,6 @@
 
             throw request.exception;
         }
-
-        // Disconnect all clients
-        IoServiceConfig cfg = request.registrationRequest.config;
-        boolean disconnectOnUnbind;
-        if( cfg instanceof IoAcceptorConfig )
-        {
-            disconnectOnUnbind = ( ( IoAcceptorConfig ) cfg ).isDisconnectOnUnbind();
-        }
-        else
-        {
-            disconnectOnUnbind = ( ( IoAcceptorConfig ) getDefaultConfig() ).isDisconnectOnUnbind();
-        }
-
-        if( disconnectOnUnbind && managedSessions != null )
-        {
-            IoSession[] tempSessions =
-                ( IoSession[] ) managedSessions.toArray( new IoSession[ managedSessions.size() ] );
-
-            final Object lock = new Object();
-
-            for( int i = 0; i < tempSessions.length; i++ )
-            {
-                if( !managedSessions.contains( tempSessions[i] ) )
-                {
-                    // The session has already been closed and have been 
-                    // removed from managedSessions by the SocketIoProcessor.
-                    continue;
-                }
-                tempSessions[i].close().addListener( new IoFutureListener()
-                {
-                    public void operationComplete( IoFuture future )
-                    {
-                        synchronized( lock )
-                        {
-                            //noinspection NakedNotify
-                            lock.notifyAll();
-                        }
-                    }
-                } );
-            }
-
-            try
-            {
-                synchronized( lock )
-                {
-                    while( !managedSessions.isEmpty() )
-                    {
-                        lock.wait( 1000 );
-                    }
-                }
-            }
-            catch( InterruptedException ie )
-            {
-                // Ignored
-            }
-
-        }
     }
 
     public void unbindAll()
@@ -333,22 +247,6 @@
         }
     }
 
-    public boolean isBound( SocketAddress address )
-    {
-        synchronized( channels )
-        {
-            return channels.containsKey( address );
-        }
-    }
-
-    public Set getBoundAddresses()
-    {
-        synchronized( channels )
-        {
-            return new HashSet( channels.keySet() );
-        }
-    }
-    
     private class Worker extends Thread
     {
         Worker()
@@ -444,8 +342,8 @@
                     RegistrationRequest req = ( RegistrationRequest ) key.attachment();
                     session = new SocketSessionImpl( SocketAcceptor.this,
                                                      nextProcessor(),
-                                                     ( Set ) sessions.get( req.address ),
-                                                     req.config.getSessionConfig(),
+                                                     getListeners(),
+                                                     req.config,
                                                      ch,
                                                      req.handler,
                                                      req.address );
@@ -453,7 +351,6 @@
                     req.config.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
                     req.config.getThreadModel().buildFilterChain( session.getFilterChain() );
                     ( ( SocketFilterChain ) session.getFilterChain() ).sessionCreated( session );
-                    session.getManagedSessions().add( session );
                     session.getIoProcessor().addNew( session );
                     success = true;
                 }
@@ -465,10 +362,6 @@
                 {
                     if( !success )
                     {
-                        if( session != null )
-                        {
-                            session.getManagedSessions().remove( session );
-                        }
                         ch.close();
                     }
                 }
@@ -537,7 +430,9 @@
                 {
                     channels.put( req.address, ssc );
                 }
-                sessions.put( req.address, Collections.synchronizedSet( new HashSet() ) );
+                
+                getListeners().fireServiceActivated(
+                        this, req.address, req.handler, req.config );
             }
             catch( IOException e )
             {
@@ -589,7 +484,6 @@
                 break;
             }
 
-            sessions.remove( request.address );
             ServerSocketChannel ssc;
             synchronized( channels )
             {
@@ -624,6 +518,14 @@
                 {
                     request.done = true;
                     request.notifyAll();
+                }
+                
+                if( request.exception == null )
+                {
+                    getListeners().fireServiceDeactivated(
+                            this, request.address,
+                            request.registrationRequest.handler,
+                            request.registrationRequest.config );
                 }
             }
         }

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=440315&r1=440314&r2=440315
==============================================================================
--- 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 Tue Sep  5 03:14:53 2006
@@ -26,8 +26,6 @@
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
@@ -59,7 +57,6 @@
     private final String threadName = "SocketConnector-" + id;
     private final IoServiceConfig defaultConfig = new SocketConnectorConfig();
     private final Queue connectQueue = new Queue();
-    private final Set managedSessions = Collections.synchronizedSet( new HashSet() );
     private final SocketIoProcessor[] ioProcessors;
     private final int processorCount;
 
@@ -351,8 +348,8 @@
     {
         SocketSessionImpl session = new SocketSessionImpl( this,
                                                            nextProcessor(),
-                                                           managedSessions,
-                                                           config.getSessionConfig(),
+                                                           getListeners(),
+                                                           config,
                                                            ch,
                                                            handler,
                                                            ch.socket().getRemoteSocketAddress() );
@@ -367,7 +364,6 @@
         {
             throw ( IOException ) new IOException( "Failed to create a session." ).initCause( e );
         }
-        session.getManagedSessions().add( session );
         session.getIoProcessor().addNew( session );
         return session;
     }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java Tue Sep  5 03:14:53 2006
@@ -168,13 +168,13 @@
             }
             catch( IOException e )
             {
-                session.getManagedSessions().remove( session );
                 registered = false;
                 ( ( SocketFilterChain ) session.getFilterChain() ).exceptionCaught( session, e );
             }
 
             if( registered )
             {
+                session.getServiceListeners().fireSessionCreated( session );
                 ( ( SocketFilterChain ) session.getFilterChain() ).sessionOpened( session );
             }
         }
@@ -224,7 +224,7 @@
             finally
             {
                 releaseWriteBuffers( session );
-                session.getManagedSessions().remove( session );
+                session.getServiceListeners().fireSessionDestroyed( session );
 
                 ( ( SocketFilterChain ) session.getFilterChain() ).sessionClosed( session );
             }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java Tue Sep  5 03:14:53 2006
@@ -19,24 +19,25 @@
  */
 package org.apache.mina.transport.socket.nio;
 
-import org.apache.mina.common.IoFilter.WriteRequest;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.SocketChannel;
+
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
+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.TransportType;
+import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
 import org.apache.mina.common.support.BaseIoSessionConfig;
+import org.apache.mina.common.support.IoServiceListenerSupport;
 import org.apache.mina.util.Queue;
 
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
-import java.util.Set;
-
 /**
  * An {@link IoSession} for socket transport (TCP/IP).
  *
@@ -46,6 +47,7 @@
 class SocketSessionImpl extends BaseIoSession
 {
     private final IoService manager;
+    private final IoServiceConfig serviceConfig;
     private final SocketSessionConfig config = new SessionConfigImpl();
     private final SocketIoProcessor ioProcessor;
     private final SocketFilterChain filterChain;
@@ -55,7 +57,7 @@
     private final SocketAddress remoteAddress;
     private final SocketAddress localAddress;
     private final SocketAddress serviceAddress;
-    private final Set managedSessions;
+    private final IoServiceListenerSupport serviceListeners;
     private SelectionKey key;
     private int readBufferSize;
 
@@ -64,14 +66,14 @@
      */
     SocketSessionImpl( IoService manager,
                        SocketIoProcessor ioProcessor,
-                       Set managedSessions,
-                       IoSessionConfig config,
+                       IoServiceListenerSupport listeners,
+                       IoServiceConfig serviceConfig,
                        SocketChannel ch,
                        IoHandler defaultHandler,
                        SocketAddress serviceAddress )
     {
         this.manager = manager;
-        this.managedSessions = managedSessions;
+        this.serviceListeners = listeners;
         this.ioProcessor = ioProcessor;
         this.filterChain = new SocketFilterChain( this );
         this.ch = ch;
@@ -80,11 +82,13 @@
         this.remoteAddress = ch.socket().getRemoteSocketAddress();
         this.localAddress = ch.socket().getLocalSocketAddress();
         this.serviceAddress = serviceAddress;
+        this.serviceConfig = serviceConfig;
 
         // Apply the initial session settings
-        if( config instanceof SocketSessionConfig )
+        IoSessionConfig sessionConfig = serviceConfig.getSessionConfig();
+        if( sessionConfig instanceof SocketSessionConfig )
         {
-            SocketSessionConfig cfg = ( SocketSessionConfig ) config;
+            SocketSessionConfig cfg = ( SocketSessionConfig ) sessionConfig;
             this.config.setKeepAlive( cfg.isKeepAlive() );
             this.config.setOobInline( cfg.isOobInline() );
             this.config.setReceiveBufferSize( cfg.getReceiveBufferSize() );
@@ -105,6 +109,11 @@
     {
         return manager;
     }
+    
+    public IoServiceConfig getServiceConfig()
+    {
+        return serviceConfig;
+    }
 
     public IoSessionConfig getConfig()
     {
@@ -126,9 +135,9 @@
         return ch;
     }
 
-    Set getManagedSessions()
+    IoServiceListenerSupport getServiceListeners()
     {
-        return managedSessions;
+        return serviceListeners;
     }
 
     SelectionKey getSelectionKey()

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java Tue Sep  5 03:14:53 2006
@@ -228,7 +228,7 @@
         RegistrationRequest req = ( RegistrationRequest ) key.attachment();
         DatagramSessionImpl s = new DatagramSessionImpl(
                 wrapper, this,
-                req.config.getSessionConfig(), ch, req.handler,
+                req.config, ch, req.handler,
                 req.address );
         s.setRemoteAddress( remoteAddress );
         s.setSelectionKey( key );
@@ -370,7 +370,7 @@
             RegistrationRequest req = ( RegistrationRequest ) key.attachment();
             DatagramSessionImpl session = new DatagramSessionImpl(
                     wrapper, this,
-                    req.config.getSessionConfig(),
+                    req.config,
                     ch, req.handler,
                     req.address );
             session.setSelectionKey( key );
@@ -578,6 +578,9 @@
                 {
                     channels.put( req.address, ch );
                 }
+                
+                getListeners().fireServiceActivated(
+                        this, req.address, req.handler, req.config);
             }
             catch( Throwable t )
             {
@@ -642,6 +645,7 @@
                 else
                 {
                     SelectionKey key = ch.keyFor( selector );
+                    request.registrationRequest = ( RegistrationRequest ) key.attachment();
                     key.cancel();
                     selector.wakeup(); // wake up again to trigger thread death
                     ch.disconnect();
@@ -659,6 +663,14 @@
                     request.done = true;
                     request.notify();
                 }
+
+                if( request.exception == null )
+                {
+                    getListeners().fireServiceDeactivated(
+                            this, request.address,
+                            request.registrationRequest.handler,
+                            request.registrationRequest.config );
+                }
             }
         }
     }
@@ -691,6 +703,7 @@
     {
         private final SocketAddress address;
         private boolean done;
+        private RegistrationRequest registrationRequest;
         private RuntimeException exception;
         
         private CancellationRequest( SocketAddress address )

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java Tue Sep  5 03:14:53 2006
@@ -545,7 +545,7 @@
 
             DatagramSessionImpl session = new DatagramSessionImpl(
                     wrapper, this,
-                    req.config.getSessionConfig(),
+                    req.config,
                     req.channel, req.handler,
                     req.channel.socket().getRemoteSocketAddress() );
 

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java Tue Sep  5 03:14:53 2006
@@ -28,6 +28,7 @@
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.RuntimeIOException;
@@ -48,6 +49,7 @@
 class DatagramSessionImpl extends BaseIoSession implements BroadcastIoSession
 {
     private final IoService wrapperManager;
+    private final IoServiceConfig serviceConfig;
     private final DatagramSessionConfig config = new SessionConfigImpl();
     private final DatagramService managerDelegate;
     private final DatagramFilterChain filterChain;
@@ -65,7 +67,7 @@
      */
     DatagramSessionImpl( IoService wrapperManager,
                          DatagramService managerDelegate,
-                         IoSessionConfig config,
+                         IoServiceConfig serviceConfig,
                          DatagramChannel ch, IoHandler defaultHandler,
                          SocketAddress serviceAddress )
     {
@@ -78,11 +80,13 @@
         this.remoteAddress = ch.socket().getRemoteSocketAddress();
         this.localAddress = ch.socket().getLocalSocketAddress();
         this.serviceAddress = serviceAddress;
+        this.serviceConfig = serviceConfig;
         
         // Apply the initial session settings
-        if( config instanceof DatagramSessionConfig )
+        IoSessionConfig sessionConfig = serviceConfig.getSessionConfig();
+        if( sessionConfig instanceof DatagramSessionConfig )
         {
-            DatagramSessionConfig cfg = ( DatagramSessionConfig ) config;
+            DatagramSessionConfig cfg = ( DatagramSessionConfig ) sessionConfig;
             this.config.setBroadcast( cfg.isBroadcast() );
             this.config.setReceiveBufferSize( cfg.getReceiveBufferSize() );
             this.readBufferSize = cfg.getReceiveBufferSize();
@@ -99,6 +103,11 @@
     public IoService getService()
     {
         return wrapperManager;
+    }
+    
+    public IoServiceConfig getServiceConfig()
+    {
+        return serviceConfig;
     }
     
     public IoSessionConfig getConfig()

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java Tue Sep  5 03:14:53 2006
@@ -85,11 +85,10 @@
             VmPipeSessionImpl session =
                 new VmPipeSessionImpl(
                         this,
+                        config,
                         new Object(), // lock
                         new AnonymousSocketAddress(),
                         handler,
-                        config.getFilterChainBuilder(),
-                        config.getThreadModel(),
                         entry );
             future.setSession( session );
         }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java Tue Sep  5 03:14:53 2006
@@ -25,12 +25,11 @@
 
 import org.apache.mina.common.ExceptionMonitor;
 import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoFilterChainBuilder;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
-import org.apache.mina.common.ThreadModel;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
@@ -48,6 +47,7 @@
     private static final IoSessionConfig CONFIG = new BaseIoSessionConfig() {};
     
     private final IoService manager;
+    private final IoServiceConfig serviceConfig;
     private final SocketAddress localAddress;
     private final SocketAddress remoteAddress;
     private final SocketAddress serviceAddress;
@@ -61,11 +61,11 @@
     /**
      * Constructor for client-side session.
      */
-    public VmPipeSessionImpl( IoService manager, Object lock, SocketAddress localAddress,
-                   IoHandler handler, IoFilterChainBuilder filterChainBuilder, ThreadModel threadModel,
-                   VmPipe remoteEntry ) throws IOException
+    public VmPipeSessionImpl( IoService manager, IoServiceConfig serviceConfig, Object lock, SocketAddress localAddress,
+                   IoHandler handler, VmPipe remoteEntry ) throws IOException
     {
         this.manager = manager;
+        this.serviceConfig = serviceConfig;
         this.lock = lock;
         this.localAddress = localAddress;
         this.remoteAddress = this.serviceAddress = remoteEntry.getAddress();
@@ -97,8 +97,8 @@
         try
         {
             manager.getFilterChainBuilder().buildFilterChain( filterChain );
-            filterChainBuilder.buildFilterChain( filterChain );
-            threadModel.buildFilterChain( filterChain );
+            serviceConfig.getFilterChainBuilder().buildFilterChain( filterChain );
+            serviceConfig.getThreadModel().buildFilterChain( filterChain );
             handler.sessionCreated( this );
         }
         catch( Throwable t )
@@ -122,6 +122,7 @@
     private VmPipeSessionImpl( IoService manager, VmPipeSessionImpl remoteSession, VmPipe entry )
     {
         this.manager = manager;
+        this.serviceConfig = entry.getConfig();
         this.lock = remoteSession.lock;
         this.localAddress = this.serviceAddress = remoteSession.remoteAddress;
         this.remoteAddress = remoteSession.localAddress;
@@ -140,6 +141,11 @@
     public IoService getService()
     {
         return manager;
+    }
+    
+    public IoServiceConfig getServiceConfig()
+    {
+        return serviceConfig;
     }
     
     public IoSessionConfig getConfig()

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java Tue Sep  5 03:14:53 2006
@@ -313,6 +313,11 @@
         public int getScheduledWriteBytes() {
             return 0;
         }
+
+        public IoServiceConfig getServiceConfig()
+        {
+            return null;
+        }
     }
 
     private class EventOrderTestFilter extends IoFilterAdapter
@@ -443,6 +448,11 @@
                 public int getScheduledWriteBytes()
                 {
                     return 0;
+                }
+
+                public IoServiceConfig getServiceConfig()
+                {
+                    return null;
                 }
             } );
         }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/FutureTest.java Tue Sep  5 03:14:53 2006
@@ -28,6 +28,7 @@
 import org.apache.mina.common.IoFuture;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.TransportType;
@@ -127,6 +128,11 @@
             public int getScheduledWriteBytes()
             {
                 return 0;
+            }
+
+            public IoServiceConfig getServiceConfig()
+            {
+                return null;
             }
         };
         

Added: directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/IoServiceListenerSupportTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/IoServiceListenerSupportTest.java?view=auto&rev=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/IoServiceListenerSupportTest.java (added)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/IoServiceListenerSupportTest.java Tue Sep  5 03:14:53 2006
@@ -0,0 +1,296 @@
+/*
+ *  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.common.support;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoAcceptorConfig;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoFilterChain;
+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.common.IoSessionConfig;
+import org.apache.mina.common.TransportType;
+import org.easymock.MockControl;
+
+/**
+ * Tests {@link IoServiceListenerSupport}.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$ 
+ */
+public class IoServiceListenerSupportTest extends TestCase
+{
+    private static final SocketAddress ADDRESS = new InetSocketAddress( 8080 );
+
+    private IoServiceListenerSupport support;
+    
+    public void setUp() throws Exception
+    {
+        support = new IoServiceListenerSupport();
+    }
+    
+    public void testServiceLifecycle() throws Exception
+    {
+        MockControl listenerControl = MockControl.createControl( IoServiceListener.class );
+        IoServiceListener listener = ( IoServiceListener ) listenerControl.getMock();
+        
+        // Test activation
+        listener.serviceActivated( null, ADDRESS, null, null );
+        
+        listenerControl.replay();
+        
+        support.add( listener );
+        support.fireServiceActivated( null, ADDRESS, null, null );
+        
+        listenerControl.verify();
+        
+        Assert.assertEquals( 1, support.getManagedServiceAddresses().size() );
+        Assert.assertTrue( support.getManagedServiceAddresses().contains( ADDRESS ) );
+        
+        // Test deactivation & other side effects
+        listenerControl.reset();
+        listener.serviceDeactivated( null, ADDRESS, null, null );
+
+        listenerControl.replay();
+        //// Activate more than once
+        support.fireServiceActivated( null, ADDRESS, null, null );
+        //// Deactivate
+        support.fireServiceDeactivated( null, ADDRESS, null, null );
+        //// Deactivate more than once
+        support.fireServiceDeactivated( null, ADDRESS, null, null );
+        
+        listenerControl.verify();
+
+        Assert.assertEquals( 0, support.getManagedServiceAddresses().size() );
+        Assert.assertFalse( support.getManagedServiceAddresses().contains( ADDRESS ) );
+    }
+    
+    public void testSessionLifecycle() throws Exception
+    {
+        IoSession session = new TestSession( ADDRESS );
+        MockControl listenerControl = MockControl.createControl( IoServiceListener.class );
+        IoServiceListener listener = ( IoServiceListener ) listenerControl.getMock();
+        
+        // Test creation
+        listener.sessionCreated( session );
+        
+        listenerControl.replay();
+        
+        support.add( listener );
+        support.fireSessionCreated( session );
+        
+        listenerControl.verify();
+        
+        Assert.assertEquals( 1, support.getManagedSessions( ADDRESS ).size() );
+        Assert.assertTrue( support.getManagedSessions( ADDRESS ).contains( session ) );
+        
+        // Test destruction & other side effects
+        listenerControl.reset();
+        listener.sessionDestroyed( session );
+
+        listenerControl.replay();
+        //// Activate more than once
+        support.fireSessionCreated( session );
+        //// Deactivate
+        support.fireSessionDestroyed( session );
+        //// Deactivate more than once
+        support.fireSessionDestroyed( session );
+        
+        listenerControl.verify();
+
+        Assert.assertFalse( session.isClosing() );
+        Assert.assertEquals( 0, support.getManagedSessions( ADDRESS ).size() );
+        Assert.assertFalse( support.getManagedSessions( ADDRESS ).contains( session ) );
+    }
+    
+    public void testDisconnectOnUnbind() throws Exception
+    {
+        MockControl acceptorControl = MockControl.createControl( IoAcceptor.class );
+        IoAcceptor acceptor = ( IoAcceptor ) acceptorControl.getMock();
+        MockControl configControl = MockControl.createControl( IoAcceptorConfig.class );
+        IoAcceptorConfig config = ( IoAcceptorConfig ) configControl.getMock();
+        final IoSession session = new TestSession( acceptor, ADDRESS );
+        MockControl listenerControl = MockControl.createControl( IoServiceListener.class );
+        IoServiceListener listener = ( IoServiceListener ) listenerControl.getMock();
+        
+        // Activate a service and create a session.
+        listener.serviceActivated( acceptor, ADDRESS, null, config );
+        listener.sessionCreated( session );
+        
+        listenerControl.replay();
+        
+        support.add( listener );
+        support.fireServiceActivated( acceptor, ADDRESS, null, config );
+        support.fireSessionCreated( session );
+        
+        listenerControl.verify();
+        
+        // Deactivate a service and make sure the session is closed & destroyed.
+        listenerControl.reset();
+        listener.serviceDeactivated( acceptor, ADDRESS, null, config );
+        configControl.expectAndReturn(config.isDisconnectOnUnbind(), true );
+        listener.sessionDestroyed( session );
+
+        listenerControl.replay();
+        configControl.replay();
+        new Thread()
+        {
+            // Emulate I/O service
+            public void run()
+            {
+                try
+                {
+                    Thread.sleep( 2000 );
+                }
+                catch( InterruptedException e )
+                {
+                    e.printStackTrace();
+                }
+                support.fireSessionDestroyed( session );
+            }
+        }.start();
+        support.fireServiceDeactivated( acceptor, ADDRESS, null, config );
+        
+        listenerControl.verify();
+        configControl.verify();
+
+        Assert.assertTrue( session.isClosing() );
+        Assert.assertEquals( 0, support.getManagedSessions( ADDRESS ).size() );
+        Assert.assertFalse( support.getManagedSessions( ADDRESS ).contains( session ) );
+    }
+    
+    public void testConnectorActivation() throws Exception
+    {
+        MockControl connectorControl = MockControl.createControl( IoConnector.class );
+        IoConnector connector = ( IoConnector ) connectorControl.getMock();
+        final IoSession session = new TestSession( connector, ADDRESS );
+        MockControl listenerControl = MockControl.createControl( IoServiceListener.class );
+        IoServiceListener listener = ( IoServiceListener ) listenerControl.getMock();
+        
+        // Creating a session should activate a service automatically.
+        listener.serviceActivated( connector, ADDRESS, null, null );
+        listener.sessionCreated( session );
+        
+        listenerControl.replay();
+        
+        support.add( listener );
+        support.fireSessionCreated( session );
+        
+        listenerControl.verify();
+        
+        // Destroying a session should deactivate a service automatically.
+        listenerControl.reset();
+        listener.sessionDestroyed( session );
+        listener.serviceDeactivated( connector, ADDRESS, null, null );
+        
+        listenerControl.replay();
+        support.fireSessionDestroyed( session );
+        
+        listenerControl.verify();
+
+        Assert.assertEquals( 0, support.getManagedSessions( ADDRESS ).size() );
+        Assert.assertFalse( support.getManagedSessions( ADDRESS ).contains( session ) );
+    }
+    
+    private static class TestSession extends BaseIoSession
+    {
+        private final IoService service;
+        private final SocketAddress serviceAddress;
+        
+        public TestSession( SocketAddress serviceAddress )
+        {
+            this( null, serviceAddress );
+        }
+        
+        public TestSession( IoService service, SocketAddress serviceAddress )
+        {
+            this.service = service;
+            this.serviceAddress = serviceAddress;
+        }
+
+        protected void updateTrafficMask()
+        {
+        }
+
+        public IoSessionConfig getConfig()
+        {
+            return null;
+        }
+
+        public IoFilterChain getFilterChain()
+        {
+            return null;
+        }
+
+        public IoHandler getHandler()
+        {
+            return null;
+        }
+
+        public SocketAddress getLocalAddress()
+        {
+            return null;
+        }
+
+        public SocketAddress getRemoteAddress()
+        {
+            return null;
+        }
+
+        public int getScheduledWriteBytes()
+        {
+            return 0;
+        }
+
+        public int getScheduledWriteRequests()
+        {
+            return 0;
+        }
+
+        public IoService getService()
+        {
+            return service;
+        }
+
+        public SocketAddress getServiceAddress()
+        {
+            return serviceAddress;
+        }
+
+        public IoServiceConfig getServiceConfig()
+        {
+            return null;
+        }
+
+        public TransportType getTransportType()
+        {
+            return null;
+        }
+    }
+}

Propchange: directory/trunks/mina/core/src/test/java/org/apache/mina/common/support/IoServiceListenerSupportTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java Tue Sep  5 03:14:53 2006
@@ -30,6 +30,7 @@
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoService;
 import org.apache.mina.common.IoSessionConfig;
@@ -227,6 +228,11 @@
         }
 
         public IoService getService()
+        {
+            return null;
+        }
+
+        public IoServiceConfig getServiceConfig()
         {
             return null;
         }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineDecoderTest.java Tue Sep  5 03:14:53 2006
@@ -30,6 +30,7 @@
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.TransportType;
@@ -188,6 +189,11 @@
         }
 
         public IoService getService()
+        {
+            return null;
+        }
+        
+        public IoServiceConfig getServiceConfig()
         {
             return null;
         }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/codec/textline/TextLineEncoderTest.java Tue Sep  5 03:14:53 2006
@@ -28,6 +28,7 @@
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoService;
 import org.apache.mina.common.IoSessionConfig;
@@ -81,6 +82,11 @@
         }
 
         public IoService getService()
+        {
+            return null;
+        }
+
+        public IoServiceConfig getServiceConfig()
         {
             return null;
         }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/thread/ThreadPoolFilterRegressionTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/thread/ThreadPoolFilterRegressionTest.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/thread/ThreadPoolFilterRegressionTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/thread/ThreadPoolFilterRegressionTest.java Tue Sep  5 03:14:53 2006
@@ -29,6 +29,7 @@
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.TransportType;
@@ -217,6 +218,11 @@
             return null;
         }
 
+        public IoServiceConfig getServiceConfig()
+        {
+            return null;
+        }
+
         public IoSessionConfig getConfig()
         {
             return null;
@@ -332,6 +338,11 @@
         }
 
         public IoService getService()
+        {
+            return null;
+        }
+
+        public IoServiceConfig getServiceConfig()
         {
             return null;
         }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java?view=diff&rev=440315&r1=440314&r2=440315
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java Tue Sep  5 03:14:53 2006
@@ -26,6 +26,7 @@
 
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoService;
 import org.apache.mina.common.IoSessionConfig;
@@ -61,6 +62,11 @@
                     }
 
                     public IoService getService()
+                    {
+                        return null;
+                    }
+
+                    public IoServiceConfig getServiceConfig()
                     {
                         return null;
                     }



Mime
View raw message