mirror of
https://github.com/corda/corda.git
synced 2025-02-02 17:21:06 +00:00
Disable the DemoBench tab if the node exits abnormally. (#692)
* Log a message when the CRaSH shell exits. * Disable the DemoBench tab if the node exits abnormally.
This commit is contained in:
parent
68f0e5d683
commit
5cf304e8c4
@ -15,6 +15,7 @@ import net.corda.core.flows.FlowLogic
|
|||||||
import net.corda.core.flows.FlowStateMachine
|
import net.corda.core.flows.FlowStateMachine
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
import net.corda.core.utilities.Emoji
|
import net.corda.core.utilities.Emoji
|
||||||
|
import net.corda.core.utilities.loggerFor
|
||||||
import net.corda.jackson.JacksonSupport
|
import net.corda.jackson.JacksonSupport
|
||||||
import net.corda.jackson.StringToMethodCallParser
|
import net.corda.jackson.StringToMethodCallParser
|
||||||
import net.corda.node.internal.Node
|
import net.corda.node.internal.Node
|
||||||
@ -70,6 +71,7 @@ import kotlin.concurrent.thread
|
|||||||
// TODO: Make it notice new shell commands added after the node started.
|
// TODO: Make it notice new shell commands added after the node started.
|
||||||
|
|
||||||
object InteractiveShell {
|
object InteractiveShell {
|
||||||
|
private val log = loggerFor<InteractiveShell>()
|
||||||
private lateinit var node: Node
|
private lateinit var node: Node
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,6 +131,7 @@ object InteractiveShell {
|
|||||||
thread(name = "Command line shell terminator", isDaemon = true) {
|
thread(name = "Command line shell terminator", isDaemon = true) {
|
||||||
// Wait for the shell to finish.
|
// Wait for the shell to finish.
|
||||||
jlineProcessor.closed()
|
jlineProcessor.closed()
|
||||||
|
log.info("Command shell has exited")
|
||||||
terminal.restore()
|
terminal.restore()
|
||||||
node.stop()
|
node.stop()
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ class NodeRPC(config: NodeConfig, start: (NodeConfig, CordaRPCOps) -> Unit, invo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val rpcClient = CordaRPCClient(HostAndPort.fromParts("localhost", config.rpcPort))
|
private val rpcClient = CordaRPCClient(HostAndPort.fromParts("localhost", config.rpcPort))
|
||||||
|
private var rpcConnection: CordaRPCConnection? = null
|
||||||
private val timer = Timer()
|
private val timer = Timer()
|
||||||
private val connections = Collections.synchronizedCollection(ArrayList<CordaRPCConnection>())
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val setupTask = object : TimerTask() {
|
val setupTask = object : TimerTask() {
|
||||||
@ -26,7 +26,7 @@ class NodeRPC(config: NodeConfig, start: (NodeConfig, CordaRPCOps) -> Unit, invo
|
|||||||
try {
|
try {
|
||||||
val user = config.users.elementAt(0)
|
val user = config.users.elementAt(0)
|
||||||
val connection = rpcClient.start(user.username, user.password)
|
val connection = rpcClient.start(user.username, user.password)
|
||||||
connections.add(connection)
|
rpcConnection = connection
|
||||||
val ops = connection.proxy
|
val ops = connection.proxy
|
||||||
|
|
||||||
// Cancel the "setup" task now that we've created the RPC client.
|
// Cancel the "setup" task now that we've created the RPC client.
|
||||||
@ -53,7 +53,11 @@ class NodeRPC(config: NodeConfig, start: (NodeConfig, CordaRPCOps) -> Unit, invo
|
|||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
timer.cancel()
|
timer.cancel()
|
||||||
connections.forEach(CordaRPCConnection::close)
|
try {
|
||||||
|
rpcConnection?.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
log.error("Failed to close RPC connection (Error: {})", e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -270,8 +270,13 @@ class NodeTabView : Fragment() {
|
|||||||
nodeTab.text = config.legalName.commonName
|
nodeTab.text = config.legalName.commonName
|
||||||
nodeTerminalView.open(config) { exitCode ->
|
nodeTerminalView.open(config) { exitCode ->
|
||||||
Platform.runLater {
|
Platform.runLater {
|
||||||
if (exitCode == 0)
|
if (exitCode == 0) {
|
||||||
nodeTab.requestClose()
|
nodeTab.requestClose()
|
||||||
|
} else {
|
||||||
|
// The node did not shut down cleanly. Keep the
|
||||||
|
// terminal open but ensure that it is disabled.
|
||||||
|
nodeTerminalView.shutdown()
|
||||||
|
}
|
||||||
nodeController.dispose(config)
|
nodeController.dispose(config)
|
||||||
main.forceAtLeastOneTab()
|
main.forceAtLeastOneTab()
|
||||||
}
|
}
|
||||||
|
@ -229,16 +229,21 @@ class NodeTerminalView : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shutdown() {
|
||||||
|
header.isDisable = true
|
||||||
|
subscriptions.forEach {
|
||||||
|
// Don't allow any exceptions here to halt tab destruction.
|
||||||
|
try { it.unsubscribe() } catch (e: Exception) {}
|
||||||
|
}
|
||||||
|
webServer.close()
|
||||||
|
explorer.close()
|
||||||
|
viewer.close()
|
||||||
|
rpc?.close()
|
||||||
|
}
|
||||||
|
|
||||||
fun destroy() {
|
fun destroy() {
|
||||||
if (!isDestroyed) {
|
if (!isDestroyed) {
|
||||||
subscriptions.forEach {
|
shutdown()
|
||||||
// Don't allow any exceptions here to halt tab destruction.
|
|
||||||
try { it.unsubscribe() } catch (e: Exception) {}
|
|
||||||
}
|
|
||||||
webServer.close()
|
|
||||||
explorer.close()
|
|
||||||
viewer.close()
|
|
||||||
rpc?.close()
|
|
||||||
pty?.close()
|
pty?.close()
|
||||||
isDestroyed = true
|
isDestroyed = true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user