-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce commHandlers for kernel-provided functionality; support deb…
…ugPortComm messages in kernel
- Loading branch information
1 parent
a4df334
commit db0dc9c
Showing
9 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
jupyter-lib/shared-compiler/src/main/kotlin/org/jetbrains/kotlinx/jupyter/messaging/debug.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.jetbrains.kotlinx.jupyter.messaging | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
object ProvidedCommMessages { | ||
const val OPEN_DEBUG_PORT_TARGET: String = "open_debug_port_target" | ||
} | ||
|
||
@Serializable | ||
class OpenDebugPortReply( | ||
val port: Int? | ||
) : OkReply() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/org/jetbrains/kotlinx/jupyter/messaging/defaultCommHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.jetbrains.kotlinx.jupyter.messaging | ||
|
||
import kotlinx.serialization.json.JsonObject | ||
import org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl | ||
import org.jetbrains.kotlinx.jupyter.api.libraries.Comm | ||
import org.jetbrains.kotlinx.jupyter.api.libraries.sendData | ||
import org.jetbrains.kotlinx.jupyter.messaging.ProvidedCommMessages.OPEN_DEBUG_PORT_TARGET | ||
|
||
typealias CommMessageProcessCallback = (Comm, JsonObject, ReplForJupyterImpl) -> Unit | ||
|
||
abstract class DefaultCommHandler { | ||
abstract val targetId: String | ||
|
||
abstract fun onReceive(): CommMessageProcessCallback | ||
|
||
abstract fun register(repl: ReplForJupyterImpl) | ||
} | ||
|
||
class DebugPortCommHandler : DefaultCommHandler() { | ||
override val targetId: String | ||
get() = OPEN_DEBUG_PORT_TARGET | ||
|
||
override fun onReceive(): CommMessageProcessCallback { | ||
return { comm, _, repl -> | ||
comm.sendData(OpenDebugPortReply(repl.debugPort)) | ||
} | ||
} | ||
|
||
override fun register(repl: ReplForJupyterImpl) { | ||
repl.notebook.commManager.registerCommTarget(targetId) { comm, _ -> | ||
comm.onMessage { | ||
onReceive() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters