directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r379346 - in /directory/trunks/mina/core/src/main/java/org/apache/mina: common/ common/support/ transport/socket/nio/support/ transport/vmpipe/
Date Tue, 21 Feb 2006 05:10:32 GMT
Author: trustin
Date: Mon Feb 20 21:10:30 2006
New Revision: 379346

URL: http://svn.apache.org/viewcvs?rev=379346&view=rev
Log:
Resolve issue: DIRMINA-174 (IoAcceptor.isBound(SocketAddress) and IoAcceptor.unbindAll())
* Added IoAcceptor.isBound( SocketAddress )
* Added IoAcceptor.unbindAll()

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/support/DelegatedIoAcceptor.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/SocketAcceptorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoAcceptor.java?rev=379346&r1=379345&r2=379346&view=diff
==============================================================================
--- 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 Mon Feb
20 21:10:30 2006
@@ -64,6 +64,17 @@
      * connected there.
      */
     void unbind( SocketAddress address );
+
+    /**
+     * 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 );
     
     /**
      * (Optional) Returns an {@link IoSession} that is bound to the specified

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java?rev=379346&r1=379345&r2=379346&view=diff
==============================================================================
--- 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
Mon Feb 20 21:10:30 2006
@@ -69,6 +69,16 @@
     {
         delegate.unbind( address );
     }
+    
+    public void unbindAll()
+    {
+        delegate.unbindAll();
+    }
+    
+    public boolean isBound( SocketAddress address )
+    {
+        return delegate.isBound( address );
+    }
 
     public Set getManagedSessions( SocketAddress address )
     {

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?rev=379346&r1=379345&r2=379346&view=diff
==============================================================================
--- 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
Mon Feb 20 21:10:30 2006
@@ -24,8 +24,10 @@
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -167,6 +169,28 @@
         }
     }
     
+    public void unbindAll()
+    {
+        List addresses;
+        synchronized( channels )
+        {
+            addresses = new ArrayList( channels.keySet() );
+        }
+        
+        for( Iterator i = addresses.iterator(); i.hasNext(); )
+        {
+            unbind( ( SocketAddress ) i.next() );
+        }
+    }
+    
+    public boolean isBound( SocketAddress address )
+    {
+        synchronized( channels )
+        {
+            return channels.containsKey( address );
+        }
+    }
+    
     public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress
)
     {
         if( remoteAddress == null )
@@ -525,7 +549,10 @@
                 ch.configureBlocking( false );
                 ch.socket().bind( req.address );
                 ch.register( selector, SelectionKey.OP_READ, req );
-                channels.put( req.address, ch );
+                synchronized( channels )
+                {
+                    channels.put( req.address, ch );
+                }
             }
             catch( Throwable t )
             {
@@ -573,7 +600,12 @@
                 break;
             }
 
-            DatagramChannel ch = ( DatagramChannel ) channels.remove( request.address );
+            DatagramChannel ch;
+            synchronized( channels )
+            {
+                ch = ( DatagramChannel ) channels.remove( request.address );
+            }
+
             // close the channel
             try
             {

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java?rev=379346&r1=379345&r2=379346&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
Mon Feb 20 21:10:30 2006
@@ -25,12 +25,14 @@
 import java.nio.channels.Selector;
 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;
 import java.util.Set;
 
@@ -286,6 +288,28 @@
         }        
     }
     
+    public void unbindAll()
+    {
+        List addresses;
+        synchronized( channels )
+        {
+            addresses = new ArrayList( channels.keySet() );
+        }
+        
+        for( Iterator i = addresses.iterator(); i.hasNext(); )
+        {
+            unbind( ( SocketAddress ) i.next() );
+        }
+    }
+    
+    public boolean isBound( SocketAddress address )
+    {
+        synchronized( channels )
+        {
+            return channels.containsKey( address );
+        }
+    }
+    
     private class Worker extends Thread
     {
         public Worker()
@@ -462,7 +486,10 @@
                 ssc.socket().bind( req.address, cfg.getBacklog() );
                 ssc.register( selector, SelectionKey.OP_ACCEPT, req );
 
-                channels.put( req.address, ssc );
+                synchronized( channels )
+                {
+                    channels.put( req.address, ssc );
+                }
                 sessions.put( req.address, Collections.synchronizedSet( new HashSet() ) );
             }
             catch( IOException e )
@@ -516,7 +543,11 @@
             }
 
             sessions.remove( request.address );
-            ServerSocketChannel ssc = ( ServerSocketChannel ) channels.remove( request.address
);
+            ServerSocketChannel ssc;
+            synchronized( channels )
+            {
+                ssc = ( ServerSocketChannel ) channels.remove( request.address );
+            }
             
             // close the channel
             try

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java?rev=379346&r1=379345&r2=379346&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
Mon Feb 20 21:10:30 2006
@@ -5,9 +5,12 @@
 
 import java.io.IOException;
 import java.net.SocketAddress;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -71,7 +74,7 @@
                                           handler, config ) );
         }
     }
-
+    
     public Set getManagedSessions( SocketAddress address )
     {
         if( address == null )
@@ -162,6 +165,26 @@
                 // Ignored
             }
         }                
+    }
+    
+    public void unbindAll()
+    {
+        synchronized( boundHandlers )
+        {
+            List addresses = new ArrayList( boundHandlers.keySet() );
+            for( Iterator i = addresses.iterator(); i.hasNext(); )
+            {
+                unbind( ( SocketAddress ) i.next() );
+            }
+        }
+    }
+    
+    public boolean isBound( SocketAddress address )
+    {
+        synchronized( boundHandlers )
+        {
+            return boundHandlers.containsKey( address );
+        }
     }
     
     public IoServiceConfig getDefaultConfig()



Mime
View raw message