author | coleenp |
Wed, 15 Nov 2017 08:14:31 -0500 | |
changeset 47894 | 352b17f62ff7 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
1 |
/* |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
4 |
* |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
8 |
* |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
14 |
* |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
18 |
* |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
21 |
* questions. |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
22 |
*/ |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
23 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
24 |
import java.util.Map; |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
42969
diff
changeset
|
25 |
import java.util.logging.Level; |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
42969
diff
changeset
|
26 |
import java.util.logging.Logger; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
27 |
import jdk.jshell.JShell; |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
28 |
import jdk.jshell.execution.JdiExecutionControlProvider; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
29 |
import jdk.jshell.execution.RemoteExecutionControl; |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
30 |
import jdk.jshell.spi.ExecutionControlProvider; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
31 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
32 |
/** |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
33 |
* Hang for three minutes (long enough to cause a timeout). |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
34 |
*/ |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
35 |
class HangingRemoteAgent extends RemoteExecutionControl { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
36 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
37 |
private static final long DELAY = 4000L; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
38 |
private static final int TIMEOUT = 2000; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
39 |
private static final boolean INFRA_VERIFY = false; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
40 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
42 |
if (INFRA_VERIFY) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
43 |
RemoteExecutionControl.main(args); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
44 |
} else { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
45 |
long end = System.currentTimeMillis() + DELAY; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
46 |
long remaining; |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
47 |
while ((remaining = end - System.currentTimeMillis()) > 0L) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
48 |
try { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
49 |
Thread.sleep(remaining); |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
50 |
} catch (InterruptedException ex) { |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
51 |
// loop again |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
52 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
53 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
54 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
55 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
56 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
57 |
static JShell state(boolean isLaunch, String host) { |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
58 |
ExecutionControlProvider ecp = new JdiExecutionControlProvider(); |
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
59 |
Map<String,String> pm = ecp.defaultParameters(); |
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
60 |
pm.put(JdiExecutionControlProvider.PARAM_REMOTE_AGENT, HangingRemoteAgent.class.getName()); |
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
61 |
pm.put(JdiExecutionControlProvider.PARAM_HOST_NAME, host==null? "" : host); |
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
62 |
pm.put(JdiExecutionControlProvider.PARAM_LAUNCH, ""+isLaunch); |
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
63 |
pm.put(JdiExecutionControlProvider.PARAM_TIMEOUT, ""+TIMEOUT); |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
42969
diff
changeset
|
64 |
// turn on logging of launch failures |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
42969
diff
changeset
|
65 |
Logger.getLogger("jdk.jshell.execution").setLevel(Level.ALL); |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
66 |
return JShell.builder() |
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
67 |
.executionEngine(ecp, pm) |
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42272
diff
changeset
|
68 |
.build(); |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
69 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
70 |
|
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
diff
changeset
|
71 |
} |