Skip to content

io microsphere net CompositeSubProtocolURLConnectionFactory

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

CompositeSubProtocolURLConnectionFactory

Type: Class | Module: microsphere-java-core | Package: io.microsphere.net | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/net/CompositeSubProtocolURLConnectionFactory.java

Overview

A composite implementation of SubProtocolURLConnectionFactory that combines multiple factories. This class allows dynamic modification at runtime by adding or removing individual factories.

The composite factory delegates the creation of URL connections to its internal list of factories, selecting the appropriate one based on support for the given URL and sub-protocols.

Key Features

- **Dynamic Composition:** Add or remove factories at runtime.
- **Prioritized Ordering:** Factories are sorted based on their priority using the
    `Prioritized` interface. Higher priority factories are consulted first when determining support.
- **Efficient Delegation:** Delegates connection creation to the first factory that supports the URL and sub-protocols.

Example Usage

`CompositeSubProtocolURLConnectionFactory compositeFactory = new CompositeSubProtocolURLConnectionFactory();

// Create and add a custom factory
SubProtocolURLConnectionFactory myFactory = new MySubProtocolURLConnectionFactory();
compositeFactory.add(myFactory);

// Use the composite factory to create a connection
URL url = new URL("http://example.com");
List subProtocols = Arrays.asList("myprotocol", "anotherprotocol");
Proxy proxy = Proxy.NO_PROXY;

if (compositeFactory.supports(url, subProtocols)) {
    URLConnection connection = compositeFactory.create(url, subProtocols, proxy);
    // proceed with using the connection
`
}

This class is thread-safe as long as modifications to the factory list happen through the provided methods, which re-sort the internal list in a thread-safe manner.

Declaration

public class CompositeSubProtocolURLConnectionFactory implements SubProtocolURLConnectionFactory

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

CompositeSubProtocolURLConnectionFactory compositeFactory = new CompositeSubProtocolURLConnectionFactory();

// Create and add a custom factory
SubProtocolURLConnectionFactory myFactory = new MySubProtocolURLConnectionFactory();
compositeFactory.add(myFactory);

// Use the composite factory to create a connection
URL url = new URL("http://example.com");
List<String> subProtocols = Arrays.asList("myprotocol", "anotherprotocol");
Proxy proxy = Proxy.NO_PROXY;

if (compositeFactory.supports(url, subProtocols)) {
    URLConnection connection = compositeFactory.create(url, subProtocols, proxy);
    // proceed with using the connection
}

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.net.CompositeSubProtocolURLConnectionFactory;

API Reference

Public Methods

Method Description
add
add
remove
supports
create

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally