public abstract class ApplicationProtocolNegotiationHandler extends ChannelInboundHandlerAdapter
ChannelPipeline
depending on the application-level protocol negotiation result of
SslHandler
. For example, you could configure your HTTP pipeline depending on the result of ALPN:
public class MyInitializer extendsChannelInitializer
<Channel
> { private finalSslContext
sslCtx; public MyInitializer(SslContext
sslCtx) { this.sslCtx = sslCtx; } protected void initChannel(Channel
ch) {ChannelPipeline
p = ch.pipeline(); p.addLast(sslCtx.newHandler(...)); // AddsSslHandler
p.addLast(new MyNegotiationHandler()); } } public class MyNegotiationHandler extendsApplicationProtocolNegotiationHandler
{ public MyNegotiationHandler() { super(ApplicationProtocolNames
.HTTP_1_1); } protected void configurePipeline(ChannelHandlerContext
ctx, String protocol) { if (ApplicationProtocolNames
.HTTP_2.equals(protocol) { configureHttp2(ctx); } else if (ApplicationProtocolNames
.HTTP_1_1.equals(protocol)) { configureHttp1(ctx); } else { throw new IllegalStateException("unknown protocol: " + protocol); } } }
ChannelHandler.Sharable
限定符 | 构造器和说明 |
---|---|
protected |
ApplicationProtocolNegotiationHandler(java.lang.String fallbackProtocol)
Creates a new instance with the specified fallback protocol name.
|
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged
ensureNotSharable, isSharable
protected ApplicationProtocolNegotiationHandler(java.lang.String fallbackProtocol)
fallbackProtocol
- the name of the protocol to use when
ALPN/NPN negotiation fails or the client does not support ALPN/NPNpublic void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerAdded
在接口中 ChannelHandler
handlerAdded
在类中 ChannelHandlerAdapter
java.lang.Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved
在接口中 ChannelHandler
handlerRemoved
在类中 ChannelHandlerAdapter
java.lang.Exception
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
在接口中 ChannelInboundHandler
channelRead
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireUserEventTriggered(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.userEventTriggered
在接口中 ChannelInboundHandler
userEventTriggered
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelInactive()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelInactive
在接口中 ChannelInboundHandler
channelInactive
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
protected abstract void configurePipeline(ChannelHandlerContext ctx, java.lang.String protocol) throws java.lang.Exception
protocol
- the name of the negotiated application-level protocol, or
the fallback protocol name specified in the constructor call if negotiation failed or the client
isn't aware of ALPN/NPN extensionjava.lang.Exception
protected void handshakeFailure(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
java.lang.Exception
public void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireExceptionCaught(Throwable)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.exceptionCaught
在接口中 ChannelHandler
exceptionCaught
在接口中 ChannelInboundHandler
exceptionCaught
在类中 ChannelInboundHandlerAdapter
java.lang.Exception