/*
 * Created by Koen Deschacht (koendeschacht@gmail.com) 2017-4-28. For license
 * information see the LICENSE file in the root folder of this repository.
 */

package be.bagofwords.minidepi.remote;

import be.bagofwords.exec.RemoteExecConfig;
import be.bagofwords.util.SocketConnection;

import java.io.IOException;

public class RemoteExecService {

    public static final String SOCKET_NAME = "remote-exec";

    public SocketConnection execRemotely(String host, int port, RemoteExecConfig remoteExecConfig) throws IOException {
        SocketConnection socketConnection = new SocketConnection(host, port, SOCKET_NAME);
        socketConnection.writeValue(remoteExecConfig.pack());
        return socketConnection;
    }

}

@@ -281,16 +281,54 @@
 nection;
+%0Aimport org.apache.commons.io.IOUtils;
 %0A%0Aimport
@@ -718,16 +718,557 @@
 ack());%0A
+        boolean success = socketConnection.readBoolean();%0A        if (!success) %7B%0A            String error = socketConnection.readString();%0A            socketConnection.writeBoolean(true);%0A            IOUtils.closeQuietly(socketConnection);%0A            String remoteError = %22%5CnREMOTE ERROR START:%5Cn%22 + error + %22%5CnREMOTE ERROR END%5Cn%22;%0A            throw new RuntimeException(%22Failed to execute remote class %22 + remoteExecConfig.getExecutorClassName() + remoteError);%0A        %7D else %7B%0A            socketConnection.writeBoolean(true);%0A        %7D%0A
         

Return error messages if the compilation of remote methods fails