All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.runtime.QuarkusBindException Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.runtime;

import java.net.BindException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * An exception that is meant to stand in for {@link BindException} and provide information
 * about the target which caused the bind exception.
 */
public class QuarkusBindException extends BindException {

    private final List ports;

    private static String createMessage(List ports) {
        return "Port(s) already bound: " + ports.stream().map(i -> Integer.toString(i)).collect(Collectors.joining(", "));
    }

    private static void assertPortsNotEmpty(List ports) {
        if (ports.isEmpty()) {
            throw new IllegalStateException("ports must not be empty");
        }
    }

    public QuarkusBindException(Integer... ports) {
        this(Arrays.asList(ports));
    }

    public QuarkusBindException(List ports) {
        super(createMessage(ports));
        assertPortsNotEmpty(ports);
        this.ports = ports;
    }

    public QuarkusBindException(BindException e, Integer... ports) {
        this(e, Arrays.asList(ports));
    }

    public QuarkusBindException(BindException e, List ports) {
        super(createMessage(ports) + ": " + e.getMessage());
        assertPortsNotEmpty(ports);
        this.ports = ports;
    }

    public List getPorts() {
        return ports;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy