From 3275f74ef9738a4312dea10b9c7f185db79ab2a9 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 17 Dec 2009 08:37:11 +0000 Subject: [PATCH] Fixed issue: NETTY-260 ZlibEncoder.close() and SslHandler.handshake/close() methods do not require a parameter * ZlibEncoder implements LifeCycleAwareChannelHandler to retrieve its context * ZlibEncoder.close() does not need an argument anymore --- .../codec/compression/ZlibEncoder.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/compression/ZlibEncoder.java b/src/main/java/org/jboss/netty/handler/codec/compression/ZlibEncoder.java index 19a3e34a49..9913927880 100644 --- a/src/main/java/org/jboss/netty/handler/codec/compression/ZlibEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/compression/ZlibEncoder.java @@ -27,6 +27,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.Channels; +import org.jboss.netty.channel.LifeCycleAwareChannelHandler; import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; import org.jboss.netty.util.internal.jzlib.JZlib; import org.jboss.netty.util.internal.jzlib.ZStream; @@ -40,12 +41,13 @@ import org.jboss.netty.util.internal.jzlib.ZStream; * @version $Rev$, $Date$ */ @ChannelPipelineCoverage("one") -public class ZlibEncoder extends OneToOneEncoder { +public class ZlibEncoder extends OneToOneEncoder implements LifeCycleAwareChannelHandler { private static final byte[] EMPTY_ARRAY = new byte[0]; private final ZStream z = new ZStream(); private final AtomicBoolean finished = new AtomicBoolean(); + private volatile ChannelHandlerContext ctx; /** * Creates a new zlib encoder with the default compression level ({@code 6}) @@ -161,8 +163,12 @@ public class ZlibEncoder extends OneToOneEncoder { } } - public ChannelFuture close(Channel channel) { - return finishEncode(channel.getPipeline().getContext(this), null); + public ChannelFuture close() { + ChannelHandlerContext ctx = this.ctx; + if (ctx == null) { + throw new IllegalStateException("not added to a pipeline"); + } + return finishEncode(ctx, null); } public boolean isClosed() { @@ -304,4 +310,20 @@ public class ZlibEncoder extends OneToOneEncoder { return future; } + + 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 + } }