public void startupFinished()

in src/main/java/org/apache/sling/maven/slingstart/launcher/Launcher.java [36:89]


    public void startupFinished() {
        final List<String> hosts = new ArrayList<String>();
        hosts.add("localhost");
        hosts.add("127.0.0.1");

        boolean done = false;
        int index = 0;
        while ( !done && index < hosts.size() ) {
            final String hostName = hosts.get(index);
            final int twoMinutes = 2 * 60 * 1000;

            Socket clientSocket = null;
            DataOutputStream out = null;
            BufferedReader in = null;
            try {
                clientSocket = new Socket();
                clientSocket.connect(new InetSocketAddress(hostName, listenerPort), twoMinutes);
                // without that, read() call on the InputStream associated with this Socket is infinite
                clientSocket.setSoTimeout(twoMinutes);

                out = new DataOutputStream(clientSocket.getOutputStream());
                in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                out.writeBytes("started\n");
                in.readLine();
                done = true;
            } catch (final Throwable ignore) {
                // catch Throwable because InetSocketAddress and Socket#connect throws unchecked exceptions
                // we ignore this for now
            } finally {
                if ( in != null ) {
                    try {
                        in.close();
                    } catch ( final IOException ioe) {
                        // ignore
                    }
                }
                if ( out != null ) {
                    try {
                        out.close();
                    } catch ( final IOException ioe) {
                        // ignore
                    }
                }
                if ( clientSocket != null ) {
                    try {
                        clientSocket.close();
                    } catch (final IOException e) {
                        // ignore
                    }
                }
            }
            index++;
        }
    }