public ProcessDescription call()

in src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java [63:135]


    public ProcessDescription call() throws Exception {

        // fail if launchpad with this id is already started
        if (!ProcessDescriptionProvider.getInstance().isRunConfigurationAvailable(configuration.getId())) {
            throw new Exception("Launchpad with id " + configuration.getId() + " is not available");
        }

        // get the launchpad jar
        final File launchpad = this.environment.prepare(this.configuration.getFolder());

        // Lock the launchpad id
        final String launchpadKey = ProcessDescriptionProvider.getInstance().getId(configuration.getId());

        // start launchpad
        ProcessDescription cfg = this.start(launchpad);

        // Add thread hook to shutdown launchpad
        if (environment.isShutdownOnExit()) {
            cfg.installShutdownHook();
        }

        // Add configuration to the config provider
        ProcessDescriptionProvider.getInstance().addRunConfiguration(cfg, launchpadKey);

        boolean started = false;
        try {
            final long endTime = System.currentTimeMillis() + this.environment.getReadyTimeOutSec() * 1000;
            boolean finished = false;
            while ( !started && !finished && System.currentTimeMillis() < endTime ) {
                Thread.sleep(5000);
                started = cfg.getControlListener().isStarted();
                try {
                    // if we get an exit value, the process has stopped
                    cfg.getProcess().exitValue();
                    finished = true;
                } catch ( final IllegalThreadStateException itse) {
                    // everything as expected
                }
                
            }

            if ( finished ) {
                throw new Exception("Launchpad did exit unexpectedly.");
            }
            if ( !started ) {
                throw new Exception("Launchpad did not start successfully in " + this.environment.getReadyTimeOutSec() + " seconds.");
            }
            // now check for the availability of the HTTP port
            boolean httpAvailable = isLocalhostPortAvailable(Integer.valueOf(this.configuration.getPort()));
            // repeat until http service is up as well
            while ( !httpAvailable && System.currentTimeMillis() < endTime ) {
                Thread.sleep(1000);
                httpAvailable = isLocalhostPortAvailable(Integer.valueOf(this.configuration.getPort()));
            }
            if ( !httpAvailable ) {
                throw new Exception("Launchpad did not start http service on port " + this.configuration.getPort() + " successfully in " + this.environment.getReadyTimeOutSec() + " seconds.");
            }
            this.logger.info("Started Launchpad '" + configuration.getId() +
                    "' at port " + configuration.getPort()+ " [run modes: " + configuration.getRunmode()+ "]");
        } finally {
            // stop control port
            cfg.getControlListener().stop();

            // call launchpad stop routine if not properly started
            if (!started) {
                stop(this.logger, cfg);
                ProcessDescriptionProvider.getInstance().removeRunConfiguration(cfg.getId());
                cfg = null;
            }
        }

        return cfg;
    }