author | jlahoda |
Tue, 09 May 2017 12:22:15 +0200 | |
changeset 45044 | 7c50549b7744 |
parent 43770 | a321bed02000 |
permissions | -rw-r--r-- |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
1 |
/* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
4 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
10 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
15 |
* accompanied this code). |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
16 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
20 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
23 |
* questions. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
24 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
25 |
package jdk.jshell.execution; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
26 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
27 |
import jdk.jshell.spi.ExecutionEnv; |
40767 | 28 |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
29 |
import java.io.IOException; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
30 |
import java.io.InputStream; |
41628 | 31 |
import java.io.InterruptedIOException; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
32 |
import java.io.ObjectInput; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
33 |
import java.io.ObjectInputStream; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
34 |
import java.io.ObjectOutput; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
35 |
import java.io.ObjectOutputStream; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
36 |
import java.io.OutputStream; |
40767 | 37 |
import java.util.Arrays; |
38 |
import java.util.HashMap; |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
39 |
import java.util.Map; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
40 |
import java.util.Map.Entry; |
40767 | 41 |
import java.util.function.BiFunction; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
42 |
import java.util.function.Consumer; |
40767 | 43 |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
44 |
import com.sun.jdi.VirtualMachine; |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
45 |
import jdk.jshell.spi.ExecutionControl; |
41628 | 46 |
import jdk.jshell.spi.ExecutionControl.ExecutionControlException; |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
47 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
48 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
49 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
50 |
* Miscellaneous utility methods for setting-up implementations of |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
51 |
* {@link ExecutionControl}. Particularly implementations with remote |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
52 |
* execution. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
53 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
54 |
* @author Jan Lahoda |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
55 |
* @author Robert Field |
43770 | 56 |
* @since 9 |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
57 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
58 |
public class Util { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
59 |
|
41628 | 60 |
private static final int TAG_DATA = 0; |
61 |
private static final int TAG_CLOSED = 1; |
|
62 |
private static final int TAG_EXCEPTION = 2; |
|
63 |
||
43766
498b07dcf851
8174262: Error message misspelling: "instanciated"
rfield
parents:
42969
diff
changeset
|
64 |
// never instantiated |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
65 |
private Util() {} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
66 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
67 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
68 |
* Forward commands from the input to the specified {@link ExecutionControl} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
69 |
* instance, then responses back on the output. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
70 |
* @param ec the direct instance of {@link ExecutionControl} to process commands |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
71 |
* @param in the command input |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
72 |
* @param out the command response output |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
73 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
74 |
public static void forwardExecutionControl(ExecutionControl ec, |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
75 |
ObjectInput in, ObjectOutput out) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
76 |
new ExecutionControlForwarder(ec, in, out).commandLoop(); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
77 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
78 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
79 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
80 |
* Forward commands from the input to the specified {@link ExecutionControl} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
81 |
* instance, then responses back on the output. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
82 |
* @param ec the direct instance of {@link ExecutionControl} to process commands |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
83 |
* @param inStream the stream from which to create the command input |
40767 | 84 |
* @param outStream the stream that will carry any specified auxiliary channels (like |
85 |
* {@code System.out} and {@code System.err}), and the command response output. |
|
86 |
* @param outputStreamMap a map between names of additional streams to carry and setters |
|
87 |
* for the stream. Names starting with '$' are reserved for internal use. |
|
88 |
* @param inputStreamMap a map between names of additional streams to carry and setters |
|
89 |
* for the stream. Names starting with '$' are reserved for internal use. |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
90 |
* @throws IOException if there are errors using the passed streams |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
91 |
*/ |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
92 |
public static void forwardExecutionControlAndIO(ExecutionControl ec, |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
93 |
InputStream inStream, OutputStream outStream, |
40767 | 94 |
Map<String, Consumer<OutputStream>> outputStreamMap, |
95 |
Map<String, Consumer<InputStream>> inputStreamMap) throws IOException { |
|
96 |
for (Entry<String, Consumer<OutputStream>> e : outputStreamMap.entrySet()) { |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
97 |
e.getValue().accept(multiplexingOutputStream(e.getKey(), outStream)); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
98 |
} |
40767 | 99 |
|
100 |
ObjectOutputStream cmdOut = new ObjectOutputStream(multiplexingOutputStream("$command", outStream)); |
|
101 |
PipeInputStream cmdInPipe = new PipeInputStream(); |
|
102 |
Map<String, OutputStream> inputs = new HashMap<>(); |
|
103 |
inputs.put("$command", cmdInPipe.createOutput()); |
|
104 |
for (Entry<String, Consumer<InputStream>> e : inputStreamMap.entrySet()) { |
|
105 |
OutputStream inputSignal = multiplexingOutputStream("$" + e.getKey() + "-input-requested", outStream); |
|
106 |
PipeInputStream inputPipe = new PipeInputStream() { |
|
107 |
@Override protected void inputNeeded() throws IOException { |
|
108 |
inputSignal.write('1'); |
|
109 |
inputSignal.flush(); |
|
110 |
} |
|
41628 | 111 |
@Override |
112 |
public synchronized int read() throws IOException { |
|
113 |
int tag = super.read(); |
|
114 |
switch (tag) { |
|
115 |
case TAG_DATA: return super.read(); |
|
116 |
case TAG_CLOSED: close(); return -1; |
|
117 |
case TAG_EXCEPTION: |
|
118 |
int len = (super.read() << 0) + (super.read() << 8) + (super.read() << 16) + (super.read() << 24); |
|
119 |
byte[] message = new byte[len]; |
|
120 |
for (int i = 0; i < len; i++) { |
|
121 |
message[i] = (byte) super.read(); |
|
122 |
} |
|
123 |
throw new IOException(new String(message, "UTF-8")); |
|
124 |
case -1: |
|
125 |
return -1; |
|
126 |
default: |
|
127 |
throw new IOException("Internal error: unrecognized message tag: " + tag); |
|
128 |
} |
|
129 |
} |
|
40767 | 130 |
}; |
131 |
inputs.put(e.getKey(), inputPipe.createOutput()); |
|
132 |
e.getValue().accept(inputPipe); |
|
133 |
} |
|
134 |
new DemultiplexInput(inStream, inputs, inputs.values()).start(); |
|
135 |
ObjectInputStream cmdIn = new ObjectInputStream(cmdInPipe); |
|
136 |
||
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
137 |
forwardExecutionControl(ec, cmdIn, cmdOut); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
138 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
139 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
140 |
static OutputStream multiplexingOutputStream(String label, OutputStream outputStream) { |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
141 |
return new MultiplexingOutputStream(label, outputStream); |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
142 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
143 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
144 |
/** |
40767 | 145 |
* Creates an ExecutionControl for given packetized input and output. The given InputStream |
146 |
* is de-packetized, and content forwarded to ObjectInput and given OutputStreams. The ObjectOutput |
|
147 |
* and values read from the given InputStream are packetized and sent to the given OutputStream. |
|
148 |
* |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
149 |
* @param input the packetized input stream |
40767 | 150 |
* @param output the packetized output stream |
151 |
* @param outputStreamMap a map between stream names and the output streams to forward. |
|
152 |
* Names starting with '$' are reserved for internal use. |
|
153 |
* @param inputStreamMap a map between stream names and the input streams to forward. |
|
154 |
* Names starting with '$' are reserved for internal use. |
|
155 |
* @param factory to create the ExecutionControl from ObjectInput and ObjectOutput. |
|
156 |
* @return the created ExecutionControl |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
157 |
* @throws IOException if setting up the streams raised an exception |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
158 |
*/ |
40767 | 159 |
public static ExecutionControl remoteInputOutput(InputStream input, OutputStream output, |
160 |
Map<String, OutputStream> outputStreamMap, Map<String, InputStream> inputStreamMap, |
|
161 |
BiFunction<ObjectInput, ObjectOutput, ExecutionControl> factory) throws IOException { |
|
41628 | 162 |
ExecutionControl[] result = new ExecutionControl[1]; |
40767 | 163 |
Map<String, OutputStream> augmentedStreamMap = new HashMap<>(outputStreamMap); |
164 |
ObjectOutput commandOut = new ObjectOutputStream(Util.multiplexingOutputStream("$command", output)); |
|
165 |
for (Entry<String, InputStream> e : inputStreamMap.entrySet()) { |
|
166 |
InputStream in = e.getValue(); |
|
167 |
OutputStream inTarget = Util.multiplexingOutputStream(e.getKey(), output); |
|
168 |
augmentedStreamMap.put("$" + e.getKey() + "-input-requested", new OutputStream() { |
|
169 |
@Override |
|
170 |
public void write(int b) throws IOException { |
|
171 |
//value ignored, just a trigger to read from the input |
|
41628 | 172 |
try { |
173 |
int r = in.read(); |
|
174 |
if (r == (-1)) { |
|
175 |
inTarget.write(TAG_CLOSED); |
|
176 |
} else { |
|
177 |
inTarget.write(new byte[] {TAG_DATA, (byte) r}); |
|
178 |
} |
|
179 |
} catch (InterruptedIOException exc) { |
|
180 |
try { |
|
181 |
result[0].stop(); |
|
182 |
} catch (ExecutionControlException ex) { |
|
183 |
debug(ex, "$" + e.getKey() + "-input-requested.write"); |
|
184 |
} |
|
185 |
} catch (IOException exc) { |
|
186 |
byte[] message = exc.getMessage().getBytes("UTF-8"); |
|
187 |
inTarget.write(TAG_EXCEPTION); |
|
188 |
inTarget.write((message.length >> 0) & 0xFF); |
|
189 |
inTarget.write((message.length >> 8) & 0xFF); |
|
190 |
inTarget.write((message.length >> 16) & 0xFF); |
|
191 |
inTarget.write((message.length >> 24) & 0xFF); |
|
192 |
inTarget.write(message); |
|
193 |
} |
|
40767 | 194 |
} |
195 |
}); |
|
196 |
} |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
197 |
PipeInputStream commandIn = new PipeInputStream(); |
40767 | 198 |
OutputStream commandInTarget = commandIn.createOutput(); |
199 |
augmentedStreamMap.put("$command", commandInTarget); |
|
200 |
new DemultiplexInput(input, augmentedStreamMap, Arrays.asList(commandInTarget)).start(); |
|
41628 | 201 |
return result[0] = factory.apply(new ObjectInputStream(commandIn), commandOut); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
202 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
203 |
|
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
204 |
/** |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
205 |
* Monitor the JDI event stream for {@link com.sun.jdi.event.VMDeathEvent} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
206 |
* and {@link com.sun.jdi.event.VMDisconnectEvent}. If encountered, invokes |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
207 |
* {@code unbiddenExitHandler}. |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
208 |
* |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
209 |
* @param vm the virtual machine to check |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
210 |
* @param unbiddenExitHandler the handler, which will accept the exit |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
211 |
* information |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
212 |
*/ |
41941
a935ac3f5274
8161983: JShell API: Clean-up following 8160127 et. al.
rfield
parents:
41628
diff
changeset
|
213 |
public static void detectJdiExitEvent(VirtualMachine vm, Consumer<String> unbiddenExitHandler) { |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
214 |
if (vm.canBeModified()) { |
41941
a935ac3f5274
8161983: JShell API: Clean-up following 8160127 et. al.
rfield
parents:
41628
diff
changeset
|
215 |
new JdiEventHandler(vm, unbiddenExitHandler).start(); |
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
216 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
217 |
} |
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
218 |
|
41628 | 219 |
/** |
220 |
* Log a serious unexpected internal exception. |
|
221 |
* |
|
222 |
* @param ex the exception |
|
223 |
* @param where a description of the context of the exception |
|
224 |
*/ |
|
225 |
private static void debug(Throwable ex, String where) { |
|
226 |
// Reserved for future logging |
|
227 |
} |
|
39807
ba0ff343d241
8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents:
diff
changeset
|
228 |
} |