org.apache.spark.repl

H2OIMain

class H2OIMain extends H2OImports with Logging

An interpreter for Scala code. It is slighlty modified for H2O purposes so it can be used in the environemnt where multiple interpretrs exist and are using the same http class server.

The main public entry points are compile(), interpret(), and bind(). The compile() method loads a complete Scala file. The interpret() method executes one line of Scala code at the request of the user. The bind() method binds an object to a variable that can then be used by later interpreted code.

The overall approach is based on compiling the requested code and then using a Java classloader and Java reflection to run the code and access its results.

In more detail, a single compiler instance is used to accumulate all successfully compiled or interpreted Scala code. To "interpret" a line of code, the compiler generates a fresh object that includes the line of code and which has public member(s) to export all variables defined by that code. To extract the result of an interpreted line to show the user, a second "result object" is created which imports the variables exported by the above object and then exports members called "$eval" and "$print". To accomodate user expressions that read from variables or methods defined in previous statements, "import" statements are used.

This interpreter shares the strengths and weaknesses of using the full compiler-to-Java. The main strength is that interpreted code behaves exactly as does compiled code, including running at full speed. The main weakness is that redefining classes and methods is not handled properly, because rebinding at the Java level is technically difficult.

Self Type
H2OIMain
Annotations
@DeveloperApi()
Linear Supertypes
Logging, H2OImports, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. H2OIMain
  2. Logging
  3. H2OImports
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new H2OIMain(sharedCLHelper: ClassLoaderHelper, initialSettings: Settings, out: JPrintWriter, sessionID: Int, propagateExceptions: Boolean = false)

Type Members

  1. class ReadEvalPrint extends AnyRef

    Here is where we:

  2. class Request extends AnyRef

    One line of code submitted by the user for interpretation

  3. case class SparkComputedImports extends Product with Serializable

    Compute imports that allow definitions from previous requests to be visible in a new request.

    Compute imports that allow definitions from previous requests to be visible in a new request. Returns three pieces of related code:

    1. An initial code fragment that should go before the code of the new request.

    2. A code fragment that should go after the code of the new request.

    3. An access path which can be traversed to access any bindings inside code wrapped by #1 and #2 .

    The argument is a set of Names that need to be imported.

    Limitations: This method is not as precise as it could be. (1) It does not process wildcard imports to see what exactly they import. (2) If it imports any names from a request, it imports all of them, which is not really necessary. (3) It imports multiple same-named implicits, but only the last one imported is actually usable.

    Definition Classes
    H2OImports

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. object FixedSessionNames

    Captures the session names (which are set by system properties) once, instead of for each line.

  7. def addImports(ids: String*): Result

    Executes an import statement per "id" provided

    Executes an import statement per "id" provided

    ids

    The series of "id" strings used for import statements

    returns

    The results of importing the series of "id" strings

    Annotations
    @DeveloperApi()
    Example:
    1. addImports("org.apache.spark.SparkContext")

  8. def addUrlsToClassPath(urls: URL*): Unit

    Adds any specified jars to the compile and runtime classpaths.

    Adds any specified jars to the compile and runtime classpaths.

    urls

    The list of items to add to the compile and runtime classpaths

    Annotations
    @DeveloperApi()
    Note

    Currently only supports jars, not directories

  9. def allDefinedNames: List[scala.tools.nsc.Global.Name]

    Retrieves all simple names contained in the current instance.

    Retrieves all simple names contained in the current instance.

    returns

    A list of sorted names

    Annotations
    @DeveloperApi()
  10. def allImportedNames: List[scala.tools.nsc.Global.Name]

    Definition Classes
    H2OImports
  11. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  12. def beQuietDuring[T](body: ⇒ T): T

    Suppresses overwriting print results during the operation.

    Suppresses overwriting print results during the operation.

    T

    The return type of the block

    body

    The block to execute

    returns

    The result from executing the block

    Annotations
    @DeveloperApi()
  13. def beSilentDuring[T](operation: ⇒ T): T

    Completely masks all output during the operation (minus JVM standard out and error).

    Completely masks all output during the operation (minus JVM standard out and error).

    T

    The return type of the block

    operation

    The block to execute

    returns

    The result from executing the block

    Annotations
    @DeveloperApi()
  14. def bind(name: String, boundType: String, value: Any, modifiers: List[String] = Nil): Result

    Bind a specified name to a specified value.

    Bind a specified name to a specified value. The name may later be used by expressions passed to interpret.

    name

    The variable name to bind

    boundType

    The type of the variable, as a string

    value

    The object value to bind to it

    returns

    An indication of whether the binding succeeded or failed using interpreter results

    Annotations
    @DeveloperApi()
    Note

    This binds via compilation and interpretation

  15. def classOfTerm(id: String): Option[JClass]

    Retrieves the class representing the id (variable name, method name, class name, etc) provided.

    Retrieves the class representing the id (variable name, method name, class name, etc) provided.

    id

    The id (variable name, method name, class name, etc) whose associated class to retrieve

    returns

    Some containing term name (id) class if exists, else None

    Annotations
    @DeveloperApi()
  16. def classServerUri: String

    URI of the class server used to feed REPL compiled classes.

    URI of the class server used to feed REPL compiled classes.

    returns

    The string representing the class server uri

    Annotations
    @DeveloperApi()
  17. def classSymbols: List[scala.tools.nsc.Global.ClassSymbol]

    Retrieves the Symbols representing classes in the compiler.

    Retrieves the Symbols representing classes in the compiler.

    returns

    The list of matching ClassSymbol instances

    Annotations
    @DeveloperApi()
  18. def clearExecutionWrapper(): Unit

    Clears the code used as a wrapper around all code executed by this instance.

    Clears the code used as a wrapper around all code executed by this instance.

    Annotations
    @DeveloperApi()
  19. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. def close(): Unit

    Stops the underlying REPL class server and flushes the reporter used for compiler output.

    Stops the underlying REPL class server and flushes the reporter used for compiler output.

    Annotations
    @DeveloperApi()
  21. def compileSources(sources: SourceFile*): Boolean

    Compiles specified source files.

    Compiles specified source files.

    sources

    The sequence of source files to compile

    returns

    True if successful, otherwise false

    Annotations
    @DeveloperApi()
  22. def compileString(code: String): Boolean

    Compiles a string of code.

    Compiles a string of code.

    code

    The string of code to compile

    returns

    True if successful, otherwise false

    Annotations
    @DeveloperApi()
  23. def definedSymbolList: List[scala.tools.nsc.Global.Symbol]

    Retrieves the list of public symbols in the compiler.

    Retrieves the list of public symbols in the compiler.

    returns

    The list of public Symbol instances

    Annotations
    @DeveloperApi()
  24. def definedSymbols: Set[scala.tools.nsc.Global.Symbol]

    Retrieves the defined symbols in the compiler.

    Retrieves the defined symbols in the compiler.

    returns

    The set of matching Symbol instances

    Annotations
    @DeveloperApi()
  25. def definedTerms: List[scala.tools.nsc.Global.TermName]

    Retrieves the defined, public names in the compiler.

    Retrieves the defined, public names in the compiler.

    returns

    The list of matching "term" names

    Annotations
    @DeveloperApi()
  26. def definedTypes: List[scala.tools.nsc.Global.TypeName]

    Retrieves the defined type names in the compiler.

    Retrieves the defined type names in the compiler.

    returns

    The list of matching type names

    Annotations
    @DeveloperApi()
  27. def definitionForName(name: scala.tools.nsc.Global.Name): Option[(memberHandlers)#MemberHandler]

  28. def directBind(name: String, boundType: String, value: Any): Result

    Bind a specified name to a specified value directly.

    Bind a specified name to a specified value directly.

    name

    The variable name to bind

    boundType

    The type of the variable, as a string

    value

    The object value to bind to it

    returns

    An indication of whether the binding succeeded or failed using interpreter results

    Annotations
    @DeveloperApi()
    Note

    This updates internal bound names directly

  29. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  30. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  31. def executionWrapper: String

    Contains the code (in string form) representing a wrapper around all code executed by this instance.

    Contains the code (in string form) representing a wrapper around all code executed by this instance.

    returns

    The wrapper code as a string

    Annotations
    @DeveloperApi()
  32. def fallback: Boolean

    Definition Classes
    H2OImports
  33. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  34. def generatedName(simpleName: String): Option[String]

    Returns the real name of a class based on its repl-defined name.

    Returns the real name of a class based on its repl-defined name.

    Example

    Given a simple repl-defined name, returns the real name of the class representing it, e.g. for "Bippy" it may return

    $line19.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$Bippy
    simpleName

    The repl-defined name whose real name to retrieve

    returns

    Some real name if the simple name exists, else None

    Annotations
    @DeveloperApi()
  35. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  36. lazy val getClassOutputDirectory: File

    Returns the path to the output directory containing all generated class files that will be served by the REPL class server.

  37. lazy val global: Global

    The underlying compiler used to generate ASTs and execute code.

  38. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  39. def implicitSymbols: List[scala.tools.nsc.Global.Symbol]

    Definition Classes
    H2OImports
  40. def implicitSymbolsBySource: List[(scala.tools.nsc.Global.Symbol, List[scala.tools.nsc.Global.Symbol])]

    Definition Classes
    H2OImports
  41. def importedSymbols: List[scala.tools.nsc.Global.Symbol]

    Definition Classes
    H2OImports
  42. def importedSymbolsBySource: List[(scala.tools.nsc.Global.Symbol, List[scala.tools.nsc.Global.Symbol])]

    Tuples of (source, imported symbols) in the order they were imported.

    Tuples of (source, imported symbols) in the order they were imported.

    Definition Classes
    H2OImports
  43. def importedTermNamed(name: String): scala.tools.nsc.Global.Symbol

    Definition Classes
    H2OImports
  44. def importedTermSymbols: List[scala.tools.nsc.Global.TermSymbol]

    Definition Classes
    H2OImports
  45. def importedTerms: List[scala.tools.nsc.Global.TermName]

    Definition Classes
    H2OImports
  46. def importedTypeSymbols: List[scala.tools.nsc.Global.TypeSymbol]

    Definition Classes
    H2OImports
  47. def importedTypes: List[scala.tools.nsc.Global.TypeName]

    Definition Classes
    H2OImports
  48. def importsCode(wanted: Set[scala.tools.nsc.Global.Name], definedClass: Boolean): SparkComputedImports

    Attributes
    protected
    Definition Classes
    H2OImports
  49. def initializeSynchronous(): Unit

    Initializes the underlying compiler/interpreter in a blocking fashion.

    Initializes the underlying compiler/interpreter in a blocking fashion.

    Annotations
    @DeveloperApi()
    Note

    Must be executed before using SparkIMain!

  50. def interpret(line: String): Result

    Interpret one line of input.

    Interpret one line of input. All feedback, including parse errors and evaluation results, are printed via the supplied compiler's reporter. Values defined are available for future interpreted strings.

    line

    The line representing the code to interpret

    returns

    Whether the line was interpreted successfully, or failed due to incomplete code, compilation error, or runtime error

    Annotations
    @DeveloperApi()
    Note

    This assigns variables with user name structure like "res0"

  51. def interpretSynthetic(line: String): Result

    Interpret one line of input.

    Interpret one line of input. All feedback, including parse errors and evaluation results, are printed via the supplied compiler's reporter. Values defined are available for future interpreted strings.

    line

    The line representing the code to interpret

    returns

    Whether the line was interpreted successfully, or failed due to incomplete code, compilation error, or runtime error

    Annotations
    @DeveloperApi()
    Note

    This assigns variables with synthetic (generated) name structure like "$ires0"

  52. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  53. def isNoImports: Boolean

    Definition Classes
    H2OImports
  54. def isNoPredef: Boolean

    Definition Classes
    H2OImports
  55. def isReportingErrors: Boolean

    Determines if errors were reported (typically during compilation).

    Determines if errors were reported (typically during compilation).

    returns

    True if had errors, otherwise false

    Annotations
    @DeveloperApi()
    Note

    This is not for runtime errors

  56. def isTraceEnabled(): Boolean

    Attributes
    protected
    Definition Classes
    Logging
  57. def languageSymbols: List[scala.tools.nsc.Global.Symbol]

    Definition Classes
    H2OImports
  58. def languageWildcardHandlers: List[(memberHandlers)#ImportHandler]

    Definition Classes
    H2OImports
  59. def languageWildcardSyms: List[scala.tools.nsc.Global.Symbol]

    Symbols whose contents are language-defined to be imported.

    Symbols whose contents are language-defined to be imported.

    Definition Classes
    H2OImports
  60. def languageWildcards: List[scala.tools.nsc.Global.Type]

    Definition Classes
    H2OImports
  61. def lastWarnings: List[(scala.tools.nsc.Global.Position, String)]

    Returns a list of recent warnings from compiler execution.

    Returns a list of recent warnings from compiler execution.

    returns

    The list of tuples (compiler position, warning)

    Annotations
    @DeveloperApi()
  62. def log: Logger

    Attributes
    protected
    Definition Classes
    Logging
  63. def logDebug(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  64. def logDebug(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  65. def logError(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  66. def logError(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  67. def logInfo(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  68. def logInfo(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  69. def logName: String

    Attributes
    protected
    Definition Classes
    Logging
  70. def logTrace(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  71. def logTrace(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  72. def logWarning(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  73. def logWarning(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  74. def methodSymbols: List[scala.tools.nsc.Global.MethodSymbol]

    Retrieves the Symbols representing methods in the compiler.

    Retrieves the Symbols representing methods in the compiler.

    returns

    The list of matching MethodSymbol instances

    Annotations
    @DeveloperApi()
  75. def mostRecentVar: String

    Returns the name of the most recent interpreter result.

    Returns the name of the most recent interpreter result. Useful for for extracting information regarding the previous result.

    returns

    The simple name of the result (such as res0)

    Annotations
    @DeveloperApi()
  76. def namedDefinedTerms: List[scala.tools.nsc.Global.TermName]

    Retrieves defined, public names that are not res0 or the result of a direct bind.

    Retrieves defined, public names that are not res0 or the result of a direct bind.

    returns

    The list of matching "term" names

    Annotations
    @DeveloperApi()
  77. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  78. def newCompiler(settings: Settings, reporter: Reporter): ReplGlobal

    Instantiates a new compiler used by SparkIMain.

    Instantiates a new compiler used by SparkIMain. Overridable to provide own instance of a compiler.

    settings

    The settings to provide the compiler

    reporter

    The reporter to use for compiler output

    returns

    The compiler as a Global

    Attributes
    protected
    Annotations
    @DeveloperApi()
  79. final def notify(): Unit

    Definition Classes
    AnyRef
  80. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  81. def onlyTerms(xs: List[scala.tools.nsc.Global.Name]): List[scala.tools.nsc.Global.TermName]

    Attributes
    protected
  82. def onlyTypes(xs: List[scala.tools.nsc.Global.Name]): List[scala.tools.nsc.Global.TypeName]

    Attributes
    protected
  83. val out: JPrintWriter

  84. def parentClassLoader: ClassLoader

    Represents the parent classloader used by this instance.

    Represents the parent classloader used by this instance. Can be overridden to provide alternative classloader.

    returns

    The classloader used as the parent loader of this instance

    Attributes
    protected
    Annotations
    @DeveloperApi()
  85. def parse(line: String): Option[List[scala.tools.nsc.Global.Tree]]

    Constructs a list of abstract syntax trees representing the provided code.

    Constructs a list of abstract syntax trees representing the provided code.

    line

    The line of code to parse and construct into ASTs

    returns

    Some list of ASTs if the line is valid, else None

    Annotations
    @DeveloperApi()
  86. def pathToName(name: scala.tools.nsc.Global.Name): String

    Retrieves the full code path to access the specified simple name content.

    Retrieves the full code path to access the specified simple name content.

    name

    The simple name of the target whose path to determine

    returns

    The full path used to access the specified target (name)

    Annotations
    @DeveloperApi()
  87. def rebind(p: NamedParam): Result

    Overwrites previously-bound val with a new instance.

    Overwrites previously-bound val with a new instance.

    p

    The named parameters used to provide the name, value, and type

    returns

    The results of rebinding the named val

    Annotations
    @DeveloperApi()
  88. def requestForIdent(line: String): Option[Request]

  89. def requestForName(name: scala.tools.nsc.Global.Name): Option[Request]

  90. def requestForReqId(id: Int): Option[Request]

  91. def requestHistoryForName(name: scala.tools.nsc.Global.Name): List[Request]

  92. def reset(): Unit

    Reset this interpreter, forgetting all user-specified requests.

    Reset this interpreter, forgetting all user-specified requests.

    Annotations
    @DeveloperApi()
  93. def runtimeClassAndTypeOfTerm(id: String): Option[(JClass, scala.tools.nsc.Global.Type)]

    Retrieves the runtime class and type representing the id (variable name, method name, class name, etc) provided.

    Retrieves the runtime class and type representing the id (variable name, method name, class name, etc) provided.

    id

    The id (variable name, method name, class name, etc) whose associated runtime class and type to retrieve

    returns

    Some runtime class and Type information as a tuple for the provided term name if it exists, else None

    Annotations
    @DeveloperApi()
  94. def runtimeTypeOfTerm(id: String): scala.tools.nsc.Global.Type

    Retrieves the runtime type representing the id (variable name, method name, class name, etc) provided.

    Retrieves the runtime type representing the id (variable name, method name, class name, etc) provided.

    id

    The id (variable name, method name, class name, etc) whose associated runtime type to retrieve

    returns

    The runtime Type information about the term name (id) provided

    Annotations
    @DeveloperApi()
  95. val sessionID: Int

  96. def sessionImportedSymbols: List[scala.tools.nsc.Global.Symbol]

    Definition Classes
    H2OImports
  97. def sessionWildcards: List[scala.tools.nsc.Global.Type]

    Types which have been wildcard imported, such as: val x = "abc" ; import x.

    Types which have been wildcard imported, such as: val x = "abc" ; import x._ // type java.lang.String import java.lang.String._ // object java.lang.String

    Used by tab completion.

    XXX right now this gets import x._ and import java.lang.String._, but doesn't figure out import String._. There's a lot of ad hoc scope twiddling which should be swept away in favor of digging into the compiler scopes.

    Definition Classes
    H2OImports
  98. def setExecutionWrapper(code: String): Unit

    Sets the code to use as a wrapper around all code executed by this instance.

    Sets the code to use as a wrapper around all code executed by this instance.

    code

    The wrapper code as a string

    Annotations
    @DeveloperApi()
  99. val sharedCLHelper: ClassLoaderHelper

  100. def symbolOfLine(code: String): scala.tools.nsc.Global.Symbol

    Constructs a Symbol representing the final result of the expression provided or representing the definition provided.

    Constructs a Symbol representing the final result of the expression provided or representing the definition provided.

    code

    The line of code

    returns

    The Symbol or NoSymbol (found under scala.reflect.internal)

    Annotations
    @DeveloperApi()
  101. def symbolOfTerm(id: String): scala.tools.nsc.Global.Symbol

    Retrieves the symbol representing the id (variable name, method name, class name, etc) provided.

    Retrieves the symbol representing the id (variable name, method name, class name, etc) provided.

    id

    The id (variable name, method name, class name, etc) whose associated symbol to retrieve

    returns

    The Symbol information about the term name (id) provided

    Annotations
    @DeveloperApi()
  102. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  103. def toString(): String

    Definition Classes
    AnyRef → Any
  104. def treesForRequestId(id: Int): List[scala.tools.nsc.Global.Tree]

  105. def typeOfExpression(expr: String, silent: Boolean = true): scala.tools.nsc.Global.Type

    Constucts type information based on the provided expression's final result or the definition provided.

    Constucts type information based on the provided expression's final result or the definition provided.

    expr

    The expression or definition

    silent

    Whether to output information while constructing the type

    returns

    The type information or an error

    Annotations
    @DeveloperApi()
  106. def typeOfTerm(id: String): scala.tools.nsc.Global.Type

    Retrieves the type representing the id (variable name, method name, class name, etc) provided.

    Retrieves the type representing the id (variable name, method name, class name, etc) provided.

    id

    The id (variable name, method name, class name, etc) whose associated type to retrieve

    returns

    The Type information about the term name (id) provided

    Annotations
    @DeveloperApi()
  107. def valueOfTerm(id: String): Option[AnyRef]

    Retrieves the object representing the id (variable name, method name, class name, etc) provided.

    Retrieves the object representing the id (variable name, method name, class name, etc) provided.

    id

    The id (variable name, method name, class name, etc) whose associated content to retrieve

    returns

    Some containing term name (id) representation if exists, else None

    Annotations
    @DeveloperApi()
  108. def visibleTermNames: List[scala.tools.nsc.Global.Name]

    Retrieves a list of unique defined and imported names in the compiler.

    Retrieves a list of unique defined and imported names in the compiler.

    returns

    The list of "term" names

  109. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  110. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  111. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  112. def wildcardTypes: List[scala.tools.nsc.Global.Type]

    Definition Classes
    H2OImports

Inherited from Logging

Inherited from H2OImports

Inherited from AnyRef

Inherited from Any

Ungrouped