Author: fhanik
Date: Fri Aug 31 13:59:00 2007
New Revision: 571578

URL: http://svn.apache.org/viewvc?rev=571578&view=rev
Log:
Move back to original idea, use primitive int instead of enum, extremely 
inefficient using enums and arrays to hold them. 

Modified:
    tomcat/trunk/java/org/apache/catalina/CometEvent.java
    tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java
    tomcat/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
    tomcat/trunk/java/org/apache/tomcat/util/net/PollerInterest.java

Modified: tomcat/trunk/java/org/apache/catalina/CometEvent.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/CometEvent.java?rev=571578&r1=571577&r2=571578&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/CometEvent.java (original)
+++ tomcat/trunk/java/org/apache/catalina/CometEvent.java Fri Aug 31 13:59:00 
2007
@@ -23,6 +23,7 @@
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.nio.channels.SelectionKey;
 
 /**
  * The CometEvent interface.
@@ -139,7 +140,7 @@
      * asycnhronously, then issue a 
      * register(OP_CALLBACK) immediately after this method has been invoked.
      * 
-     * @see #register(CometOperation)
+     * @see #register(int)
      */
     public void close() throws IOException;
     
@@ -190,9 +191,14 @@
      * OP_CALLBACK - receive a CALLBACK event from the container
      * OP_READ - receive a READ event when the connection has data to be read
      * OP_WRITE - receive a WRITE event when the connection is able to receive 
data to be written
-     * @see #register(CometOperations)
+     * @see #register(int)
      */
-    public enum CometOperation {OP_CALLBACK, OP_READ, OP_WRITE};
+    public static class CometOperation {
+        //currently map these to the same values as 
org.apache.tomcat.util.net.PollerInterest
+        public static final int OP_CALLBACK = 0x200;
+        public static final int OP_READ = SelectionKey.OP_READ;
+        public static final int OP_WRITE = SelectionKey.OP_WRITE;
+    };
     
     /**
      * Registers the Comet connection with the container for IO and event 
notifications.
@@ -203,22 +209,22 @@
      * @see #EventType
      * @see #CometOperation
      */
-    public void register(CometOperation... operations) throws 
IllegalStateException;
+    public void register(int operations) throws IllegalStateException;
     
     /**
      * Unregisters Comet operations for this CometConnection
      * @param operations CometOperation[]
      * @throws IllegalStateException
      */
-    public void unregister(CometOperation... operations) throws 
IllegalStateException;
+    public void unregister(int operations) throws IllegalStateException;
 
     /**
      * Returns what the current IO notifications that the Comet
      * connection is registered for.
-     * @return CometOperations[]
-     * @see #register(CometOperations...)
+     * @return integer representing registered operations
+     * @see #register(int)
      */
-    public CometOperation[] getRegisteredOps();
+    public int getRegisteredOps();
     
     /**
      * Returns true if the Comet connection is blocking or non blocking and 
you can write

Modified: tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java?rev=571578&r1=571577&r2=571578&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java Fri Aug 
31 13:59:00 2007
@@ -77,7 +77,7 @@
     /**
      * Current set of operations
      */
-    protected HashSet<CometOperation> cometOperations = new 
HashSet<CometOperation>(3);
+    protected int cometOperations = 0;
     
     /**
      * Blocking or not blocking
@@ -97,7 +97,7 @@
         request = null;
         response = null;
         blocking = true;
-        cometOperations.clear();
+        cometOperations = 0;
     }
 
     public void setEventType(EventType eventType) {
@@ -148,8 +148,8 @@
         return response.isWriteable();
     }
     
-    public boolean hasOp(CometEvent.CometOperation op) {
-        return cometOperations.contains(op);
+    public boolean hasOp(int op) {
+        return (cometOperations & op ) == op;
     }
     
     public void configureBlocking(boolean blocking) throws 
IllegalStateException {
@@ -160,24 +160,24 @@
         this.blocking = bool.get();
     }
 
-    public void register(CometEvent.CometOperation... operations) throws 
IllegalStateException {
+    public void register(int operations) throws IllegalStateException {
         //add it to the registered set
-        cometOperations.addAll(Arrays.asList(operations));
-        request.action(ActionCode.ACTION_COMET_REGISTER, 
translate(cometOperations.toArray(new CometOperation[0])));
+        cometOperations = cometOperations | operations;
+        request.action(ActionCode.ACTION_COMET_REGISTER, 
translate(cometOperations));
     }
 
-    public void unregister(CometOperation... operations) throws 
IllegalStateException {
+    public void unregister(int operations) throws IllegalStateException {
         //remove from the registered set
-        cometOperations.removeAll(Arrays.asList(operations));
-        request.action(ActionCode.ACTION_COMET_REGISTER, 
translate(cometOperations.toArray(new CometOperation[0])));
+        cometOperations = cometOperations & (~operations);
+        request.action(ActionCode.ACTION_COMET_REGISTER, 
translate(cometOperations));
     }
     
     public boolean isBlocking() {
         return blocking;
     }
     
-    public CometOperation[] getRegisteredOps() {
-        return (CometOperation[])cometOperations.toArray(new 
CometOperation[0]);
+    public int getRegisteredOps() {
+        return cometOperations;
     }
     
     public String toString() {
@@ -204,19 +204,8 @@
             throw new IllegalStateException("The operation can only be 
performed when invoked by a Tomcat worker thread.");
     }
     
-    protected PollerInterest[] translate(CometOperation... op) {
-        PollerInterest[] result = new PollerInterest[op.length];
-        for (int i=0; i<result.length; i++) {
-            if (op[i] == CometEvent.CometOperation.OP_READ)
-                result[i] = PollerInterest.READ;
-            else if (op[i] == CometEvent.CometOperation.OP_WRITE)
-                result[i] = PollerInterest.WRITE;
-            else if (op[i] == CometEvent.CometOperation.OP_CALLBACK)
-                result[i] = PollerInterest.CALLBACK;
-            else
-                throw new IllegalArgumentException(op != null ? op.toString() 
: "null");
-        }
-        return result;
+    protected Integer translate(int op) {
+        return new Integer(op);
     }
     
     //inner class used to keep track if the current thread is a worker thread.

Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=571578&r1=571577&r2=571578&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Fri Aug 31 
13:59:00 2007
@@ -2268,7 +2268,7 @@
         return bool.get();    
     }
 
-    public boolean hasOp(CometEvent.CometOperation op) {
+    public boolean hasOp(int op) {
         if ( !comet || getEvent()==null ) return false;
         return event.hasOp(op);
     }

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=571578&r1=571577&r2=571578&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Fri Aug 
31 13:59:00 2007
@@ -1233,7 +1233,7 @@
         } else if (actionCode == ActionCode.ACTION_COMET_END) {
             comet = false;
         } else if (actionCode == ActionCode.ACTION_COMET_REGISTER) {
-            int interest = getPollerInterest(param);
+            int interest = ((Integer)param).intValue();
             NioEndpoint.KeyAttachment attach = 
(NioEndpoint.KeyAttachment)socket.getAttachment(false);
             attach.setCometOps(interest);
             //notify poller if not on a tomcat thread
@@ -1248,31 +1248,14 @@
             try {
                 bool.set(inputBuffer.isReadable());
             }catch ( IOException x ) {
-                throw new RuntimeException(x);
+                if (log.isDebugEnabled()) log.debug("Unable to check 
readability on NIO socket.",x);
+                bool.set(false);
             }
         } else if (actionCode == ActionCode.ACTION_COMET_WRITEABLE) {
             MutableBoolean bool = (MutableBoolean)param;
             bool.set(outputBuffer.isWritable());
         }
 
-    }
-
-    private int getPollerInterest(Object param) throws 
IllegalArgumentException {
-        if ( param == null || (!(param instanceof PollerInterest[])) )
-            throw new IllegalArgumentException("Action parameter must be a 
PollerInterest[] object.");
-        int interest = 0;
-        PollerInterest[] piarr = (PollerInterest[])param;
-        for ( PollerInterest pi : piarr ) {
-            if (pi == PollerInterest.CALLBACK)
-                interest = interest | NioEndpoint.OP_CALLBACK;
-            else if (pi == PollerInterest.READ)
-                interest = interest | SelectionKey.OP_READ;
-            else if (pi == PollerInterest.WRITE)
-                interest = interest | SelectionKey.OP_WRITE;
-            else
-                throw new IllegalArgumentException(pi != null ? pi.toString() 
: "null");
-        }
-        return interest;
     }
 
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/PollerInterest.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/PollerInterest.java?rev=571578&r1=571577&r2=571578&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/PollerInterest.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/PollerInterest.java Fri Aug 31 
13:59:00 2007
@@ -17,10 +17,14 @@
 
 package org.apache.tomcat.util.net;
 
+import java.nio.channels.SelectionKey;
+
 /**
  * Different poller inter
  * @author fhanik
  */
-public enum PollerInterest {
-    READ, WRITE, CALLBACK;
+public class PollerInterest {
+    public static final int READ = SelectionKey.OP_READ;
+    public static final int WRITE = SelectionKey.OP_WRITE;
+    public static final int CALLBACK = NioEndpoint.OP_CALLBACK;
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to