directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r344372 - in /directory/network/trunk/src/java/org/apache/mina/transport: socket/nio/support/DatagramSessionImpl.java socket/nio/support/SocketSessionImpl.java vmpipe/support/VmPipeSessionImpl.java
Date Tue, 15 Nov 2005 15:02:42 GMT
Author: trustin
Date: Tue Nov 15 07:02:37 2005
New Revision: 344372

URL: http://svn.apache.org/viewcvs?rev=344372&view=rev
Log:
Introduced thread safety for close(), write(), and isClosing()

Modified:
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
    directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java?rev=344372&r1=344371&r2=344372&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
Tue Nov 15 07:02:37 2005
@@ -45,21 +45,14 @@
 class DatagramSessionImpl extends BaseIoSession implements DatagramSession
 {
     private final IoSessionManagerFilterChain managerFilterChain;
-    
     private final IoSessionFilterChain filterChain;
-
     private final DatagramChannel ch;
-
     private final Queue writeRequestQueue;
-
     private final IoHandler handler;
-
     private final SocketAddress localAddress;
-
+    private final Object ioLock = new Object();
     private SocketAddress remoteAddress;
-
     private SelectionKey key;
-    
     private final CloseFuture closeFuture = new CloseFuture();
     private boolean closing;
 
@@ -115,17 +108,23 @@
     
     public CloseFuture close()
     {
-        if( !closing && !closeFuture.isReady() )
+        synchronized( ioLock )
         {
-            closing = true;
-            managerFilterChain.filterClose( this, closeFuture );
+            if( !closing )
+            {
+                closing = true;
+                managerFilterChain.filterClose( this, closeFuture );
+            }
         }
         return closeFuture;
     }
     
     public boolean isClosing()
     {
-        return closing;
+        synchronized( ioLock )
+        {
+            return closing;
+        }
     }
 
     Queue getWriteRequestQueue()
@@ -136,13 +135,16 @@
     public WriteFuture write( Object message )
     {
         WriteFuture future = new WriteFuture();
-        if( isClosing() )
-        {
-            future.setWritten( false );
-        }
-        else
+        synchronized( ioLock )
         {
-            filterChain.filterWrite( this, new WriteRequest( message, future ) );
+            if( isClosing() )
+            {
+                future.setWritten( false );
+            }
+            else
+            {
+                filterChain.filterWrite( this, new WriteRequest( message, future ) );
+            }
         }
         return future;
     }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java?rev=344372&r1=344371&r2=344372&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
Tue Nov 15 07:02:37 2005
@@ -54,6 +54,7 @@
     private final IoHandler handler;
     private final SocketAddress remoteAddress;
     private final SocketAddress localAddress;
+    private final Object ioLock = new Object();
     private SelectionKey key;
     private CloseFuture closeFuture = new CloseFuture();
     private boolean closing;
@@ -119,10 +120,13 @@
     
     public CloseFuture close()
     {
-        if( !closing && !closeFuture.isReady() )
+        synchronized( ioLock )
         {
-            closing = true;
-            filterChain.filterClose( this, closeFuture );
+            if( !closing )
+            {
+                closing = true;
+                filterChain.filterClose( this, closeFuture );
+            }
         }
 
         return closeFuture;
@@ -130,7 +134,10 @@
     
     public boolean isClosing()
     {
-        return closing;
+        synchronized( ioLock )
+        {
+            return closing;
+        }
     }
 
     Queue getWriteRequestQueue()
@@ -149,13 +156,16 @@
     public WriteFuture write( Object message )
     {
         WriteFuture future = new WriteFuture();
-        if( isClosing() )
-        {
-            future.setWritten( false );
-        }
-        else
+        synchronized( ioLock )
         {
-            filterChain.filterWrite( this, new WriteRequest( message, future ) );
+            if( isClosing() )
+            {
+                future.setWritten( false );
+            }
+            else
+            {
+                filterChain.filterWrite( this, new WriteRequest( message, future ) );
+            }
         }
         return future;
     }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java?rev=344372&r1=344371&r2=344372&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
Tue Nov 15 07:02:37 2005
@@ -29,19 +29,13 @@
 public class VmPipeSessionImpl extends BaseIoSession implements VmPipeSession
 {
     private final SocketAddress localAddress;
-
     private final SocketAddress remoteAddress;
-
     private final IoHandler handler;
-    
     private final IoSessionFilterChain filterChain;
-    
     private final VmPipeSessionManagerFilterChain managerFilterChain;
-
+    private final Object ioLock = new Object();
     final VmPipeSessionImpl remoteSession;
-
     final Object lock;
-
     private boolean closing;
     CloseFuture closeFuture = new CloseFuture();
 
@@ -130,31 +124,39 @@
 
     public CloseFuture close()
     {
-        if( !closing )
+        synchronized( ioLock )
         {
-            closing = true;
-            managerFilterChain.filterClose( this, closeFuture );
+            if( !closing )
+            {
+                closing = true;
+                managerFilterChain.filterClose( this, closeFuture );
+            }
         }
-            
         return closeFuture;
     }
     
     public boolean isClosing()
     {
-        return closing;
+        synchronized( ioLock )
+        {
+            return closing;
+        }
     }
     
 
     public WriteFuture write( Object message )
     {
         WriteFuture future = new WriteFuture();
-        if( isClosing() )
-        {
-            future.setWritten( false );
-        }
-        else
+        synchronized( ioLock )
         {
-            this.filterChain.filterWrite( this, new WriteRequest( message, future ) );
+            if( isClosing() )
+            {
+                future.setWritten( false );
+            }
+            else
+            {
+                this.filterChain.filterWrite( this, new WriteRequest( message, future ) );
+            }
         }
         return future;
     }



Mime
View raw message