Author: fhanik
Date: Tue May 29 03:29:25 2007
New Revision: 542479

URL: http://svn.apache.org/viewvc?view=rev&rev=542479
Log:
Added in the registration of comet interest operations
Added in PollerInterest enumeration to satisfy different socket implementations 
and to decouple org.apache.tomcat from org.apache.catalina

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

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?view=diff&rev=542479&r1=542478&r2=542479
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java Tue May 
29 03:29:25 2007
@@ -27,6 +27,7 @@
 import org.apache.catalina.CometEvent;
 import org.apache.catalina.util.StringManager;
 import org.apache.coyote.ActionCode;
+import org.apache.tomcat.util.net.PollerInterest;
 
 public class CometEventImpl implements CometEvent {
 
@@ -172,7 +173,7 @@
             for (CometEvent.CometOperation co : operations) {
                 if (!cometOperations.contains(co)) {
                     cometOperations.add(co);
-                    request.action(ActionCode.ACTION_COMET_REGISTER, co);
+                    request.action(ActionCode.ACTION_COMET_REGISTER, 
translate(co));
                 }
             }
         }
@@ -185,7 +186,7 @@
             for (CometEvent.CometOperation co : operations) {
                 if (cometOperations.contains(co)) {
                     cometOperations.remove(co);
-                    request.action(ActionCode.ACTION_COMET_UNREGISTER, co);
+                    request.action(ActionCode.ACTION_COMET_UNREGISTER, 
translate(co));
                 }
             }
         }
@@ -223,9 +224,22 @@
             throw new IllegalStateException("The operation can only be 
performed when invoked by a Tomcat worker thread.");
     }
     
+    protected PollerInterest translate(CometOperation op) {
+        if ( op == CometEvent.CometOperation.OP_READ )
+            return PollerInterest.READ;
+        else if ( op == CometEvent.CometOperation.OP_WRITE )
+            return PollerInterest.WRITE;
+        else if ( op == CometEvent.CometOperation.OP_CALLBACK )
+            return PollerInterest.CALLBACK;
+        else 
+            throw new IllegalArgumentException(op!=null?op.toString():"null");
+    }
+    
     //inner class used to keep track if the current thread is a worker thread.
     private static class WorkerThreadCheck extends ThreadLocal {
         
     }
+    
+    
 
 }

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?view=diff&rev=542479&r1=542478&r2=542479
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Tue May 
29 03:29:25 2007
@@ -53,6 +53,7 @@
 import org.apache.tomcat.util.net.NioEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.util.net.NioEndpoint.KeyAttachment;
+import org.apache.tomcat.util.net.PollerInterest;
 
 
 /**
@@ -1221,8 +1222,35 @@
             attach.setTimeout(to.longValue());
         } else if (actionCode == ActionCode.ACTION_COMET_END) {
             comet = false;
+        } else if (actionCode == ActionCode.ACTION_COMET_REGISTER) {
+            int interest = getPollerInterest(param);
+            NioEndpoint.KeyAttachment attach = 
(NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            attach.setCometOps(attach.getCometOps()|interest);
+            attach.getPoller().cometInterest(socket);
+        } else if (actionCode == ActionCode.ACTION_COMET_UNREGISTER) {
+            int interest = getPollerInterest(param);
+            NioEndpoint.KeyAttachment attach = 
(NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            attach.setCometOps(attach.getCometOps()& (~interest));
+            attach.getPoller().cometInterest(socket);
+        } else if (actionCode == ActionCode.ACTION_COMET_CONFIGURE) {
         }
 
+    }
+
+    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 pi = (PollerInterest)param;
+        if ( pi == PollerInterest.CALLBACK )
+            interest = NioEndpoint.OP_CALLBACK;
+        else if ( pi == PollerInterest.READ ) 
+            interest  = SelectionKey.OP_READ;
+        else if ( pi == PollerInterest.WRITE ) 
+            interest = SelectionKey.OP_WRITE;
+        else
+            throw new IllegalArgumentException(pi!=null?pi.toString():"null");
+        return interest;
     }
 
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?view=diff&rev=542479&r1=542478&r2=542479
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue May 29 
03:29:25 2007
@@ -103,7 +103,8 @@
      */
     public static final String SESSION_ID_KEY = 
"javax.servlet.request.ssl_session";
 
-    public static final int OP_REGISTER = -1; //register interest op
+    public static final int OP_REGISTER = 0x100; //register interest op
+    public static final int OP_CALLBACK = 0x200; //callback interest op
     
     // ----------------------------------------------------------------- Fields
 
@@ -1312,6 +1313,14 @@
             events.offer(event);
             if ( wakeupCounter.incrementAndGet() < 3 ) selector.wakeup();
         }
+        
+        public void cometInterest(NioChannel socket) {
+            throw new UnsupportedOperationException();
+        }
+        
+        public void wakeup() {
+            selector.wakeup();
+        }
 
         /**
          * Add specified socket and associated pool to the poller. The socket 
will
@@ -1648,6 +1657,8 @@
         public void access(long access) { lastAccess = access; }
         public void setComet(boolean comet) { this.comet = comet; }
         public boolean getComet() { return comet; }
+        public void setCometOps(int ops) { this.cometOps = ops; }
+        public int getCometOps() { return cometOps; }
         public boolean getCurrentAccess() { return currentAccess; }
         public void setCurrentAccess(boolean access) { currentAccess = access; 
}
         public Object getMutex() {return mutex;}
@@ -1697,6 +1708,7 @@
         protected long lastAccess = -1;
         protected boolean currentAccess = false;
         protected boolean comet = false;
+        protected int cometOps = 0;
         protected long timeout = -1;
         protected boolean error = false;
         protected NioChannel channel = null;

Added: 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?view=auto&rev=542479
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/PollerInterest.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/PollerInterest.java Tue May 29 
03:29:25 2007
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.tomcat.util.net;
+
+/**
+ * Different poller inter
+ * @author fhanik
+ */
+public enum PollerInterest {
+    READ, WRITE, CALLBACK;
+}



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

Reply via email to