directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r354351 - /directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java
Date Tue, 06 Dec 2005 07:58:27 GMT
Author: trustin
Date: Mon Dec  5 23:58:22 2005
New Revision: 354351

URL: http://svn.apache.org/viewcvs?rev=354351&view=rev
Log:
Removed ioLock and replaced it with 'this'.

Modified:
    directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java

Modified: directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java?rev=354351&r1=354350&r2=354351&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java Mon
Dec  5 23:58:22 2005
@@ -19,6 +19,7 @@
 package org.apache.mina.common.support;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -41,12 +42,6 @@
     private final Map attributes = new HashMap();
     private final long creationTime;
 
-    /**
-     * A lock object which is acquired when {@link IoSession#close()},
-     * {@link #isClosing()}, or {@link IoSession#write(Object)} is invoked.
-     */
-    protected final Object ioLock = new Object();
-    
     /** 
      * A future that will be set 'closed' when the connection is closed.
      */
@@ -89,12 +84,9 @@
         return !closeFuture.isClosed();
     }
     
-    public boolean isClosing()
+    public synchronized boolean isClosing()
     {
-        synchronized( ioLock )
-        {
-            return closing;
-        }
+        return closing;
     }
     
     public CloseFuture getCloseFuture()
@@ -102,19 +94,15 @@
         return closeFuture;
     }
     
-    public CloseFuture close()
+    public synchronized CloseFuture close()
     {
-        synchronized( ioLock )
+        if( !closing )
         {
-            if( !closing )
-            {
-                closing = true;
-                close0( closeFuture );
-            }
+            closing = true;
+            close0( closeFuture );
         }
 
         return closeFuture;
-
     }
 
     /**
@@ -129,19 +117,16 @@
         closeFuture.setClosed();
     }
     
-    public WriteFuture write( Object message )
+    public synchronized WriteFuture write( Object message )
     {
         WriteFuture future = new WriteFuture();
-        synchronized( ioLock )
+        if( isClosing() )
+        {
+            future.setWritten( false );
+        }
+        else
         {
-            if( isClosing() )
-            {
-                future.setWritten( false );
-            }
-            else
-            {
-                write0( new WriteRequest( message, future ) );
-            }
+            write0( new WriteRequest( message, future ) );
         }
         return future;
     }
@@ -161,7 +146,10 @@
     
     public Object getAttachment()
     {
-        return attributes.get( "" );
+        synchronized( attributes )
+        {
+            return attributes.get( "" );
+        }
     }
 
     public Object setAttachment( Object attachment )
@@ -174,7 +162,10 @@
 
     public Object getAttribute( String key )
     {
-        return attributes.get( key );
+        synchronized( attributes )
+        {
+            return attributes.get( key );
+        }
     }
 
     public Object setAttribute( String key, Object value )
@@ -203,10 +194,11 @@
         return getAttribute( key ) != null;
     }
 
-    public Set getAttributeKeys() {
+    public Set getAttributeKeys()
+    {
         synchronized( attributes )
         {
-            return attributes.keySet();
+            return new HashSet( attributes.keySet() );
         }
     }
     



Mime
View raw message