hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r756997 - in /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor: AbstractIOReactor.java IOSessionImpl.java InterestOpEntry.java
Date Sat, 21 Mar 2009 19:36:57 GMT
Author: olegk
Date: Sat Mar 21 19:36:56 2009
New Revision: 756997

URL: http://svn.apache.org/viewvc?rev=756997&view=rev
Log:
HTTPCORE-155: Compatibility mode with IBM JRE and other JREs with naive (broken) implementation
of SelectionKey.

* code brush-ups

Contributed by Marc Beyerle <marc.beyerle at de.ibm.com> 
Reviewed by Oleg Kalnichevski

Modified:
    httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
    httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
    httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java

Modified: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java?rev=756997&r1=756996&r2=756997&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
(original)
+++ httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
Sat Mar 21 19:36:56 2009
@@ -427,7 +427,7 @@
         Processes all pending {@link java.nio.channels.SelectionKey#interestOps(int) interestOps(int)}
         operations.
     */
-    protected void processPendingInterestOps() {
+    private void processPendingInterestOps() {
         // validity check
         if (!this.interestOpsQueueing) {
             return;
@@ -442,17 +442,10 @@
 
                 // obtain the operation's details
                 IOSessionImpl ioSession = queueElement.getIoSession();
-                int operationType = queueElement.getOperationType();
-                int operationArgument = queueElement.getOperationArgument();
+                int eventMask = queueElement.getEventMask();
 
                 // perform the operation
-                if (operationType == InterestOpEntry.OPERATION_TYPE_SET_EVENT) {
-                    ioSession.setEventImpl(operationArgument);
-                } else if (operationType == InterestOpEntry.OPERATION_TYPE_CLEAR_EVENT) {
-                    ioSession.clearEventImpl(operationArgument);
-                } else if (operationType == InterestOpEntry.OPERATION_TYPE_SET_EVENT_MASK)
{
-                    ioSession.setEventMaskImpl(operationArgument);
-                }
+                ioSession.applyEventMask(eventMask);
             }
         }
     }
@@ -596,18 +589,6 @@
             return false;
         }
 
-        // local variable
-        int operationType = entry.getOperationType();
-
-        /*
-            NOTE: Most of the operations are setEvent(), so check for this one first.
-        */
-        if ((operationType != InterestOpEntry.OPERATION_TYPE_SET_EVENT) &&
-            (operationType != InterestOpEntry.OPERATION_TYPE_CLEAR_EVENT) &&
-            (operationType != InterestOpEntry.OPERATION_TYPE_SET_EVENT_MASK)) {
-            return false;
-        }
-
         synchronized (this.interestOpsQueue) {
             // add this operation to the interestOps() queue
             this.interestOpsQueue.add(entry);

Modified: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java?rev=756997&r1=756996&r2=756997&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
(original)
+++ httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
Sat Mar 21 19:36:56 2009
@@ -65,6 +65,7 @@
     
     private SessionBufferStatus bufferStatus;
     private int socketTimeout;
+    private volatile int currentEventMask;
     
     public IOSessionImpl(final SelectionKey key, final SessionClosedCallback callback, final
AbstractIOReactor abstractIOReactor) {
         super();
@@ -83,6 +84,7 @@
         this.attributes = Collections.synchronizedMap(new HashMap<String, Object>());
         this.abstractIOReactor = abstractIOReactor;
         this.interestOpsQueueing = abstractIOReactor.getInterestOpsQueueing();
+        this.currentEventMask = 0;
         this.socketTimeout = 0;
         this.status = ACTIVE;
     }
@@ -110,93 +112,77 @@
     }
 
     public int getEventMask() {
-        if (interestOpsQueueing) {
-            // flush the interestOps() queue
-            abstractIOReactor.processPendingInterestOps();
-        }
-
-        return this.key.interestOps();
+        return this.interestOpsQueueing ? this.currentEventMask : this.key.interestOps();
     }
     
     public void setEventMask(int ops) {
+        if (this.status == CLOSED) {
+            return;
+        }
         if (this.interestOpsQueueing) {
+            // update the current event mask
+            this.currentEventMask = ops;
+
             // local variable
-            InterestOpEntry entry = new InterestOpEntry(
-                    this, InterestOpEntry.OPERATION_TYPE_SET_EVENT_MASK, ops);
+            InterestOpEntry entry = new InterestOpEntry(this, this.currentEventMask);
 
             // add this operation to the interestOps() queue
             this.abstractIOReactor.addInterestOpsQueueElement(entry);
-
-            // wake up this key's selector
-            this.key.selector().wakeup();
         } else {
-            // simply invoke the actual implementation
-            setEventMaskImpl(ops);
+            this.key.interestOps(ops);
         }
+        this.key.selector().wakeup();
     }
 
-    protected void setEventMaskImpl(int ops) {
+    public void setEvent(int op) {
         if (this.status == CLOSED) {
             return;
         }
-        this.key.interestOps(ops);
-        this.key.selector().wakeup();
-    }
-    
-    public void setEvent(int op) {
         if (this.interestOpsQueueing) {
+            // update the current event mask
+            this.currentEventMask |= op;
+
             // local variable
-            InterestOpEntry entry = new InterestOpEntry(this, 
-                    InterestOpEntry.OPERATION_TYPE_SET_EVENT, op);
+            InterestOpEntry entry = new InterestOpEntry(this, this.currentEventMask);
 
             // add this operation to the interestOps() queue
             this.abstractIOReactor.addInterestOpsQueueElement(entry);
-
-            // wake up this key's selector
-            this.key.selector().wakeup();
         } else {
-            // simply invoke the actual implementation
-            setEventImpl(op);
+            synchronized (this.key) {
+                int ops = this.key.interestOps();
+                this.key.interestOps(ops | op);
+            }
         }
+        this.key.selector().wakeup();
     }
 
-    protected void setEventImpl(int op) {
+    public void clearEvent(int op) {
         if (this.status == CLOSED) {
             return;
         }
-        synchronized (this.key) {
-            int ops = this.key.interestOps();
-            this.key.interestOps(ops | op);
-        }
-        this.key.selector().wakeup();
-    }
-    
-    public void clearEvent(int op) {
         if (this.interestOpsQueueing) {
+            // update the current event mask
+            this.currentEventMask &= ~op;
+
             // local variable
-            InterestOpEntry entry = new InterestOpEntry(this, 
-                    InterestOpEntry.OPERATION_TYPE_CLEAR_EVENT, op);
+            InterestOpEntry entry = new InterestOpEntry(this, this.currentEventMask);
 
             // add this operation to the interestOps() queue
             this.abstractIOReactor.addInterestOpsQueueElement(entry);
-
-            // wake up this key's selector
-            this.key.selector().wakeup();
         } else {
-            // simply invoke the actual implementation
-            clearEventImpl(op);
+            synchronized (this.key) {
+                int ops = this.key.interestOps();
+                this.key.interestOps(ops & ~op);
+            }
         }
+        this.key.selector().wakeup();
     }
 
-    protected void clearEventImpl(int op) {
+    protected void applyEventMask(int ops) {
         if (this.status == CLOSED) {
             return;
         }
-        synchronized (this.key) {
-            int ops = this.key.interestOps();
-            this.key.interestOps(ops & ~op);
-        }
-        this.key.selector().wakeup();
+        this.key.interestOps(ops);
     }
     
     public int getSocketTimeout() {
@@ -288,13 +274,8 @@
         buffer.append("[");
         if (this.key.isValid()) {
             buffer.append("interested ops: ");
-
-            if (interestOpsQueueing) {
-                // flush the interestOps() queue
-                abstractIOReactor.processPendingInterestOps();
-            }
-
-            formatOps(buffer, this.key.interestOps());
+            formatOps(buffer, this.interestOpsQueueing ? 
+                    this.currentEventMask : this.key.interestOps());
             buffer.append("; ready ops: ");
             formatOps(buffer, this.key.readyOps());
         } else {

Modified: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java?rev=756997&r1=756996&r2=756997&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java
(original)
+++ httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java
Sat Mar 21 19:36:56 2009
@@ -37,33 +37,21 @@
  */
 class InterestOpEntry {
 
-    public static final int OPERATION_TYPE_SET_EVENT_MASK = 0;
-
-    public static final int OPERATION_TYPE_SET_EVENT = 1;
-
-    public static final int OPERATION_TYPE_CLEAR_EVENT = 2;
-
     private final IOSessionImpl ioSession;
-    private final int operationType;
-    private final int operationArgument;
+    private final int eventMask;
 
-    public InterestOpEntry(IOSessionImpl ioSession, int operationType, int operationArgument)
{
+    public InterestOpEntry(IOSessionImpl ioSession, int eventMask) {
         // initialize instance members
         this.ioSession = ioSession;
-        this.operationType = operationType;
-        this.operationArgument = operationArgument;
+        this.eventMask = eventMask;
     }
 
     public IOSessionImpl getIoSession() {
         return ioSession;
     }
 
-    public int getOperationType() {
-        return operationType;
-    }
-
-    public int getOperationArgument() {
-        return operationArgument;
+    public int getEventMask() {
+        return eventMask;
     }
 
 }



Mime
View raw message