public void start()

in arquillian/daemon/src/main/java/org/wildfly/swarm/arquillian/daemon/container/DaemonDeployableContainerBase.java [64:135]


    public void start() throws LifecycleException {
        // Open up remote resources
        try {

            final long startTime = System.currentTimeMillis();
            final int secondsToWait = this.timeout;
            final long acceptableTime = startTime + 1000 * secondsToWait; // 10 seconds from now
            Socket socket = null;
            while (true) {
                try {
                    // TODO Security Action
                    socket = new Socket(remoteAddress.getHostString(), remoteAddress.getPort());
                    if (log.isLoggable(Level.FINEST)) {
                        log.finest("Got connection to " + remoteAddress.toString());
                    }
                    break;
                } catch (final ConnectException ce) {
                    if (log.isLoggable(Level.FINEST)) {
                        log.finest("No connection yet available to remote process");
                    }
                    final long currentTime = System.currentTimeMillis();
                    // Time expired?
                    if (currentTime > acceptableTime) {
                        throw new LifecycleException("Could not connect to the server at "
                                                             + remoteAddress.getHostString() + ":" + remoteAddress.getPort() + " in the allotted "
                                                             + secondsToWait + "s", ce);
                    }
                    // Sleep and try again
                    try {
                        Thread.sleep(200);
                    } catch (final InterruptedException e) {
                        Thread.interrupted();
                        throw new RuntimeException("No one should be interrupting us while we're waiting to connect", e);
                    }
                }
            }
            assert socket != null : "Socket should have been connected";
            this.socket = socket;
            final OutputStream socketOutstream = socket.getOutputStream();
            this.socketOutstream = socketOutstream;
            final PrintWriter writer = new PrintWriter(new OutputStreamWriter(socketOutstream, WireProtocol.CHARSET),
                                                       true);
            this.writer = writer;
            final InputStream socketInstream = socket.getInputStream();
            this.socketInstream = socketInstream;
            final BufferedReader reader = new BufferedReader(new InputStreamReader(socketInstream));
            this.reader = reader;

            final StringBuilder builder = new StringBuilder();
            builder.append(WireProtocol.COMMAND_CHECK_DEPLOYMENT);
            builder.append(WireProtocol.COMMAND_EOF_DELIMITER);
            final String checkCommand = builder.toString();
            // Request
            writer.write(checkCommand);
            writer.flush();

            Throwable error = null;
            try {
                final ObjectInputStream response = new ObjectInputStream(socketInstream);
                error = (Throwable) response.readObject();
            } catch (Throwable e) {
                e.printStackTrace();
            }
            if (error != null) {
                throw new LifecycleException(error.getMessage(), error);
            }
        } catch (final IOException ioe) {
            this.closeRemoteResources();
            throw new LifecycleException("Could not open connection to remote process", ioe);
        }

    }