From 146f5edfde23778049eaa1bd59311beedd9e7624 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Sat, 26 May 2012 22:30:48 +0200 Subject: [PATCH] Updated to NPN API version 1.1.0, calling NextProtoNego.remove(), instead of using AtomicReferences to clear the SSLEngine references. --- jetty-spdy/pom.xml | 2 +- .../org/eclipse/jetty/spdy/SPDYClient.java | 19 ++++++------------- .../jetty/spdy/SPDYServerConnector.java | 11 +++-------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/jetty-spdy/pom.xml b/jetty-spdy/pom.xml index d40c65db93e..75b43fe7462 100644 --- a/jetty-spdy/pom.xml +++ b/jetty-spdy/pom.xml @@ -13,7 +13,7 @@ Jetty :: SPDY :: Parent - 1.0.0.v20120402 + 1.1.0.v20120525 diff --git a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java index 6f04c5bb3c1..f1cf9374690 100644 --- a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java +++ b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYClient.java @@ -38,7 +38,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.atomic.AtomicReference; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; @@ -314,7 +313,7 @@ public class SPDYClient } @Override - public AsyncConnection newConnection(final SocketChannel channel, AsyncEndPoint endPoint, Object attachment) + public AsyncConnection newConnection(final SocketChannel channel, AsyncEndPoint endPoint, final Object attachment) { SessionPromise sessionPromise = (SessionPromise)attachment; final SPDYClient client = sessionPromise.client; @@ -323,22 +322,18 @@ public class SPDYClient { if (sslContextFactory != null) { - final AtomicReference sslEndPointRef = new AtomicReference<>(); - final AtomicReference attachmentRef = new AtomicReference<>(attachment); - SSLEngine engine = client.newSSLEngine(sslContextFactory, channel); + final SSLEngine engine = client.newSSLEngine(sslContextFactory, channel); SslConnection sslConnection = new SslConnection(engine, endPoint) { @Override public void onClose() { - sslEndPointRef.set(null); - attachmentRef.set(null); + NextProtoNego.remove(engine); super.onClose(); } }; endPoint.setConnection(sslConnection); - AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint(); - sslEndPointRef.set(sslEndPoint); + final AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint(); // Instances of the ClientProvider inner class strong reference the // SslEndPoint (via lexical scoping), which strong references the SSLEngine. @@ -361,8 +356,7 @@ public class SPDYClient { // Server does not support NPN, but this is a SPDY client, so hardcode SPDY ClientSPDYAsyncConnectionFactory connectionFactory = new ClientSPDYAsyncConnectionFactory(); - AsyncEndPoint sslEndPoint = sslEndPointRef.get(); - AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachmentRef.get()); + AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachment); sslEndPoint.setConnection(connection); } @@ -374,8 +368,7 @@ public class SPDYClient return null; AsyncConnectionFactory connectionFactory = client.getAsyncConnectionFactory(protocol); - AsyncEndPoint sslEndPoint = sslEndPointRef.get(); - AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachmentRef.get()); + AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachment); sslEndPoint.setConnection(connection); return protocol; } diff --git a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java index 1e431e2eebf..dcacb8d39d1 100644 --- a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java +++ b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java @@ -29,7 +29,6 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; @@ -177,20 +176,18 @@ public class SPDYServerConnector extends SelectChannelConnector { if (sslContextFactory != null) { - SSLEngine engine = newSSLEngine(sslContextFactory, channel); - final AtomicReference sslEndPointRef = new AtomicReference<>(); + final SSLEngine engine = newSSLEngine(sslContextFactory, channel); SslConnection sslConnection = new SslConnection(engine, endPoint) { @Override public void onClose() { - sslEndPointRef.set(null); + NextProtoNego.remove(engine); super.onClose(); } }; endPoint.setConnection(sslConnection); - AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint(); - sslEndPointRef.set(sslEndPoint); + final AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint(); // Instances of the ServerProvider inner class strong reference the // SslEndPoint (via lexical scoping), which strong references the SSLEngine. @@ -206,7 +203,6 @@ public class SPDYServerConnector extends SelectChannelConnector public void unsupported() { AsyncConnectionFactory connectionFactory = getDefaultAsyncConnectionFactory(); - AsyncEndPoint sslEndPoint = sslEndPointRef.get(); AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, SPDYServerConnector.this); sslEndPoint.setConnection(connection); } @@ -221,7 +217,6 @@ public class SPDYServerConnector extends SelectChannelConnector public void protocolSelected(String protocol) { AsyncConnectionFactory connectionFactory = getAsyncConnectionFactory(protocol); - AsyncEndPoint sslEndPoint = sslEndPointRef.get(); AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, SPDYServerConnector.this); sslEndPoint.setConnection(connection); }