langtools/src/jdk.jshell/share/classes/jdk/jshell/spi/ExecutionControl.java
author rfield
Wed, 08 Feb 2017 10:43:16 -0800
changeset 43758 868af3718a21
parent 43132 6a5c69926e60
child 43770 a321bed02000
permissions -rw-r--r--
8173845: JShell API: not patch compatible Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     1
/*
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     4
 *
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    10
 *
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    15
 * accompanied this code).
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    16
 *
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    20
 *
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    23
 * questions.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    24
 */
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    25
package jdk.jshell.spi;
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    26
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    27
import java.io.Serializable;
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
    28
import java.util.Collections;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
    29
import java.util.HashMap;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
    30
import java.util.Map;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
    31
import java.util.ServiceLoader;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
    32
import java.util.Set;
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    33
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    34
/**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    35
 * This interface specifies the functionality that must provided to implement a
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    36
 * pluggable JShell execution engine.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    37
 * <p>
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    38
 * The audience for this Service Provider Interface is engineers wishing to
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    39
 * implement their own version of the execution engine in support of the JShell
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    40
 * API.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    41
 * <p>
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    42
 * A Snippet is compiled into code wrapped in a 'wrapper class'. The execution
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    43
 * engine is used by the core JShell implementation to load and, for executable
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    44
 * Snippets, execute the Snippet.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    45
 * <p>
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    46
 * Methods defined in this interface should only be called by the core JShell
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    47
 * implementation.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    48
 */
41941
a935ac3f5274 8161983: JShell API: Clean-up following 8160127 et. al.
rfield
parents: 39807
diff changeset
    49
public interface ExecutionControl extends AutoCloseable {
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    50
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    51
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    52
     * Attempts to load new classes.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    53
     *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    54
     * @param cbcs the class name and bytecodes to load
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    55
     * @throws ClassInstallException exception occurred loading the classes,
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    56
     * some or all were not loaded
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    57
     * @throws NotImplementedException if not implemented
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    58
     * @throws EngineTerminationException the execution engine has terminated
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    59
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    60
    void load(ClassBytecodes[] cbcs)
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    61
            throws ClassInstallException, NotImplementedException, EngineTerminationException;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    62
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    63
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    64
     * Attempts to redefine previously loaded classes.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    65
     *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    66
     * @param cbcs the class name and bytecodes to redefine
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    67
     * @throws ClassInstallException exception occurred redefining the classes,
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    68
     * some or all were not redefined
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    69
     * @throws NotImplementedException if not implemented
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    70
     * @throws EngineTerminationException the execution engine has terminated
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    71
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    72
    void redefine(ClassBytecodes[] cbcs)
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    73
            throws ClassInstallException, NotImplementedException, EngineTerminationException;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    74
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    75
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    76
     * Invokes an executable Snippet by calling a method on the specified
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    77
     * wrapper class. The method must have no arguments and return String.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    78
     *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    79
     * @param className the class whose method should be invoked
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    80
     * @param methodName the name of method to invoke
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    81
     * @return the result of the execution or null if no result
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    82
     * @throws UserException the invoke raised a user exception
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    83
     * @throws ResolutionException the invoke attempted to directly or
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    84
     * indirectly invoke an unresolved snippet
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    85
     * @throws StoppedException if the {@code invoke()} was canceled by
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    86
     * {@link ExecutionControl#stop}
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    87
     * @throws EngineTerminationException the execution engine has terminated
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    88
     * @throws InternalException an internal problem occurred
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    89
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    90
    String invoke(String className, String methodName)
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    91
            throws RunException, EngineTerminationException, InternalException;
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    92
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
    93
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    94
     * Returns the value of a variable.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    95
     *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    96
     * @param className the name of the wrapper class of the variable
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    97
     * @param varName the name of the variable
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    98
     * @return the value of the variable
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
    99
     * @throws UserException formatting the value raised a user exception
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   100
     * @throws ResolutionException formatting the value attempted to directly or
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   101
     * indirectly invoke an unresolved snippet
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   102
     * @throws StoppedException if the formatting the value was canceled by
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   103
     * {@link ExecutionControl#stop}
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   104
     * @throws EngineTerminationException the execution engine has terminated
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   105
     * @throws InternalException an internal problem occurred
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   106
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   107
    String varValue(String className, String varName)
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   108
            throws RunException, EngineTerminationException, InternalException;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   109
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   110
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   111
     * Adds the path to the execution class path.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   112
     *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   113
     * @param path the path to add
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   114
     * @throws EngineTerminationException the execution engine has terminated
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   115
     * @throws InternalException an internal problem occurred
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   116
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   117
    void addToClasspath(String path)
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   118
            throws EngineTerminationException, InternalException;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   119
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   120
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   121
     * Interrupts a running invoke.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   122
     *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   123
     * @throws EngineTerminationException the execution engine has terminated
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   124
     * @throws InternalException an internal problem occurred
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   125
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   126
    void stop()
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   127
            throws EngineTerminationException, InternalException;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   128
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   129
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   130
     * Run a non-standard command (or a standard command from a newer version).
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   131
     *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   132
     * @param command the non-standard command
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   133
     * @param arg the commands argument
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   134
     * @return the commands return value
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   135
     * @throws UserException the command raised a user exception
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   136
     * @throws ResolutionException the command attempted to directly or
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   137
     * indirectly invoke an unresolved snippet
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   138
     * @throws StoppedException if the command was canceled by
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   139
     * {@link ExecutionControl#stop}
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   140
     * @throws EngineTerminationException the execution engine has terminated
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   141
     * @throws NotImplementedException if not implemented
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   142
     * @throws InternalException an internal problem occurred
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   143
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   144
    Object extensionCommand(String command, Object arg)
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   145
            throws RunException, EngineTerminationException, InternalException;
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   146
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   147
    /**
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   148
     * Shuts down this execution engine. Implementation should free all
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   149
     * resources held by this execution engine.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   150
     * <p>
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   151
     * No calls to methods on this interface should be made after close.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   152
     */
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   153
    @Override
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   154
    void close();
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   155
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   156
    /**
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   157
     * Search for a provider, then create and return the
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   158
     * {@code ExecutionControl} instance.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   159
     *
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   160
     * @param env the execution environment (provided by JShell)
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   161
     * @param name the name of provider
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   162
     * @param parameters the parameter map.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   163
     * @return the execution engine
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   164
     * @throws Throwable an exception that occurred attempting to find or create
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   165
     * the execution engine.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   166
     * @throws IllegalArgumentException if no ExecutionControlProvider has the
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   167
     * specified {@code name} and {@code parameters}.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   168
     */
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   169
    static ExecutionControl generate(ExecutionEnv env, String name, Map<String, String> parameters)
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   170
            throws Throwable {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   171
        Set<String> keys = parameters == null
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   172
                ? Collections.emptySet()
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   173
                : parameters.keySet();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   174
        for (ExecutionControlProvider p : ServiceLoader.load(ExecutionControlProvider.class)) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   175
            if (p.name().equals(name)
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   176
                && p.defaultParameters().keySet().containsAll(keys)) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   177
                return p.generate(env, parameters);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   178
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   179
        }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   180
        throw new IllegalArgumentException("No ExecutionControlProvider with name '"
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   181
                + name + "' and parameter keys: " + keys.toString());
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   182
    }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   183
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   184
    /**
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   185
     * Search for a provider, then create and return the
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   186
     * {@code ExecutionControl} instance.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   187
     *
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   188
     * @param env the execution environment (provided by JShell)
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   189
     * @param spec the {@code ExecutionControl} spec, which is described in
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   190
     * the documentation of this
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   191
     * {@linkplain jdk.jshell.spi package documentation}.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   192
     * @return the execution engine
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   193
     * @throws Throwable an exception that occurred attempting to find or create
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   194
     * the execution engine.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   195
     * @throws IllegalArgumentException if no ExecutionControlProvider has the
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   196
     * specified {@code name} and {@code parameters}.
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   197
     * @throws IllegalArgumentException if {@code spec} is malformed
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   198
     */
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   199
    static ExecutionControl generate(ExecutionEnv env, String spec)
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   200
            throws Throwable {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   201
        class SpecReader {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   202
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   203
            int len = spec.length();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   204
            int i = -1;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   205
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   206
            char ch;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   207
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   208
            SpecReader() {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   209
                next();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   210
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   211
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   212
            boolean more() {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   213
                return i < len;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   214
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   215
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   216
            char current() {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   217
                return ch;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   218
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   219
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   220
            final boolean next() {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   221
                ++i;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   222
                if (i < len) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   223
                    ch = spec.charAt(i);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   224
                    return true;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   225
                }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   226
                i = len;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   227
                return false;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   228
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   229
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   230
            void skipWhite() {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   231
                while (more() && Character.isWhitespace(ch)) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   232
                    next();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   233
                }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   234
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   235
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   236
            String readId() {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   237
                skipWhite();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   238
                StringBuilder sb = new StringBuilder();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   239
                while (more() && Character.isJavaIdentifierPart(ch)) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   240
                    sb.append(ch);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   241
                    next();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   242
                }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   243
                skipWhite();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   244
                String id = sb.toString();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   245
                if (id.isEmpty()) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   246
                    throw new IllegalArgumentException("Expected identifier in " + spec);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   247
                }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   248
                return id;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   249
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   250
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   251
            void expect(char exp) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   252
                skipWhite();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   253
                if (!more() || ch != exp) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   254
                    throw new IllegalArgumentException("Expected '" + exp + "' in " + spec);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   255
                }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   256
                next();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   257
                skipWhite();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   258
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   259
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   260
            String readValue() {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   261
                expect('(');
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   262
                int parenDepth = 1;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   263
                StringBuilder sb = new StringBuilder();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   264
                while (more()) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   265
                    if (ch == ')') {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   266
                        --parenDepth;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   267
                        if (parenDepth == 0) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   268
                            break;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   269
                        }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   270
                    } else if (ch == '(') {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   271
                        ++parenDepth;
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   272
                    }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   273
                    sb.append(ch);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   274
                    next();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   275
                }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   276
                expect(')');
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   277
                return sb.toString();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   278
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   279
        }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   280
        Map<String, String> parameters = new HashMap<>();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   281
        SpecReader sr = new SpecReader();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   282
        String name = sr.readId();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   283
        if (sr.more()) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   284
            sr.expect(':');
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   285
            while (sr.more()) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   286
                String key = sr.readId();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   287
                String value = sr.readValue();
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   288
                parameters.put(key, value);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   289
                if (sr.more()) {
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   290
                    sr.expect(',');
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   291
                }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   292
            }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   293
        }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   294
        return generate(env, name, parameters);
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   295
    }
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   296
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 41941
diff changeset
   297
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   298
     * Bundles class name with class bytecodes.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   299
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   300
    public static final class ClassBytecodes implements Serializable {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   301
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   302
        private static final long serialVersionUID = 0xC1A55B47EC0DE5L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   303
        private final String name;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   304
        private final byte[] bytecodes;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   305
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   306
        /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   307
         * Creates a name/bytecode pair.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   308
         * @param name the class name
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   309
         * @param bytecodes the class bytecodes
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   310
         */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   311
        public ClassBytecodes(String name, byte[] bytecodes) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   312
            this.name = name;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   313
            this.bytecodes = bytecodes;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   314
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   315
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   316
        /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   317
         * The bytecodes for the class.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   318
         *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   319
         * @return the bytecodes
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   320
         */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   321
        public byte[] bytecodes() {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   322
            return bytecodes;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   323
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   324
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   325
        /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   326
         * The class name.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   327
         *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   328
         * @return the class name
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   329
         */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   330
        public String name() {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   331
            return name;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   332
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   333
    }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   334
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   335
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   336
     * The abstract base of all {@code ExecutionControl} exceptions.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   337
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   338
    public static abstract class ExecutionControlException extends Exception {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   339
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   340
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   341
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   342
        public ExecutionControlException(String message) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   343
            super(message);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   344
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   345
    }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   346
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   347
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   348
     * Unbidden execution engine termination has occurred.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   349
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   350
    public static class EngineTerminationException extends ExecutionControlException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   351
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   352
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   353
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   354
        public EngineTerminationException(String message) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   355
            super(message);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   356
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   357
    }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   358
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   359
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   360
     * The command is not implemented.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   361
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   362
    public static class NotImplementedException extends InternalException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   363
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   364
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   365
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   366
        public NotImplementedException(String message) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   367
            super(message);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   368
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   369
    }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   370
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   371
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   372
     * An internal problem has occurred.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   373
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   374
    public static class InternalException extends ExecutionControlException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   375
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   376
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   377
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   378
        public InternalException(String message) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   379
            super(message);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   380
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   381
    }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   382
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   383
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   384
     * A class install (load or redefine) encountered a problem.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   385
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   386
    public static class ClassInstallException extends ExecutionControlException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   387
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   388
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   389
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   390
        private final boolean[] installed;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   391
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   392
        public ClassInstallException(String message, boolean[] installed) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   393
            super(message);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   394
            this.installed = installed;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   395
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   396
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   397
        /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   398
         * Indicates which of the passed classes were successfully
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   399
         * loaded/redefined.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   400
         * @return a one-to-one array with the {@link ClassBytecodes}{@code[]}
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   401
         * array -- {@code true} if installed
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   402
         */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   403
        public boolean[] installed() {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   404
            return installed;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   405
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   406
    }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   407
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   408
    /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   409
     * The abstract base of of exceptions specific to running user code.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   410
     */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   411
    public static abstract class RunException extends ExecutionControlException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   412
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   413
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   414
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   415
        private RunException(String message) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   416
            super(message);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   417
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   418
    }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   419
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   420
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   421
     * A 'normal' user exception occurred.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   422
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   423
    public static class UserException extends RunException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   424
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   425
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   426
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   427
        private final String causeExceptionClass;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   428
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   429
        public UserException(String message, String causeExceptionClass, StackTraceElement[] stackElements) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   430
            super(message);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   431
            this.causeExceptionClass = causeExceptionClass;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   432
            this.setStackTrace(stackElements);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   433
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   434
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   435
        /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   436
         * Returns the class of the user exception.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   437
         * @return the name of the user exception class
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   438
         */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   439
        public String causeExceptionClass() {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   440
            return causeExceptionClass;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   441
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   442
    }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   443
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   444
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   445
     * An exception indicating that a {@code DeclarationSnippet} with unresolved
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   446
     * references has been encountered.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   447
     * <p>
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   448
     * Contrast this with the initiating {@link SPIResolutionException}
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   449
     * (a {@code RuntimeException}) which is embedded in generated corralled
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   450
     * code.  Also, contrast this with
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   451
     * {@link jdk.jshell.UnresolvedReferenceException} the high-level
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   452
     * exception (with {@code DeclarationSnippet} reference) provided in the
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   453
     * main API.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   454
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   455
    public static class ResolutionException extends RunException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   456
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   457
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   458
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   459
        private final int id;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   460
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   461
        /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   462
         * Constructs an exception indicating that a {@code DeclarationSnippet}
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   463
         * with unresolved references has been encountered.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   464
         *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   465
         * @param id An internal identifier of the specific method
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   466
         * @param stackElements the stack trace
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   467
         */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   468
        public ResolutionException(int id, StackTraceElement[] stackElements) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   469
            super("resolution exception: " + id);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   470
            this.id = id;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   471
            this.setStackTrace(stackElements);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   472
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   473
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   474
        /**
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   475
         * Retrieves the internal identifier of the unresolved identifier.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   476
         *
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   477
         * @return the internal identifier
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   478
         */
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   479
        public int id() {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   480
            return id;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   481
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   482
    }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   483
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   484
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   485
     * An exception indicating that an
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   486
     * {@link ExecutionControl#invoke(java.lang.String, java.lang.String) }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   487
     * (or theoretically a
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   488
     * {@link ExecutionControl#varValue(java.lang.String, java.lang.String) })
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   489
     * has been interrupted by a {@link ExecutionControl#stop() }.
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   490
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   491
    public static class StoppedException extends RunException {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   492
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   493
        private static final long serialVersionUID = 1L;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   494
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   495
        public StoppedException() {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   496
            super("stopped by stop()");
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   497
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   498
    }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38535
diff changeset
   499
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff changeset
   500
}