Fixed issue: NETTY-260 ZlibEncoder.close() and SslHandler.handshake/close() methods do not require a parameter

* SslHandler implements LifeCycleAwareChannelHandler to retrieve its context
* SslHandler.handshake() and close() do not need an argument anymore
* Deprecated the old methods
This commit is contained in:
Trustin Lee 2009-12-17 08:44:38 +00:00
parent 3275f74ef9
commit 578def7a9b
5 changed files with 46 additions and 11 deletions

View File

@ -183,7 +183,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
SslHandler sslHandler = new SslHandler(engine);
realChannel.getPipeline().addFirst("ssl", sslHandler);
sslHandshakeFuture = sslHandler.handshake(realChannel);
sslHandshakeFuture = sslHandler.handshake();
}
// Send the HTTP request.

View File

@ -58,7 +58,7 @@ public class SecureChatClientHandler extends SimpleChannelUpstreamHandler {
SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
// Begin handshake.
sslHandler.handshake(e.getChannel());
sslHandler.handshake();
}
@Override

View File

@ -69,7 +69,7 @@ public class SecureChatServerHandler extends SimpleChannelUpstreamHandler {
final SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
// Get notified when SSL handshake is done.
ChannelFuture handshakeFuture = sslHandler.handshake(e.getChannel());
ChannelFuture handshakeFuture = sslHandler.handshake();
handshakeFuture.addListener(new Greeter(sslHandler));
}

View File

@ -45,6 +45,7 @@ import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.DownstreamMessageEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.LifeCycleAwareChannelHandler;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
import org.jboss.netty.logging.InternalLogger;
@ -130,7 +131,9 @@ import org.jboss.netty.util.internal.ImmediateExecutor;
* @apiviz.landmark
* @apiviz.uses org.jboss.netty.handler.ssl.SslBufferPool
*/
public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler {
public class SslHandler extends FrameDecoder
implements ChannelDownstreamHandler,
LifeCycleAwareChannelHandler {
private static final InternalLogger logger =
InternalLoggerFactory.getInstance(SslHandler.class);
@ -154,6 +157,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
return defaultBufferPool;
}
private volatile ChannelHandlerContext ctx;
private final SSLEngine engine;
private final SslBufferPool bufferPool;
private final Executor delegatedTaskExecutor;
@ -305,7 +309,9 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
* @return a {@link ChannelFuture} which is notified when the handshake
* succeeds or fails.
*/
public ChannelFuture handshake(Channel channel) {
public ChannelFuture handshake() {
ChannelHandlerContext ctx = this.ctx;
Channel channel = ctx.getChannel();
ChannelFuture handshakeFuture;
synchronized (handshakeLock) {
if (handshaking) {
@ -323,20 +329,29 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
}
try {
wrapNonAppData(context(channel), channel);
wrapNonAppData(ctx, channel);
} catch (SSLException e) {
handshakeFuture.setFailure(e);
}
return handshakeFuture;
}
/**
* @deprecated Use {@link #handshake()} instead.
*/
@Deprecated
public ChannelFuture handshake(@SuppressWarnings("unused") Channel channel) {
return handshake();
}
/**
* Sends an SSL {@code close_notify} message to the specified channel and
* destroys the underlying {@link SSLEngine}.
*/
public ChannelFuture close(Channel channel) {
public ChannelFuture close() {
ChannelHandlerContext ctx = this.ctx;
Channel channel = ctx.getChannel();
try {
ChannelHandlerContext ctx = context(channel);
engine.closeOutbound();
return wrapNonAppData(ctx, channel);
} catch (SSLException e) {
@ -344,8 +359,12 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
}
}
private ChannelHandlerContext context(Channel channel) {
return channel.getPipeline().getContext(this);
/**
* @deprecated Use {@link #close()} instead.
*/
@Deprecated
public ChannelFuture close(@SuppressWarnings("unused") Channel channel) {
return close();
}
public void handleDownstream(
@ -928,4 +947,20 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
}
}
}
public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
this.ctx = ctx;
}
public void afterAdd(ChannelHandlerContext ctx) throws Exception {
// Unused
}
public void beforeRemove(ChannelHandlerContext ctx) throws Exception {
// Unused
}
public void afterRemove(ChannelHandlerContext ctx) throws Exception {
// Unused
}
}

View File

@ -130,7 +130,7 @@ public abstract class AbstractSocketSslEchoTest {
assertTrue(ccf.isSuccess());
Channel cc = ccf.getChannel();
ChannelFuture hf = cc.getPipeline().get(SslHandler.class).handshake(cc);
ChannelFuture hf = cc.getPipeline().get(SslHandler.class).handshake();
hf.awaitUninterruptibly();
if (!hf.isSuccess()) {
logger.error("Handshake failed", hf.getCause());