From 469cb8b80be6a44ea66b723b7ded0cca327aef81 Mon Sep 17 00:00:00 2001 From: norman Date: Fri, 2 Mar 2012 07:37:43 +0100 Subject: [PATCH 1/6] Remove Twitter license. See #202 --- .../netty/handler/codec/spdy/SpdyZlibDecoder.java | 15 --------------- .../netty/handler/codec/spdy/SpdyZlibEncoder.java | 15 --------------- 2 files changed, 30 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java index 33f2ed4b84..7ae7a260b1 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java @@ -13,21 +13,6 @@ * License for the specific language governing permissions and limitations * under the License. */ -/* - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package io.netty.handler.codec.spdy; import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibEncoder.java index b455a64531..a57b9b7bf0 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibEncoder.java @@ -13,21 +13,6 @@ * License for the specific language governing permissions and limitations * under the License. */ -/* - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package io.netty.handler.codec.spdy; import java.util.zip.Deflater; From 985fc448dc52b0878acdce45edbc8043a95707d4 Mon Sep 17 00:00:00 2001 From: norman Date: Fri, 2 Mar 2012 07:38:05 +0100 Subject: [PATCH 2/6] Remove unused imports --- .../main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java index d202f19bbf..5d0c5140e9 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java @@ -19,8 +19,6 @@ import io.netty.buffer.ChannelBuffer; import io.netty.buffer.ChannelBuffers; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.compression.ZlibDecoder; -import io.netty.handler.codec.embedder.DecoderEmbedder; import io.netty.handler.codec.frame.FrameDecoder; import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; From 8eec6938834c38c9dd51a43df3adc2b029872d3f Mon Sep 17 00:00:00 2001 From: norman Date: Fri, 2 Mar 2012 07:46:56 +0100 Subject: [PATCH 3/6] Remove twitter license headers. See #202 --- .../handler/codec/spdy/SpdyJZlibDecoder.java | 15 --------------- .../handler/codec/spdy/SpdyJZlibEncoder.java | 15 --------------- 2 files changed, 30 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibDecoder.java index 38bd2aaee0..30063d5285 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibDecoder.java @@ -13,21 +13,6 @@ * License for the specific language governing permissions and limitations * under the License. */ -/* - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package io.netty.handler.codec.spdy; import io.netty.buffer.ChannelBuffer; diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibEncoder.java index b3ea627c1f..c76d08b13b 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyJZlibEncoder.java @@ -13,21 +13,6 @@ * License for the specific language governing permissions and limitations * under the License. */ -/* - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package io.netty.handler.codec.spdy; import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; From 529156028326efe51338990bce57666895f31a1b Mon Sep 17 00:00:00 2001 From: norman Date: Fri, 2 Mar 2012 08:03:20 +0100 Subject: [PATCH 4/6] Remove left-over of refactoring. See #211 --- .../handler/codec/spdy/SpdyZlibDecoder.java | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java deleted file mode 100644 index 7ae7a260b1..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyZlibDecoder.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.handler.codec.spdy; - -import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; - -import io.netty.buffer.ChannelBuffer; -import io.netty.handler.codec.compression.CompressionException; -import io.netty.util.internal.jzlib.JZlib; -import io.netty.util.internal.jzlib.ZStream; - -class SpdyZlibDecoder { - - private final byte[] out = new byte[8192]; - private final ZStream z = new ZStream(); - - public SpdyZlibDecoder() { - int resultCode; - resultCode = z.inflateInit(JZlib.W_ZLIB); - if (resultCode != JZlib.Z_OK) { - throw new CompressionException("ZStream initialization failure"); - } - z.next_out = out; - } - - public void setInput(ChannelBuffer compressed) { - byte[] in = new byte[compressed.readableBytes()]; - compressed.readBytes(in); - z.next_in = in; - z.next_in_index = 0; - z.avail_in = in.length; - } - - public void decode(ChannelBuffer decompressed) { - z.next_out_index = 0; - z.avail_out = out.length; - - int resultCode = z.inflate(JZlib.Z_SYNC_FLUSH); - - if (resultCode == JZlib.Z_NEED_DICT) { - resultCode = z.inflateSetDictionary(SPDY_DICT, SPDY_DICT.length); - if (resultCode != JZlib.Z_OK) { - throw new CompressionException("ZStream dictionary failure"); - } - z.inflate(JZlib.Z_SYNC_FLUSH); - } - - if (z.next_out_index > 0) { - decompressed.writeBytes(out, 0, z.next_out_index); - } - } -} From 0c46db317a0310923e5112577b759db9bdd844fb Mon Sep 17 00:00:00 2001 From: norman Date: Fri, 2 Mar 2012 09:28:43 +0100 Subject: [PATCH 5/6] Allow to handle only downstream events via the ExecutionHandler. See #173 --- .../handler/execution/ExecutionHandler.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java b/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java index de2f435666..8ccc3278e9 100644 --- a/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java +++ b/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java @@ -110,25 +110,40 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre private final Executor executor; private final boolean handleDownstream; + private final boolean handleUpstream; + + /** + * Creates a new instance with the specified {@link Executor} which only handles upstream events. + * Specify an {@link OrderedMemoryAwareThreadPoolExecutor} if unsure. + */ + public ExecutionHandler(Executor executor) { + this(executor, false, true); + } + + /** + * Use {@link #ExecutionHandler(Executor, boolean, boolean)} + * + * {@link Deprecated} + */ + @Deprecated + public ExecutionHandler(Executor executor, boolean handleDownstream) { + this(executor, handleDownstream, true); + } /** * Creates a new instance with the specified {@link Executor}. * Specify an {@link OrderedMemoryAwareThreadPoolExecutor} if unsure. */ - public ExecutionHandler(Executor executor) { - this(executor, false); - } - - /** - * Creates a new instance with the specified {@link Executor}. - * Specify an {@link OrderedMemoryAwareThreadPoolExecutor} if unsure. - */ - public ExecutionHandler(Executor executor, boolean handleDownstream) { + public ExecutionHandler(Executor executor, boolean handleDownstream, boolean handleUpstream) { if (executor == null) { throw new NullPointerException("executor"); } + if (!handleDownstream && !handleUpstream) { + throw new IllegalArgumentException("You must handle at least handle one event type"); + } this.executor = executor; this.handleDownstream = handleDownstream; + this.handleUpstream = handleUpstream; } /** @@ -154,7 +169,11 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre @Override public void handleUpstream( ChannelHandlerContext context, ChannelEvent e) throws Exception { - executor.execute(new ChannelUpstreamEventRunnable(context, e)); + if (handleUpstream) { + executor.execute(new ChannelUpstreamEventRunnable(context, e)); + } else { + context.sendUpstream(e); + } } @Override From a071759575289fb85cdc2a07b116c2a3deea286b Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 2 Mar 2012 09:35:16 +0100 Subject: [PATCH 6/6] Fix formatting --- .../main/java/io/netty/handler/execution/ExecutionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java b/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java index 8ccc3278e9..391a59b797 100644 --- a/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java +++ b/handler/src/main/java/io/netty/handler/execution/ExecutionHandler.java @@ -110,7 +110,7 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre private final Executor executor; private final boolean handleDownstream; - private final boolean handleUpstream; + private final boolean handleUpstream; /** * Creates a new instance with the specified {@link Executor} which only handles upstream events.