Use finer grained type parameter in SPDY

This commit is contained in:
Trustin Lee 2013-02-08 17:57:20 +09:00
parent 01e65a01c7
commit ee189d1da7
7 changed files with 31 additions and 20 deletions

View File

@ -18,6 +18,6 @@ package io.netty.handler.codec.spdy;
/**
* A SPDY Protocol Control Frame
*/
public interface SpdyControlFrame {
public interface SpdyControlFrame extends SpdyDataOrControlFrame {
// Tag interface
}

View File

@ -22,7 +22,7 @@ import io.netty.buffer.Unpooled;
/**
* A SPDY Protocol Data Frame
*/
public interface SpdyDataFrame extends ByteBufHolder, SpdyStreamFrame {
public interface SpdyDataFrame extends ByteBufHolder, SpdyStreamFrame, SpdyDataOrControlFrame {
@Override
SpdyDataFrame setStreamId(int streamID);

View File

@ -0,0 +1,21 @@
/*
* Copyright 2013 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;
public interface SpdyDataOrControlFrame {
// Tag interface
}

View File

@ -31,7 +31,7 @@ import io.netty.channel.CombinedChannelDuplexHandler;
*/
public final class SpdyFrameCodec
extends CombinedChannelDuplexHandler
implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<Object> {
implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<SpdyDataOrControlFrame> {
/**
* Creates a new instance with the specified {@code version} and
@ -79,7 +79,7 @@ public final class SpdyFrameCodec
}
@Override
public MessageBuf<Object> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
public MessageBuf<SpdyDataOrControlFrame> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
return encoder().newOutboundBuffer(ctx);
}

View File

@ -31,7 +31,7 @@ import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
/**
* Encodes a SPDY Data or Control Frame into a {@link ByteBuf}.
*/
public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
public class SpdyFrameEncoder extends MessageToByteEncoder<SpdyDataOrControlFrame> {
private final int version;
private volatile boolean finished;
@ -59,11 +59,6 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
version, compressionLevel, windowBits, memLevel);
}
@Override
public boolean acceptOutboundMessage(Object msg) throws Exception {
return msg instanceof SpdyDataFrame || msg instanceof SpdyControlFrame;
}
@Override
public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
ctx.channel().closeFuture().addListener(new ChannelFutureListener() {
@ -81,7 +76,7 @@ public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
}
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
protected void encode(ChannelHandlerContext ctx, SpdyDataOrControlFrame msg, ByteBuf out) throws Exception {
if (msg instanceof SpdyDataFrame) {
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;

View File

@ -30,7 +30,7 @@ import io.netty.handler.codec.http.HttpObject;
*/
public final class SpdyHttpCodec
extends CombinedChannelDuplexHandler
implements ChannelInboundMessageHandler<Object>, ChannelOutboundMessageHandler<HttpObject> {
implements ChannelInboundMessageHandler<SpdyDataOrControlFrame>, ChannelOutboundMessageHandler<HttpObject> {
/**
* Creates a new instance with the specified decoder options.
@ -48,7 +48,7 @@ public final class SpdyHttpCodec
}
@Override
public MessageBuf<Object> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
public MessageBuf<SpdyDataOrControlFrame> newInboundBuffer(ChannelHandlerContext ctx) throws Exception {
return decoder().newInboundBuffer(ctx);
}

View File

@ -37,7 +37,7 @@ import java.util.Map;
* Decodes {@link SpdySynStreamFrame}s, {@link SpdySynReplyFrame}s,
* and {@link SpdyDataFrame}s into {@link FullHttpRequest}s and {@link FullHttpResponse}s.
*/
public class SpdyHttpDecoder extends MessageToMessageDecoder<Object> {
public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyDataOrControlFrame> {
private final int spdyVersion;
private final int maxContentLength;
@ -65,12 +65,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<Object> {
}
@Override
public boolean acceptInboundMessage(Object msg) throws Exception {
return msg instanceof SpdyDataFrame || msg instanceof SpdyControlFrame;
}
@Override
protected Object decode(ChannelHandlerContext ctx, Object msg) throws Exception {
protected Object decode(ChannelHandlerContext ctx, SpdyDataOrControlFrame msg) throws Exception {
if (msg instanceof SpdySynStreamFrame) {
// HTTP requests/responses are mapped one-to-one to SPDY streams.