Home / Class/ ServiceLoadingExtensions Class — netty Architecture

ServiceLoadingExtensions Class — netty Architecture

Architecture documentation for the ServiceLoadingExtensions class in ChannelInitializerExtensions.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  bab902d4_1654_a0a4_ea13_538279bdc06d["ServiceLoadingExtensions"]
  cb29dc4b_6558_3149_3d50_2eedc0d4495a["ChannelInitializerExtensions.java"]
  bab902d4_1654_a0a4_ea13_538279bdc06d -->|defined in| cb29dc4b_6558_3149_3d50_2eedc0d4495a
  d665f10a_79b1_fe90_6227_e92119441e32["ServiceLoadingExtensions()"]
  bab902d4_1654_a0a4_ea13_538279bdc06d -->|method| d665f10a_79b1_fe90_6227_e92119441e32
  c4116caa_0c6a_1f97_2e1c_c079408be1b0["extensions()"]
  bab902d4_1654_a0a4_ea13_538279bdc06d -->|method| c4116caa_0c6a_1f97_2e1c_c079408be1b0
  a6dac6b4_0853_3f22_18a9_d6a43cb56989["serviceLoadExtensions()"]
  bab902d4_1654_a0a4_ea13_538279bdc06d -->|method| a6dac6b4_0853_3f22_18a9_d6a43cb56989

Relationship Graph

Source Code

transport/src/main/java/io/netty/bootstrap/ChannelInitializerExtensions.java lines 80–126

    private static final class ServiceLoadingExtensions extends ChannelInitializerExtensions {
        private final boolean loadAndCache;

        private WeakReference<ClassLoader> classLoader;
        private Collection<ChannelInitializerExtension> extensions;

        ServiceLoadingExtensions(boolean loadAndCache) {
            this.loadAndCache = loadAndCache;
        }

        @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
        @Override
        synchronized Collection<ChannelInitializerExtension> extensions(ClassLoader cl) {
            ClassLoader configured = classLoader == null ? null : classLoader.get();
            if (configured == null || configured != cl) {
                Collection<ChannelInitializerExtension> loaded = serviceLoadExtensions(loadAndCache, cl);
                classLoader = new WeakReference<ClassLoader>(cl);
                extensions = loadAndCache ? loaded : Collections.<ChannelInitializerExtension>emptyList();
            }
            return extensions;
        }

        private static Collection<ChannelInitializerExtension> serviceLoadExtensions(boolean load, ClassLoader cl) {
            List<ChannelInitializerExtension> extensions = new ArrayList<ChannelInitializerExtension>();

            ServiceLoader<ChannelInitializerExtension> loader = ServiceLoader.load(
                    ChannelInitializerExtension.class, cl);
            for (ChannelInitializerExtension extension : loader) {
                extensions.add(extension);
            }

            if (!extensions.isEmpty()) {
                Collections.sort(extensions, new Comparator<ChannelInitializerExtension>() {
                    @Override
                    public int compare(ChannelInitializerExtension a, ChannelInitializerExtension b) {
                        return Double.compare(a.priority(), b.priority());
                    }
                });
                logger.info("ServiceLoader {}(s) {}: {}", ChannelInitializerExtension.class.getSimpleName(),
                        load ? "registered" : "detected", extensions);
                return Collections.unmodifiableList(extensions);
            }
            logger.debug("ServiceLoader {}(s) {}: []", ChannelInitializerExtension.class.getSimpleName(),
                    load ? "registered" : "detected");
            return Collections.emptyList();
        }
    }

Frequently Asked Questions

What is the ServiceLoadingExtensions class?
ServiceLoadingExtensions is a class in the netty codebase, defined in transport/src/main/java/io/netty/bootstrap/ChannelInitializerExtensions.java.
Where is ServiceLoadingExtensions defined?
ServiceLoadingExtensions is defined in transport/src/main/java/io/netty/bootstrap/ChannelInitializerExtensions.java at line 80.

Analyze Your Own Codebase

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

Try Supermodel Free