Java 类org.springframework.boot.context.embedded.PortInUseException 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TomcatEmbeddedServletContainer.java   
private void checkThatConnectorsHaveStarted() {
    for (Connector connector : this.tomcat.getService().findConnectors()) {
        if (LifecycleState.FAILED.equals(connector.getState())) {
            throw new PortInUseException(connector.getPort());
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:UndertowEmbeddedServletContainer.java   
@Override
public void start() throws EmbeddedServletContainerException {
    synchronized (this.monitor) {
        try {
            if (!this.autoStart) {
                return;
            }
            if (this.undertow == null) {
                this.undertow = createUndertowServer();
            }
            this.undertow.start();
            this.started = true;
            UndertowEmbeddedServletContainer.logger
                    .info("Undertow started on port(s) " + getPortsDescription());
        }
        catch (Exception ex) {
            if (findBindException(ex) != null) {
                List<Port> failedPorts = getConfiguredPorts();
                List<Port> actualPorts = getActualPorts();
                failedPorts.removeAll(actualPorts);
                if (failedPorts.size() == 1) {
                    throw new PortInUseException(
                            failedPorts.iterator().next().getNumber());
                }
            }
            throw new EmbeddedServletContainerException(
                    "Unable to start embedded Undertow", ex);
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PortInUseFailureAnalyzer.java   
@Override
protected FailureAnalysis analyze(Throwable rootFailure, PortInUseException cause) {
    return new FailureAnalysis(
            "Embedded servlet container failed to start. Port " + cause.getPort()
                    + " was already in use.",
            "Identify and stop the process that's listening on port "
                    + cause.getPort() + " or configure this "
                    + "application to listen on another port.",
            cause);
}
项目:shinyproxy    文件:ShinyProxyApplication.java   
public static void main(String[] args) {
    SpringApplication app = new SpringApplication(ShinyProxyApplication.class);

    boolean hasExternalConfig = Files.exists(Paths.get("application.yml"));
    if (!hasExternalConfig) app.setAdditionalProfiles("demo");

    try {
        app.run(args);
    } catch (Exception e) {
        // Workaround for bug in UndertowEmbeddedServletContainer.start():
        // If undertow.start() fails, started remains false which prevents undertow.stop() from ever being called.
        // Undertow's (non-daemon) XNIO worker threads will then prevent the JVM from exiting.
        if (e instanceof PortInUseException) System.exit(-1);
    }
}
项目:spring-boot-concourse    文件:TomcatEmbeddedServletContainer.java   
private void checkThatConnectorsHaveStarted() {
    for (Connector connector : this.tomcat.getService().findConnectors()) {
        if (LifecycleState.FAILED.equals(connector.getState())) {
            throw new PortInUseException(connector.getPort());
        }
    }
}
项目:spring-boot-concourse    文件:UndertowEmbeddedServletContainer.java   
@Override
public synchronized void start() throws EmbeddedServletContainerException {
    try {
        if (!this.autoStart) {
            return;
        }
        if (this.undertow == null) {
            this.undertow = createUndertowServer();
        }
        this.undertow.start();
        this.started = true;
        UndertowEmbeddedServletContainer.logger
                .info("Undertow started on port(s) " + getPortsDescription());
    }
    catch (Exception ex) {
        if (findBindException(ex) != null) {
            List<Port> failedPorts = getConfiguredPorts();
            List<Port> actualPorts = getActualPorts();
            failedPorts.removeAll(actualPorts);
            if (failedPorts.size() == 1) {
                throw new PortInUseException(
                        failedPorts.iterator().next().getNumber());
            }
        }
        throw new EmbeddedServletContainerException(
                "Unable to start embedded Undertow", ex);
    }
}
项目:spring-boot-concourse    文件:PortInUseFailureAnalyzer.java   
@Override
protected FailureAnalysis analyze(Throwable rootFailure, PortInUseException cause) {
    return new FailureAnalysis(
            "Embedded servlet container failed to start. Port " + cause.getPort()
                    + " was already in use.",
            "Identify and stop the process that's listening on port "
                    + cause.getPort() + " or configure this "
                    + "application to listen on another port.",
            cause);
}
项目:blog-java2    文件:BlogJava2App.java   
protected static ConfigurableApplicationContext shutdownAndRun(Class<?> clazz, String[] args) {
    try {
        return run(clazz, args);
    }
    // 二重起動
    catch (PortInUseException e) {
        HttpURLConnection connection = null;
        try {
            AppConfig appConfig = AppConfig.getInstance();
            String url = "http://localhost:" + appConfig.getManagementPort() + "/shutdown";
            connection = (HttpURLConnection) new URL(url).openConnection();
            connection.setRequestMethod("POST");
            int responseCode = connection.getResponseCode();
            if (responseCode == 200) {
                logger.info("Shutdown OK");

                // launch again
                return run(clazz, args);
            }
            else {
                throw new IllegalStateException("Invalid response code : " + responseCode);
            }
        }
        catch (Exception e2) {
            throw new IllegalStateException("Shutdown failed", e2);
        }
        finally {
            IOUtils.close(connection);
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:FailureAnalyzersTests.java   
@PostConstruct
public void fail() {
    throw new PortInUseException(8080);
}
项目:spring-boot-concourse    文件:FailureAnalyzersTests.java   
@PostConstruct
public void fail() {
    throw new PortInUseException(8080);
}