Home / Class/ AlpnSelector Class — netty Architecture

AlpnSelector Class — netty Architecture

Architecture documentation for the AlpnSelector class in JdkAlpnSslEngine.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  301bb277_7cd2_153d_3f93_7fceaab2afee["AlpnSelector"]
  69cf3d4a_9aaa_8f16_811c_d0f7b92e1125["JdkAlpnSslEngine.java"]
  301bb277_7cd2_153d_3f93_7fceaab2afee -->|defined in| 69cf3d4a_9aaa_8f16_811c_d0f7b92e1125
  3938888f_8d7c_99fd_a09c_3bb4135551f1["AlpnSelector()"]
  301bb277_7cd2_153d_3f93_7fceaab2afee -->|method| 3938888f_8d7c_99fd_a09c_3bb4135551f1
  00bbeee1_a1ed_4eda_8a7f_ba9f999421da["String()"]
  301bb277_7cd2_153d_3f93_7fceaab2afee -->|method| 00bbeee1_a1ed_4eda_8a7f_ba9f999421da
  0498f882_41cc_3328_c0f3_acd0e121da4f["checkUnsupported()"]
  301bb277_7cd2_153d_3f93_7fceaab2afee -->|method| 0498f882_41cc_3328_c0f3_acd0e121da4f

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java lines 37–78

    final class AlpnSelector implements BiFunction<SSLEngine, List<String>, String> {
        private final ProtocolSelector selector;
        private boolean called;

        AlpnSelector(ProtocolSelector selector) {
            this.selector = selector;
        }

        @Override
        public String apply(SSLEngine sslEngine, List<String> strings) {
            assert !called;
            called = true;

            try {
                String selected = selector.select(strings);
                return selected == null ? StringUtil.EMPTY_STRING : selected;
            } catch (Exception cause) {
                // Returning null means we want to fail the handshake.
                //
                // See https://download.java.net/java/jdk9/docs/api/javax/net/ssl/
                // SSLEngine.html#setHandshakeApplicationProtocolSelector-java.util.function.BiFunction-
                return null;
            }
        }

        void checkUnsupported() {
            if (called) {
                // ALPN message was received by peer and so apply(...) was called.
                // See:
                // https://hg.openjdk.java.net/jdk9/dev/jdk/file/65464a307408/src/
                // java.base/share/classes/sun/security/ssl/ServerHandshaker.java#l933
                return;
            }
            String protocol = getApplicationProtocol();
            assert protocol != null;

            if (protocol.isEmpty()) {
                // ALPN is not supported
                selector.unsupported();
            }
        }
    }

Frequently Asked Questions

What is the AlpnSelector class?
AlpnSelector is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java.
Where is AlpnSelector defined?
AlpnSelector is defined in handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java at line 37.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free