< prev index next >
src/jdk.jshell/share/classes/jdk/jshell/execution/JDIDefaultExecutionControl.java
Print this page
rev 3613 : imported patch 8131023
*** 23,35 ****
* questions.
*/
package jdk.jshell.execution;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
- import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
--- 23,35 ----
* questions.
*/
package jdk.jshell.execution;
import java.io.IOException;
+ import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
*** 46,56 ****
import com.sun.jdi.ThreadReference;
import com.sun.jdi.VMDisconnectedException;
import com.sun.jdi.VirtualMachine;
import jdk.jshell.spi.ExecutionControl;
import jdk.jshell.spi.ExecutionEnv;
! import static jdk.jshell.execution.Util.remoteInput;
/**
* The implementation of {@link jdk.jshell.spi.ExecutionControl} that the
* JShell-core uses by default.
* Launches a remote process -- the "remote agent".
--- 46,56 ----
import com.sun.jdi.ThreadReference;
import com.sun.jdi.VMDisconnectedException;
import com.sun.jdi.VirtualMachine;
import jdk.jshell.spi.ExecutionControl;
import jdk.jshell.spi.ExecutionEnv;
! import static jdk.jshell.execution.Util.remoteInputOutput;
/**
* The implementation of {@link jdk.jshell.spi.ExecutionControl} that the
* JShell-core uses by default.
* Launches a remote process -- the "remote agent".
*** 101,111 ****
* @param env the context passed by
* {@link jdk.jshell.spi.ExecutionControl#start(jdk.jshell.spi.ExecutionEnv) }
* @return the channel
* @throws IOException if there are errors in set-up
*/
! private static JDIDefaultExecutionControl create(ExecutionEnv env, boolean isLaunch) throws IOException {
try (final ServerSocket listener = new ServerSocket(0)) {
// timeout after 60 seconds
listener.setSoTimeout(60000);
int port = listener.getLocalPort();
--- 101,111 ----
* @param env the context passed by
* {@link jdk.jshell.spi.ExecutionControl#start(jdk.jshell.spi.ExecutionEnv) }
* @return the channel
* @throws IOException if there are errors in set-up
*/
! private static ExecutionControl create(ExecutionEnv env, boolean isLaunch) throws IOException {
try (final ServerSocket listener = new ServerSocket(0)) {
// timeout after 60 seconds
listener.setSoTimeout(60000);
int port = listener.getLocalPort();
*** 113,126 ****
JDIInitiator jdii = new JDIInitiator(port,
env.extraRemoteVMOptions(), REMOTE_AGENT, isLaunch);
VirtualMachine vm = jdii.vm();
Process process = jdii.process();
- // Forward input to the remote agent
- Util.forwardInputToRemote(env.userIn(), process.getOutputStream(),
- ex -> debug(ex, "input forwarding failure"));
-
List<Consumer<String>> deathListeners = new ArrayList<>();
deathListeners.add(s -> env.closeDown());
Util.detectJDIExitEvent(vm, s -> {
for (Consumer<String> h : deathListeners) {
h.accept(s);
--- 113,122 ----
*** 129,144 ****
// Set-up the commands/reslts on the socket. Piggy-back snippet
// output.
Socket socket = listener.accept();
// out before in -- match remote creation so we don't hang
! ObjectOutput cmdout = new ObjectOutputStream(socket.getOutputStream());
! Map<String, OutputStream> io = new HashMap<>();
! io.put("out", env.userOut());
! io.put("err", env.userErr());
! ObjectInput cmdin = remoteInput(socket.getInputStream(), io);
! return new JDIDefaultExecutionControl(cmdout, cmdin, vm, process, deathListeners);
}
}
/**
* Create an instance.
--- 125,141 ----
// Set-up the commands/reslts on the socket. Piggy-back snippet
// output.
Socket socket = listener.accept();
// out before in -- match remote creation so we don't hang
! OutputStream out = socket.getOutputStream();
! Map<String, OutputStream> outputs = new HashMap<>();
! outputs.put("out", env.userOut());
! outputs.put("err", env.userErr());
! Map<String, InputStream> input = new HashMap<>();
! input.put("in", env.userIn());
! return remoteInputOutput(socket.getInputStream(), out, outputs, input, (objIn, objOut) -> new JDIDefaultExecutionControl(objOut, objIn, vm, process, deathListeners));
}
}
/**
* Create an instance.
< prev index next >