[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpcomponents-commits
Subject:    svn commit: r981057 -
From:       olegk () apache ! org
Date:       2010-07-31 13:34:40
Message-ID: 20100731133440.B419723889E5 () eris ! apache ! org
[Download RAW message or body]

Author: olegk
Date: Sat Jul 31 13:34:40 2010
New Revision: 981057

URL: http://svn.apache.org/viewvc?rev=981057&view=rev
Log:
Synchronize all methods of IOSessionImpl

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java


Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
                
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/ \
java/org/apache/http/impl/nio/reactor/IOSessionImpl.java?rev=981057&r1=981056&r2=981057&view=diff
 ==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java \
                (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java \
Sat Jul 31 13:34:40 2010 @@ -47,17 +47,16 @@ import org.apache.http.nio.reactor.Sessi
  */
 public class IOSessionImpl implements IOSession {
 
-    private volatile int status;
-
     private final SelectionKey key;
     private final ByteChannel channel;
     private final Map<String, Object> attributes;
     private final InterestOpsCallback interestOpsCallback;
     private final SessionClosedCallback sessionClosedCallback;
 
-    private SessionBufferStatus bufferStatus;
-    private int socketTimeout;
+    private volatile int status;
     private volatile int currentEventMask;
+    private volatile SessionBufferStatus bufferStatus;
+    private volatile int socketTimeout;
 
     /**
      * Creates new instance of IOSessionImpl.
@@ -103,7 +102,7 @@ public class IOSessionImpl implements IO
     }
 
     public SocketAddress getLocalAddress() {
-        Channel channel = this.key.channel();
+        Channel channel = this.channel;
         if (channel instanceof SocketChannel) {
             return ((SocketChannel)channel).socket().getLocalSocketAddress();
         } else {
@@ -112,7 +111,7 @@ public class IOSessionImpl implements IO
     }
 
     public SocketAddress getRemoteAddress() {
-        Channel channel = this.key.channel();
+        Channel channel = this.channel;
         if (channel instanceof SocketChannel) {
             return ((SocketChannel)channel).socket().getRemoteSocketAddress();
         } else {
@@ -120,11 +119,11 @@ public class IOSessionImpl implements IO
         }
     }
 
-    public int getEventMask() {
+    public synchronized int getEventMask() {
         return this.interestOpsCallback != null ? this.currentEventMask : \
this.key.interestOps();  }
 
-    public void setEventMask(int ops) {
+    public synchronized void setEventMask(int ops) {
         if (this.status == CLOSED) {
             return;
         }
@@ -143,7 +142,7 @@ public class IOSessionImpl implements IO
         this.key.selector().wakeup();
     }
 
-    public void setEvent(int op) {
+    public synchronized void setEvent(int op) {
         if (this.status == CLOSED) {
             return;
         }
@@ -157,15 +156,13 @@ public class IOSessionImpl implements IO
             // add this operation to the interestOps() queue
             this.interestOpsCallback.addInterestOps(entry);
         } else {
-            synchronized (this.key) {
-                int ops = this.key.interestOps();
-                this.key.interestOps(ops | op);
-            }
+            int ops = this.key.interestOps();
+            this.key.interestOps(ops | op);
         }
         this.key.selector().wakeup();
     }
 
-    public void clearEvent(int op) {
+    public synchronized void clearEvent(int op) {
         if (this.status == CLOSED) {
             return;
         }
@@ -179,10 +176,8 @@ public class IOSessionImpl implements IO
             // add this operation to the interestOps() queue
             this.interestOpsCallback.addInterestOps(entry);
         } else {
-            synchronized (this.key) {
-                int ops = this.key.interestOps();
-                this.key.interestOps(ops & ~op);
-            }
+            int ops = this.key.interestOps();
+            this.key.interestOps(ops & ~op);
         }
         this.key.selector().wakeup();
     }
@@ -195,7 +190,7 @@ public class IOSessionImpl implements IO
         this.socketTimeout = timeout;
     }
 
-    public void close() {
+    public synchronized void close() {
         if (this.status == CLOSED) {
             return;
         }
@@ -220,7 +215,7 @@ public class IOSessionImpl implements IO
     }
 
     public boolean isClosed() {
-        return this.status == CLOSED || !this.key.isValid();
+        return this.status == CLOSED;
     }
 
     public void shutdown() {
@@ -230,11 +225,13 @@ public class IOSessionImpl implements IO
     }
 
     public boolean hasBufferedInput() {
-        return this.bufferStatus != null && this.bufferStatus.hasBufferedInput();
+        SessionBufferStatus bufferStatus = this.bufferStatus;
+        return bufferStatus != null && bufferStatus.hasBufferedInput();
     }
 
     public boolean hasBufferedOutput() {
-        return this.bufferStatus != null && this.bufferStatus.hasBufferedOutput();
+        SessionBufferStatus bufferStatus = this.bufferStatus;
+        return bufferStatus != null && bufferStatus.hasBufferedOutput();
     }
 
     public void setBufferStatus(final SessionBufferStatus bufferStatus) {
@@ -271,7 +268,7 @@ public class IOSessionImpl implements IO
     }
 
     @Override
-    public String toString() {
+    public synchronized String toString() {
         StringBuffer buffer = new StringBuffer();
         buffer.append("[");
         if (this.key.isValid()) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic