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