Updated to NPN API version 1.1.0, calling NextProtoNego.remove(), instead of using AtomicReferences to clear the SSLEngine references.

This commit is contained in:
Simone Bordet 2012-05-26 22:30:48 +02:00
parent bd4c93e441
commit 146f5edfde
3 changed files with 10 additions and 22 deletions

View File

@ -13,7 +13,7 @@
<name>Jetty :: SPDY :: Parent</name> <name>Jetty :: SPDY :: Parent</name>
<properties> <properties>
<npn.version>1.0.0.v20120402</npn.version> <npn.version>1.1.0.v20120525</npn.version>
</properties> </properties>
<modules> <modules>

View File

@ -38,7 +38,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
@ -314,7 +313,7 @@ public class SPDYClient
} }
@Override @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; SessionPromise sessionPromise = (SessionPromise)attachment;
final SPDYClient client = sessionPromise.client; final SPDYClient client = sessionPromise.client;
@ -323,22 +322,18 @@ public class SPDYClient
{ {
if (sslContextFactory != null) if (sslContextFactory != null)
{ {
final AtomicReference<AsyncEndPoint> sslEndPointRef = new AtomicReference<>(); final SSLEngine engine = client.newSSLEngine(sslContextFactory, channel);
final AtomicReference<Object> attachmentRef = new AtomicReference<>(attachment);
SSLEngine engine = client.newSSLEngine(sslContextFactory, channel);
SslConnection sslConnection = new SslConnection(engine, endPoint) SslConnection sslConnection = new SslConnection(engine, endPoint)
{ {
@Override @Override
public void onClose() public void onClose()
{ {
sslEndPointRef.set(null); NextProtoNego.remove(engine);
attachmentRef.set(null);
super.onClose(); super.onClose();
} }
}; };
endPoint.setConnection(sslConnection); endPoint.setConnection(sslConnection);
AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint(); final AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint();
sslEndPointRef.set(sslEndPoint);
// Instances of the ClientProvider inner class strong reference the // Instances of the ClientProvider inner class strong reference the
// SslEndPoint (via lexical scoping), which strong references the SSLEngine. // 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 // Server does not support NPN, but this is a SPDY client, so hardcode SPDY
ClientSPDYAsyncConnectionFactory connectionFactory = new ClientSPDYAsyncConnectionFactory(); ClientSPDYAsyncConnectionFactory connectionFactory = new ClientSPDYAsyncConnectionFactory();
AsyncEndPoint sslEndPoint = sslEndPointRef.get(); AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachment);
AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachmentRef.get());
sslEndPoint.setConnection(connection); sslEndPoint.setConnection(connection);
} }
@ -374,8 +368,7 @@ public class SPDYClient
return null; return null;
AsyncConnectionFactory connectionFactory = client.getAsyncConnectionFactory(protocol); AsyncConnectionFactory connectionFactory = client.getAsyncConnectionFactory(protocol);
AsyncEndPoint sslEndPoint = sslEndPointRef.get(); AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachment);
AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, attachmentRef.get());
sslEndPoint.setConnection(connection); sslEndPoint.setConnection(connection);
return protocol; return protocol;
} }

View File

@ -29,7 +29,6 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
@ -177,20 +176,18 @@ public class SPDYServerConnector extends SelectChannelConnector
{ {
if (sslContextFactory != null) if (sslContextFactory != null)
{ {
SSLEngine engine = newSSLEngine(sslContextFactory, channel); final SSLEngine engine = newSSLEngine(sslContextFactory, channel);
final AtomicReference<AsyncEndPoint> sslEndPointRef = new AtomicReference<>();
SslConnection sslConnection = new SslConnection(engine, endPoint) SslConnection sslConnection = new SslConnection(engine, endPoint)
{ {
@Override @Override
public void onClose() public void onClose()
{ {
sslEndPointRef.set(null); NextProtoNego.remove(engine);
super.onClose(); super.onClose();
} }
}; };
endPoint.setConnection(sslConnection); endPoint.setConnection(sslConnection);
AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint(); final AsyncEndPoint sslEndPoint = sslConnection.getSslEndPoint();
sslEndPointRef.set(sslEndPoint);
// Instances of the ServerProvider inner class strong reference the // Instances of the ServerProvider inner class strong reference the
// SslEndPoint (via lexical scoping), which strong references the SSLEngine. // SslEndPoint (via lexical scoping), which strong references the SSLEngine.
@ -206,7 +203,6 @@ public class SPDYServerConnector extends SelectChannelConnector
public void unsupported() public void unsupported()
{ {
AsyncConnectionFactory connectionFactory = getDefaultAsyncConnectionFactory(); AsyncConnectionFactory connectionFactory = getDefaultAsyncConnectionFactory();
AsyncEndPoint sslEndPoint = sslEndPointRef.get();
AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, SPDYServerConnector.this); AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, SPDYServerConnector.this);
sslEndPoint.setConnection(connection); sslEndPoint.setConnection(connection);
} }
@ -221,7 +217,6 @@ public class SPDYServerConnector extends SelectChannelConnector
public void protocolSelected(String protocol) public void protocolSelected(String protocol)
{ {
AsyncConnectionFactory connectionFactory = getAsyncConnectionFactory(protocol); AsyncConnectionFactory connectionFactory = getAsyncConnectionFactory(protocol);
AsyncEndPoint sslEndPoint = sslEndPointRef.get();
AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, SPDYServerConnector.this); AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, SPDYServerConnector.this);
sslEndPoint.setConnection(connection); sslEndPoint.setConnection(connection);
} }