All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlinx.jupyter.api.KernelRunMode.kt Maven / Gradle / Ivy

There is a newer version: 0.12.0-335
Show newest version
package org.jetbrains.kotlinx.jupyter.api

import org.jetbrains.kotlinx.jupyter.util.createDefaultDelegatingClassLoader

/**
 * Represents settings that depend on the environment in which the kernel is running
 */
interface KernelRunMode {
    val name: String

    /**
     * Creates an intermediary ClassLoader between the parent classloader (which is
     * usually a classloader that loads kernel classpath) and the chain of REPL classloaders,
     * including the base one. If null is returned, no intermediate classloader will be used.
     */
    fun createIntermediaryClassLoader(parent: ClassLoader): ClassLoader?

    val shouldKillProcessOnShutdown: Boolean

    val inMemoryOutputsSupported: Boolean

    val isRunInsideIntellijProcess: Boolean

    val streamSubstitutionType: StreamSubstitutionType

    fun initializeSession(
        notebook: Notebook,
        evaluator: CodeEvaluator,
    ) = Unit
}

abstract class AbstractKernelRunMode(override val name: String) : KernelRunMode {
    override fun toString(): String {
        return name
    }
}

object StandaloneKernelRunMode : AbstractKernelRunMode("Standalone") {
    override fun createIntermediaryClassLoader(parent: ClassLoader) = createDefaultDelegatingClassLoader(parent)

    override val shouldKillProcessOnShutdown: Boolean get() = true
    override val inMemoryOutputsSupported: Boolean get() = false
    override val isRunInsideIntellijProcess: Boolean get() = false
    override val streamSubstitutionType: StreamSubstitutionType
        get() = StreamSubstitutionType.BLOCKING
}

object EmbeddedKernelRunMode : AbstractKernelRunMode("Embedded") {
    override fun createIntermediaryClassLoader(parent: ClassLoader) = null

    override val shouldKillProcessOnShutdown: Boolean get() = false
    override val inMemoryOutputsSupported: Boolean get() = false
    override val isRunInsideIntellijProcess: Boolean get() = false
    override val streamSubstitutionType: StreamSubstitutionType
        get() = StreamSubstitutionType.BLOCKING
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy