hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r573715 - in /jakarta/httpcomponents/httpcore/trunk: contrib/src/main/java/org/apache/http/contrib/logging/ module-nio/src/main/java/org/apache/http/impl/nio/reactor/ module-nio/src/main/java/org/apache/http/nio/reactor/ module-niossl/src/m...
Date Fri, 07 Sep 2007 21:17:56 GMT
Author: olegk
Date: Fri Sep  7 14:17:55 2007
New Revision: 573715

URL: http://svn.apache.org/viewvc?rev=573715&view=rev
Log:
Maintain a more fine-grained NIO session status (ACTIVE|CLOSING|CLOSED)

Modified:
    jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java

Modified: jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java?rev=573715&r1=573714&r2=573715&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
Fri Sep  7 14:17:55 2007
@@ -134,6 +134,10 @@
         this.session.close();
     }
 
+    public int getStatus() {
+        return this.session.getStatus();
+    }
+
     public boolean isClosed() {
         return this.session.isClosed();
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java?rev=573715&r1=573714&r2=573715&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
Fri Sep  7 14:17:55 2007
@@ -46,7 +46,7 @@
 
 public class IOSessionImpl implements IOSession {
     
-    private volatile boolean closed = false;
+    private volatile int status;
     
     private final SelectionKey key;
     private final ByteChannel channel;
@@ -66,6 +66,7 @@
         this.callback = callback;
         this.attributes = Collections.synchronizedMap(new HashMap());
         this.socketTimeout = 0;
+        this.status = ACTIVE;
     }
     
     public ByteChannel channel() {
@@ -95,7 +96,7 @@
     }
     
     public void setEventMask(int ops) {
-        if (this.closed) {
+        if (this.status == CLOSED) {
             return;
         }
         synchronized (this.key) {
@@ -105,7 +106,7 @@
     }
     
     public void setEvent(int op) {
-        if (this.closed) {
+        if (this.status == CLOSED) {
             return;
         }
         synchronized (this.key) {
@@ -116,7 +117,7 @@
     }
     
     public void clearEvent(int op) {
-        if (this.closed) {
+        if (this.status == CLOSED) {
             return;
         }
         synchronized (this.key) {
@@ -135,10 +136,10 @@
     }
     
     public void close() {
-        if (this.closed) {
+        if (this.status == CLOSED) {
             return;
         }
-        this.closed = true;
+        this.status = CLOSED;
         this.key.cancel();
         try {
             this.key.channel().close();
@@ -154,8 +155,12 @@
         }
     }
     
+    public int getStatus() {
+        return this.status;
+    }
+
     public boolean isClosed() {
-        return this.closed || !this.key.isValid();
+        return this.status == CLOSED || !this.key.isValid();
     }
     
     public void shutdown() {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java?rev=573715&r1=573714&r2=573715&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java
Fri Sep  7 14:17:55 2007
@@ -38,6 +38,10 @@
 
     public static final String ATTACHMENT_KEY = "http.session.attachment";
 
+    public static final int ACTIVE       = 0;
+    public static final int CLOSING      = 1;
+    public static final int CLOSED       = Integer.MAX_VALUE;
+    
     ByteChannel channel();
     
     SocketAddress getRemoteAddress();    
@@ -55,6 +59,8 @@
     void close();
     
     void shutdown();
+    
+    int getStatus();
     
     boolean isClosed();
 

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java?rev=573715&r1=573714&r2=573715&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
Fri Sep  7 14:17:55 2007
@@ -69,7 +69,7 @@
     private int appEventMask;
     private SessionBufferStatus appBufferStatus;
     
-    private volatile boolean closed;
+    private volatile int status;
     
     public SSLIOSession(
             final IOSession session, 
@@ -146,7 +146,7 @@
                     handshaking = false;
                 }
                 if (result.getStatus() == Status.CLOSED) {
-                    this.closed = true;
+                    this.status = CLOSED;
                 }
                 break;
             case NEED_UNWRAP:
@@ -158,7 +158,7 @@
                     handshaking = false;
                 }
                 if (result.getStatus() == Status.CLOSED) {
-                    this.closed = true;
+                    this.status = CLOSED;
                 }
                 break;
             case NEED_TASK:
@@ -239,7 +239,7 @@
             SSLEngineResult result = this.sslEngine.unwrap(this.inEncrypted, this.inPlain);
             this.inEncrypted.compact();
             if (result.getStatus() == Status.CLOSED) {
-                this.closed = true;
+                this.status = CLOSED;
             }
             if (result.getStatus() == Status.OK) {
                 decrypted = true;
@@ -251,7 +251,7 @@
     public synchronized boolean isAppInputReady() throws IOException {
         int bytesRead = receiveEncryptedData();
         if (bytesRead == -1) {
-            this.closed = true;
+            this.status = CLOSED;
             return false;
         }
         doHandshake();
@@ -260,7 +260,7 @@
     }
     
     public synchronized boolean isAppOutputReady() throws IOException {
-        return !this.closed
+        return this.status != CLOSED
             && this.sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING;
     }
     
@@ -278,7 +278,7 @@
         if (src == null) {
             throw new IllegalArgumentException("Byte buffer may not be null");
         }
-        if (this.closed) {
+        if (this.status == CLOSED) {
             return -1;
         }
         if (this.outPlain.position() > 0) {
@@ -289,7 +289,7 @@
         if (this.outPlain.position() == 0) {
             SSLEngineResult result = this.sslEngine.wrap(src, this.outEncrypted);
             if (result.getStatus() == Status.CLOSED) {
-                this.closed = true;
+                this.status = CLOSED;
             }
             return result.bytesConsumed();
         } else {
@@ -301,7 +301,7 @@
         if (dst == null) {
             throw new IllegalArgumentException("Byte buffer may not be null");
         }
-        if (this.closed) {
+        if (this.status == CLOSED) {
             return -1;
         }
         if (this.inPlain.position() > 0) {
@@ -318,18 +318,22 @@
     }
     
     public void close() {
-        if (this.closed) {
+        if (this.status == CLOSED) {
             return;
         }
-        this.closed = true;
+        this.status = CLOSED;
         synchronized(this) {
             this.sslEngine.closeOutbound();
             updateEventMask();
         }
     }
+    
+    public int getStatus() {
+        return this.status;
+    }
 
     public boolean isClosed() {
-        return this.closed;
+        return this.status == CLOSED;
     }
 
     public synchronized boolean isInboundDone() {
@@ -341,7 +345,7 @@
     }
     
     public void shutdown() {
-        this.closed = true;
+        this.status = CLOSED;
         this.session.shutdown();
     }
 



Mime
View raw message