ApplicationProtocolNegotiationHandler Class — netty Architecture
Architecture documentation for the ApplicationProtocolNegotiationHandler class in ApplicationProtocolNegotiationHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1["ApplicationProtocolNegotiationHandler"] cbf9a5c1_93a7_01f5_91c1_62fff442debd["ApplicationProtocolNegotiationHandler.java"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|defined in| cbf9a5c1_93a7_01f5_91c1_62fff442debd f09707da_ce36_8579_a345_83f47dda074d["ApplicationProtocolNegotiationHandler()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| f09707da_ce36_8579_a345_83f47dda074d 98a8b2fa_52d9_f364_6cc1_24e3269068a7["handlerAdded()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| 98a8b2fa_52d9_f364_6cc1_24e3269068a7 dbf27878_9dbc_e54e_786e_5b1cddf5a397["handlerRemoved()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| dbf27878_9dbc_e54e_786e_5b1cddf5a397 73fc5f5b_e081_bdd5_167a_04c620d4fdab["channelRead()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| 73fc5f5b_e081_bdd5_167a_04c620d4fdab 291c1c5b_f3f2_7e72_e7dd_25424b02cebf["fireBufferedMessages()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| 291c1c5b_f3f2_7e72_e7dd_25424b02cebf 880f358e_d7d7_b607_f597_19124ca4364e["userEventTriggered()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| 880f358e_d7d7_b607_f597_19124ca4364e 8c0db0f8_52b4_e3f9_40f5_1382ba3eb3ab["channelInactive()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| 8c0db0f8_52b4_e3f9_40f5_1382ba3eb3ab ff97ac71_5935_7324_8055_fd73efd9c995["removeSelfIfPresent()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| ff97ac71_5935_7324_8055_fd73efd9c995 e92127ac_0c6e_3476_dbcc_4f2261e55def["configurePipeline()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| e92127ac_0c6e_3476_dbcc_4f2261e55def 6e83dea8_36d9_a481_62de_f87541b25143["handshakeFailure()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| 6e83dea8_36d9_a481_62de_f87541b25143 6d5c26f8_b0b4_a613_e7c9_27748639d0b3["exceptionCaught()"] 0233e67b_aa3b_d75b_4c03_f8c1ecbc9db1 -->|method| 6d5c26f8_b0b4_a613_e7c9_27748639d0b3
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java lines 67–210
public abstract class ApplicationProtocolNegotiationHandler extends ChannelInboundHandlerAdapter {
private static final InternalLogger logger =
InternalLoggerFactory.getInstance(ApplicationProtocolNegotiationHandler.class);
private final String fallbackProtocol;
private final RecyclableArrayList bufferedMessages = RecyclableArrayList.newInstance();
private ChannelHandlerContext ctx;
private boolean sslHandlerChecked;
/**
* Creates a new instance with the specified fallback protocol name.
*
* @param fallbackProtocol the name of the protocol to use when
* ALPN/NPN negotiation fails or the client does not support ALPN/NPN
*/
protected ApplicationProtocolNegotiationHandler(String fallbackProtocol) {
this.fallbackProtocol = ObjectUtil.checkNotNull(fallbackProtocol, "fallbackProtocol");
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
this.ctx = ctx;
super.handlerAdded(ctx);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
fireBufferedMessages();
bufferedMessages.recycle();
super.handlerRemoved(ctx);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
// Let's buffer all data until this handler will be removed from the pipeline.
bufferedMessages.add(msg);
if (!sslHandlerChecked) {
sslHandlerChecked = true;
if (ctx.pipeline().get(SslHandler.class) == null) {
// Just remove ourself if there is no SslHandler in the pipeline and so we would otherwise
// buffer forever.
removeSelfIfPresent(ctx);
}
}
}
/**
* Process all backlog into pipeline from List.
*/
private void fireBufferedMessages() {
if (!bufferedMessages.isEmpty()) {
for (int i = 0; i < bufferedMessages.size(); i++) {
ctx.fireChannelRead(bufferedMessages.get(i));
}
ctx.fireChannelReadComplete();
bufferedMessages.clear();
}
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof SslHandshakeCompletionEvent) {
SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt;
try {
if (handshakeEvent.isSuccess()) {
SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
if (sslHandler == null) {
throw new IllegalStateException("cannot find an SslHandler in the pipeline (required for "
+ "application-level protocol negotiation)");
}
String protocol = sslHandler.applicationProtocol();
configurePipeline(ctx, protocol != null ? protocol : fallbackProtocol);
} else {
// if the event is not produced because of an successful handshake we will receive the same
// exception in exceptionCaught(...) and handle it there. This will allow us more fine-grained
// control over which exception we propagate down the ChannelPipeline.
//
// See https://github.com/netty/netty/issues/10342
}
} catch (Throwable cause) {
Source
Frequently Asked Questions
What is the ApplicationProtocolNegotiationHandler class?
ApplicationProtocolNegotiationHandler is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java.
Where is ApplicationProtocolNegotiationHandler defined?
ApplicationProtocolNegotiationHandler is defined in handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java at line 67.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free