tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject svn commit: r1292131 - in /tomcat/trunk/java/org/apache: coyote/http11/Http11AprProtocol.java tomcat/util/net/AprEndpoint.java
Date Wed, 22 Feb 2012 05:37:34 GMT
Author: costin
Date: Wed Feb 22 05:37:34 2012
New Revision: 1292131

URL: http://svn.apache.org/viewvc?rev=1292131&view=rev
Log:
Add a hook to allow handling NPN extensions in the apr protocol ( the extension is not available
in java ).
I think this is the smallest change to allow plugging in spdy.


Modified:
    tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java?rev=1292131&r1=1292130&r2=1292131&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java Wed Feb 22 05:37:34
2012
@@ -19,6 +19,7 @@ package org.apache.coyote.http11;
 import java.io.IOException;
 
 import org.apache.coyote.AbstractProtocol;
+import org.apache.coyote.Adapter;
 import org.apache.coyote.Processor;
 import org.apache.coyote.http11.upgrade.UpgradeAprProcessor;
 import org.apache.coyote.http11.upgrade.UpgradeInbound;
@@ -26,6 +27,8 @@ import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.net.AbstractEndpoint;
 import org.apache.tomcat.util.net.AprEndpoint;
+import org.apache.tomcat.util.net.SocketStatus;
+import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.net.AprEndpoint.Handler;
 import org.apache.tomcat.util.net.SocketWrapper;
 
@@ -42,6 +45,15 @@ public class Http11AprProtocol extends A
 
     private static final Log log = LogFactory.getLog(Http11AprProtocol.class);
 
+    /** 
+     * Interface specific for protocols that negotiate at NPN level, like 
+     * SPDY. This is only available for APR, will replace the HTTP framing.
+     */
+    public static interface NpnHandler {
+        SocketState process(SocketWrapper<Long> socket, SocketStatus status,
+                Http11AprProtocol proto, AbstractEndpoint endpoint);
+        public void init(final AbstractEndpoint ep, long sslContext, Adapter adapter);
+    }
 
     @Override
     protected Log getLog() { return log; }
@@ -63,6 +75,7 @@ public class Http11AprProtocol extends A
     }
 
     private final Http11ConnectionHandler cHandler;
+    private NpnHandler npnHandler;
 
     public boolean getUseSendfile() { return ((AprEndpoint)endpoint).getUseSendfile(); }
     public void setUseSendfile(boolean useSendfile) { ((AprEndpoint)endpoint).setUseSendfile(useSendfile);
}
@@ -171,6 +184,16 @@ public class Http11AprProtocol extends A
     public int getSSLVerifyDepth() { return ((AprEndpoint)endpoint).getSSLVerifyDepth();
}
     public void setSSLVerifyDepth(int SSLVerifyDepth) { ((AprEndpoint)endpoint).setSSLVerifyDepth(SSLVerifyDepth);
}
 
+    // TODO: map of protocols
+    public void setNpnHandler(String impl) {
+        try {
+            Class c = Class.forName(impl);
+            npnHandler = (NpnHandler) c.newInstance();
+        } catch (Exception ex) {
+            getLog().warn("Failed to init light protocol " + impl, ex);
+        }
+    }
+    
     // ----------------------------------------------------- JMX related methods
 
     @Override
@@ -178,7 +201,16 @@ public class Http11AprProtocol extends A
         return ("http-apr");
     }
 
-
+    
+    @Override
+    public void start() throws Exception {
+        super.start();
+        if (npnHandler != null) {
+            long sslCtx = ((AprEndpoint) endpoint).getJniSslContext();
+            npnHandler.init(endpoint, sslCtx, adapter);
+        }
+    }
+    
     // --------------------  Connection handler --------------------
 
     protected static class Http11ConnectionHandler
@@ -225,6 +257,29 @@ public class Http11AprProtocol extends A
                         socket.getSocket().longValue(), true);
             }
         }
+        
+        @Override
+        public SocketState process(SocketWrapper<Long> socket,
+                SocketStatus status) {
+            if (proto.npnHandler != null) {
+                Processor<Long> processor = null;
+                if (status == SocketStatus.OPEN) {
+                    processor = connections.get(socket.getSocket());
+                   
+                }
+                if (processor == null) {
+                    // if not null - this is a former comet request, handled by http11
+                    SocketState socketState = proto.npnHandler.process(socket, status,
+                            proto, proto.endpoint);
+                    // handled by npn protocol.
+                    if (socketState == SocketState.CLOSED ||
+                            socketState == SocketState.LONG) {
+                        return socketState;
+                    }
+                }
+            }
+            return super.process(socket, status);
+        }
 
         @Override
         protected void initSsl(SocketWrapper<Long> socket,

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1292131&r1=1292130&r2=1292131&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Wed Feb 22 05:37:34 2012
@@ -578,6 +578,9 @@ public class AprEndpoint extends Abstrac
         }
     }
 
+    public long getJniSslContext() {
+        return sslContext;
+    }
 
     /**
      * Start the APR endpoint, creating acceptor, poller and sendfile threads.
@@ -811,9 +814,9 @@ public class AprEndpoint extends Abstrac
         }
     }
 
-
     /**
-     * Process given socket.
+     * Process given socket. This is called when the socket has been 
+     * accepted.
      */
     protected boolean processSocketWithOptions(long socket) {
         try {
@@ -838,7 +841,8 @@ public class AprEndpoint extends Abstrac
 
 
     /**
-     * Process given socket.
+     * Process given socket. Called in non-comet mode, typically keep alive
+     * or upgraded protocol.
      */
     protected boolean processSocket(long socket) {
         try {
@@ -1209,6 +1213,7 @@ public class AprEndpoint extends Abstrac
                 addSocket[addCount] = socket;
                 addSocketKeepAlive[addCount] = keepAlive;
                 addCount++;
+                // TODO: interrupt poll ?
                 this.notify();
             }
         }
@@ -1729,6 +1734,8 @@ public class AprEndpoint extends Abstrac
      * This class is the equivalent of the Worker, but will simply use in an
      * external Executor thread pool. This will also set the socket options
      * and do the handshake.
+     * 
+     * This is called after an accept().
      */
     protected class SocketWithOptionsProcessor implements Runnable {
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message